CCM NG: Preparation for replacing privilege strings with enums.

git-svn-id: https://svn.libreccm.org/ccm/ccm_ng@4350 8810af33-2d31-482b-a856-94f89814c4df
pull/2/head
jensp 2016-10-04 17:56:09 +00:00
parent ddc70c795d
commit 1ebbe0e59d
19 changed files with 426 additions and 8 deletions

View File

@ -0,0 +1,54 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.librecms;
import org.libreccm.security.Privilege;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public enum CmsPrivileges implements Privilege {
ADMINISTER_CATEGORIES,
ADMINISTER_CONTENT_TYPES,
ADMINISTER_LIFECYLES,
ADMINISTER_ROLES,
ADMINISTER_WORKFLOW,
ITEMS_APPROVE,
ITEMS_PUBLISH,
ITEMS_CATEGORIZE,
ITEMS_CREATE_NEW,
ITEMS_DELETE,
ITEMS_EDIT,
ITEMS_PREVIEW,
ITEMS_VIEW_PUBLISHED,
APPLY_ALTERNATE_WORKFLOW;
@Override
public String getBundle() {
return CmsConstants.CMS_BUNDLE;
}
@Override
public String getPrefix() {
return "privileges";
}
}

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.categorization;
import org.libreccm.security.Privilege;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public enum Privileges implements Privilege {
MANAGAE_CATEGORIES,
MANAGE_CATEGORY_OBJECTS,
MANAGE_DOMAINS;
@Override
public String getBundle() {
return "org.libreccm.categorization.PrivilegesBundle";
}
@Override
public String getPrefix() {
return "categorization.privileges";
}
}

View File

@ -0,0 +1,41 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.core;
import org.libreccm.security.Privilege;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public enum Privileges implements Privilege {
ADMIN,
SYSTEM;
@Override
public String getBundle() {
return "org.libreccm.core.PrivilegesBundle";
}
@Override
public String getPrefix() {
return "core.privileges";
}
}

View File

@ -0,0 +1,80 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.security;
import com.arsdigita.globalization.GlobalizedMessage;
/**
* Interface to extend by privilege enums of the various modules.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public interface Privilege {
/**
* Return to non localised key for the privilege. The default implementation
* uses the {@code toString} method.
*
* @return The non localised identifier of the privilege.
*/
default String getKey() {
return toString();
}
/**
* An optional prefix for the key to be used to retrieve the localised
* label. The default implementation returns an empty string.
*
* @return An optional prefix for the key.
*/
default String getPrefix() {
return "";
}
/**
* Return the localised label for the role. Primarily for use in the user
* interface. The default implementation the return value
* {@link #getBundle()} to get the fully qualified name of the bundle to
* use. The key is generated by joining the return value from {@link #getPrefix()}
* (if not an empty string) and the return value from {@link #getKey()}.
* The separator between prefix and key is a dot.
*
* @return The localised label for the privilege.
*/
default GlobalizedMessage getLabel() {
final String prefix = getPrefix();
final String key;
if (prefix != null && !prefix.isEmpty()) {
key = String.join(".", getPrefix(), getKey());
} else {
key = getKey();
}
return new GlobalizedMessage(key, getBundle());
}
/**
* Returns the bundle containing the localised labels for the privileges.
*
* @return The fully qualified name of the resource bundle which provides
* the localised labels for the privileges.
*/
String getBundle();
}

View File

@ -0,0 +1,4 @@
categorization.privileges.MANAGE_CATEGORIES=Manage categories
categorization.privileges.MANAGE_CATEGORY_OBJECTS=Manage categorized objects
categorization.privileges.MANAGE_DOMAINS=Manage domains

View File

@ -0,0 +1,4 @@
categorization.privileges.MANAGE_CATEGORIES=Kategorien verwalten
categorization.privileges.MANAGE_CATEGORY_OBJECTS=Kategorisierte Objekte verwalten
categorization.privileges.MANAGE_DOMAINS=Domains verwalten

View File

@ -0,0 +1,3 @@
core.privileges.ADMIN=admin
core.privileges.SYSTEM=system

View File

@ -0,0 +1,3 @@
core.privileges.ADMIN=admin
core.privileges.SYSTEM=system

View File

@ -35,6 +35,7 @@ import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import static org.junit.Assert.*; import static org.junit.Assert.*;
import static org.libreccm.testutils.DependenciesHelpers.*; import static org.libreccm.testutils.DependenciesHelpers.*;
import org.junit.Before; import org.junit.Before;
@ -46,13 +47,14 @@ import org.libreccm.core.CcmObject;
import org.libreccm.jpa.EntityManagerProducer; import org.libreccm.jpa.EntityManagerProducer;
import org.libreccm.jpa.utils.UriConverter; import org.libreccm.jpa.utils.UriConverter;
import org.libreccm.l10n.LocalizedString; import org.libreccm.l10n.LocalizedString;
import org.libreccm.security.Permission;
import org.libreccm.tests.categories.IntegrationTest; import org.libreccm.tests.categories.IntegrationTest;
import org.libreccm.web.ApplicationRepository; import org.libreccm.web.ApplicationRepository;
import org.libreccm.workflow.Workflow; import org.libreccm.workflow.Workflow;
import java.util.List; import java.util.List;
import org.libreccm.security.Privilege;
/** /**
* *
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a> * @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
@ -88,7 +90,7 @@ public class SecurityConfigTest {
"LibreCCM-com.arsdigita.kernel.security.SecurityConfigTest.war") "LibreCCM-com.arsdigita.kernel.security.SecurityConfigTest.war")
.addPackage(CcmObject.class.getPackage()) .addPackage(CcmObject.class.getPackage())
.addPackage(Categorization.class.getPackage()) .addPackage(Categorization.class.getPackage())
.addPackage(Permission.class.getPackage()) .addPackage(Privilege.class.getPackage())
.addPackage(LocalizedString.class.getPackage()) .addPackage(LocalizedString.class.getPackage())
.addPackage(Workflow.class.getPackage()) .addPackage(Workflow.class.getPackage())
.addPackage(UriConverter.class.getPackage()) .addPackage(UriConverter.class.getPackage())

View File

@ -141,7 +141,7 @@ public class CategoryManagerTest {
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()) .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
.addPackage(org.libreccm.security.Permission.class.getPackage()) .addPackage(org.libreccm.security.Privilege.class.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class .addPackage(org.libreccm.testutils.EqualsVerifier.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class .addPackage(org.libreccm.tests.categories.IntegrationTest.class

View File

@ -112,7 +112,7 @@ public class CategoryRepositoryTest {
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()) .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
.addPackage(org.libreccm.security.Permission.class.getPackage()) .addPackage(org.libreccm.security.Privilege.class.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class .addPackage(org.libreccm.testutils.EqualsVerifier.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class .addPackage(org.libreccm.tests.categories.IntegrationTest.class

View File

@ -118,7 +118,7 @@ public class ConfigurationManagerTest {
.getPackage()) .getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class .addPackage(org.libreccm.l10n.LocalizedString.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.security.Permission.class.getPackage()) .addPackage(org.libreccm.security.Privilege.class.getPackage())
.addPackage(org.libreccm.web.CcmApplication.class.getPackage()) .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
.addPackage(org.libreccm.workflow.Workflow.class.getPackage()) .addPackage(org.libreccm.workflow.Workflow.class.getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class .addPackage(org.libreccm.tests.categories.IntegrationTest.class

View File

@ -106,7 +106,7 @@ public class CcmObjectRepositoryTest {
.addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
.getPackage()) .getPackage())
.addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()) .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
.addPackage(org.libreccm.security.Permission.class.getPackage()) .addPackage(org.libreccm.security.Privilege.class.getPackage())
.addPackage(org.libreccm.testutils.EqualsVerifier.class.getPackage()) .addPackage(org.libreccm.testutils.EqualsVerifier.class.getPackage())
.addPackage(org.libreccm.tests.categories.IntegrationTest.class .addPackage(org.libreccm.tests.categories.IntegrationTest.class
.getPackage()) .getPackage())

View File

@ -42,7 +42,7 @@ public class EqualsAndHashCodeTest extends EqualsVerifier {
Group.class, Group.class,
GroupMembership.class, GroupMembership.class,
Party.class, Party.class,
Permission.class, Privilege.class,
OneTimeAuthToken.class, OneTimeAuthToken.class,
Role.class, Role.class,
RoleMembership.class, RoleMembership.class,

View File

@ -0,0 +1,43 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.security;
/**
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
public enum ExamplePrivileges implements Privilege {
ADMIN_EXAMPLES,
CREATE_EXAMPLES,
EDIT_EXAMPLES,
PREVIEW_EXAMPLES,
VIEW_EXAMPLES,
PUBLISH_EXAMPLES;
@Override
public String getBundle() {
return "org.libreccm.security.ExamplePrivilegesBundle";
}
@Override
public String getPrefix() {
return "example.privileges";
}
}

View File

@ -0,0 +1,128 @@
/*
* Copyright (C) 2016 LibreCCM Foundation.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA
*/
package org.libreccm.security;
import com.arsdigita.globalization.GlobalizedMessage;
import org.apache.oro.text.GlobCompiler;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.libreccm.tests.categories.UnitTest;
import java.util.Locale;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
/**
* A test for verifying that the default implementations of the methods of the
* {@link Privilege} interface work as expected.
*
* @author <a href="mailto:jens.pelzetter@googlemail.com">Jens Pelzetter</a>
*/
@org.junit.experimental.categories.Category(UnitTest.class)
public class PrivilegeTest {
public PrivilegeTest() {
}
@BeforeClass
public static void setUpClass() {
}
@AfterClass
public static void tearDownClass() {
}
@Before
public void setUp() {
}
@After
public void tearDown() {
}
@Test
public void verifyKeys() {
assertThat(ExamplePrivileges.ADMIN_EXAMPLES.getKey(),
is(equalTo("ADMIN_EXAMPLES")));
assertThat(ExamplePrivileges.CREATE_EXAMPLES.getKey(),
is(equalTo("CREATE_EXAMPLES")));
assertThat(ExamplePrivileges.EDIT_EXAMPLES.getKey(),
is(equalTo("EDIT_EXAMPLES")));
assertThat(ExamplePrivileges.PREVIEW_EXAMPLES.getKey(),
is(equalTo("PREVIEW_EXAMPLES")));
assertThat(ExamplePrivileges.PUBLISH_EXAMPLES.getKey(),
is(equalTo("PUBLISH_EXAMPLES")));
assertThat(ExamplePrivileges.VIEW_EXAMPLES.getKey(),
is(equalTo("VIEW_EXAMPLES")));
}
@Test
public void verifyLabels() {
final GlobalizedMessage adminLabel = ExamplePrivileges.ADMIN_EXAMPLES
.getLabel();
final GlobalizedMessage createLabel = ExamplePrivileges.CREATE_EXAMPLES
.getLabel();
final GlobalizedMessage editLabel = ExamplePrivileges.EDIT_EXAMPLES
.getLabel();
final GlobalizedMessage previewLabel
= ExamplePrivileges.PREVIEW_EXAMPLES
.getLabel();
final GlobalizedMessage publishLabel
= ExamplePrivileges.PUBLISH_EXAMPLES
.getLabel();
final GlobalizedMessage viewLabel = ExamplePrivileges.VIEW_EXAMPLES
.getLabel();
assertThat(adminLabel.localize(Locale.ENGLISH),
is(equalTo("Administer examples")));
assertThat(adminLabel.localize(Locale.GERMAN),
is(equalTo("Beispiele verwalten")));
assertThat(createLabel.localize(Locale.ENGLISH),
is(equalTo("Create new examples")));
assertThat(createLabel.localize(Locale.GERMAN),
is(equalTo("Neue Beispiele anlegen")));
assertThat(editLabel.localize(Locale.ENGLISH),
is(equalTo("Edit examples")));
assertThat(editLabel.localize(Locale.GERMAN),
is(equalTo("Beispiele bearbeiten")));
assertThat(previewLabel.localize(Locale.ENGLISH),
is(equalTo("Preview examples")));
assertThat(previewLabel.localize(Locale.GERMAN),
is(equalTo("Vorschau ansehen")));
assertThat(publishLabel.localize(Locale.ENGLISH),
is(equalTo("Publish examples")));
assertThat(publishLabel.localize(Locale.GERMAN),
is(equalTo("Beispiele veröffentlichen")));
assertThat(viewLabel.localize(Locale.ENGLISH),
is(equalTo("View examples")));
assertThat(viewLabel.localize(Locale.GERMAN),
is(equalTo("Beispiele ansehen")));
}
}

View File

@ -42,7 +42,7 @@ public class ToStringTest extends ToStringVerifier {
GroupMembership.class, GroupMembership.class,
Party.class, Party.class,
OneTimeAuthToken.class, OneTimeAuthToken.class,
Permission.class, Privilege.class,
Role.class, Role.class,
RoleMembership.class, RoleMembership.class,
User.class User.class

View File

@ -0,0 +1,6 @@
example.privileges.ADMIN_EXAMPLES=Administer examples
example.privileges.CREATE_EXAMPLES=Create new examples
example.privileges.EDIT_EXAMPLES=Edit examples
example.privileges.PREVIEW_EXAMPLES=Preview examples
example.privileges.VIEW_EXAMPLES=View examples
example.privileges.PUBLISH_EXAMPLES=Publish examples

View File

@ -0,0 +1,7 @@
example.privileges.ADMIN_EXAMPLES=Beispiele verwalten
example.privileges.CREATE_EXAMPLES=Neue Beispiele anlegen
example.privileges.EDIT_EXAMPLES=Beispiele bearbeiten
example.privileges.PREVIEW_EXAMPLES=Vorschau ansehen
example.privileges.VIEW_EXAMPLES=Beispiele ansehen
example.privileges.PUBLISH_EXAMPLES=Beispiele ver\u00f6ffentlichen