diff --git a/ccm-cms/src/main/java/org/librecms/CmsPrivileges.java b/ccm-cms/src/main/java/org/librecms/CmsPrivileges.java new file mode 100644 index 000000000..3020e83a4 --- /dev/null +++ b/ccm-cms/src/main/java/org/librecms/CmsPrivileges.java @@ -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 Jens Pelzetter + */ +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"; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/categorization/Privileges.java b/ccm-core/src/main/java/org/libreccm/categorization/Privileges.java new file mode 100644 index 000000000..54bf76762 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/categorization/Privileges.java @@ -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 Jens Pelzetter + */ +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"; + } + +} diff --git a/ccm-core/src/main/java/org/libreccm/core/Privileges.java b/ccm-core/src/main/java/org/libreccm/core/Privileges.java new file mode 100644 index 000000000..6ae3149b8 --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/core/Privileges.java @@ -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 Jens Pelzetter + */ +public enum Privileges implements Privilege { + + ADMIN, + SYSTEM; + + @Override + public String getBundle() { + return "org.libreccm.core.PrivilegesBundle"; + } + + @Override + public String getPrefix() { + return "core.privileges"; + } +} diff --git a/ccm-core/src/main/java/org/libreccm/security/Privilege.java b/ccm-core/src/main/java/org/libreccm/security/Privilege.java new file mode 100644 index 000000000..f0ca622fa --- /dev/null +++ b/ccm-core/src/main/java/org/libreccm/security/Privilege.java @@ -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 Jens Pelzetter + */ +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(); + +} diff --git a/ccm-core/src/main/resources/org/libreccm/categorization/PrivilegesBundle.properties b/ccm-core/src/main/resources/org/libreccm/categorization/PrivilegesBundle.properties new file mode 100644 index 000000000..f080cd28a --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/categorization/PrivilegesBundle.properties @@ -0,0 +1,4 @@ + +categorization.privileges.MANAGE_CATEGORIES=Manage categories +categorization.privileges.MANAGE_CATEGORY_OBJECTS=Manage categorized objects +categorization.privileges.MANAGE_DOMAINS=Manage domains diff --git a/ccm-core/src/main/resources/org/libreccm/categorization/PrivilegesBundle_de.properties b/ccm-core/src/main/resources/org/libreccm/categorization/PrivilegesBundle_de.properties new file mode 100644 index 000000000..405d25064 --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/categorization/PrivilegesBundle_de.properties @@ -0,0 +1,4 @@ + +categorization.privileges.MANAGE_CATEGORIES=Kategorien verwalten +categorization.privileges.MANAGE_CATEGORY_OBJECTS=Kategorisierte Objekte verwalten +categorization.privileges.MANAGE_DOMAINS=Domains verwalten diff --git a/ccm-core/src/main/resources/org/libreccm/core/PrivilegesBundle.properties b/ccm-core/src/main/resources/org/libreccm/core/PrivilegesBundle.properties new file mode 100644 index 000000000..a6396d020 --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/core/PrivilegesBundle.properties @@ -0,0 +1,3 @@ + +core.privileges.ADMIN=admin +core.privileges.SYSTEM=system diff --git a/ccm-core/src/main/resources/org/libreccm/core/PrivilegesBundle_de.properties b/ccm-core/src/main/resources/org/libreccm/core/PrivilegesBundle_de.properties new file mode 100644 index 000000000..a6396d020 --- /dev/null +++ b/ccm-core/src/main/resources/org/libreccm/core/PrivilegesBundle_de.properties @@ -0,0 +1,3 @@ + +core.privileges.ADMIN=admin +core.privileges.SYSTEM=system diff --git a/ccm-core/src/test/java/com/arsdigita/kernel/security/SecurityConfigTest.java b/ccm-core/src/test/java/com/arsdigita/kernel/security/SecurityConfigTest.java index 54bfcca6f..454cb370b 100644 --- a/ccm-core/src/test/java/com/arsdigita/kernel/security/SecurityConfigTest.java +++ b/ccm-core/src/test/java/com/arsdigita/kernel/security/SecurityConfigTest.java @@ -35,6 +35,7 @@ import org.junit.After; import org.junit.AfterClass; import static org.junit.Assert.*; + import static org.libreccm.testutils.DependenciesHelpers.*; import org.junit.Before; @@ -46,13 +47,14 @@ import org.libreccm.core.CcmObject; import org.libreccm.jpa.EntityManagerProducer; import org.libreccm.jpa.utils.UriConverter; import org.libreccm.l10n.LocalizedString; -import org.libreccm.security.Permission; import org.libreccm.tests.categories.IntegrationTest; import org.libreccm.web.ApplicationRepository; import org.libreccm.workflow.Workflow; import java.util.List; +import org.libreccm.security.Privilege; + /** * * @author Jens Pelzetter @@ -88,7 +90,7 @@ public class SecurityConfigTest { "LibreCCM-com.arsdigita.kernel.security.SecurityConfigTest.war") .addPackage(CcmObject.class.getPackage()) .addPackage(Categorization.class.getPackage()) - .addPackage(Permission.class.getPackage()) + .addPackage(Privilege.class.getPackage()) .addPackage(LocalizedString.class.getPackage()) .addPackage(Workflow.class.getPackage()) .addPackage(UriConverter.class.getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java b/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java index a20824380..089954032 100644 --- a/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/categorization/CategoryManagerTest.java @@ -141,7 +141,7 @@ public class CategoryManagerTest { .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.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.tests.categories.IntegrationTest.class diff --git a/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java index 0a2ffb676..e4ae596a6 100644 --- a/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java +++ b/ccm-core/src/test/java/org/libreccm/categorization/CategoryRepositoryTest.java @@ -112,7 +112,7 @@ public class CategoryRepositoryTest { .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.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.tests.categories.IntegrationTest.class diff --git a/ccm-core/src/test/java/org/libreccm/configuration/ConfigurationManagerTest.java b/ccm-core/src/test/java/org/libreccm/configuration/ConfigurationManagerTest.java index 9e4aab77c..d401088c4 100644 --- a/ccm-core/src/test/java/org/libreccm/configuration/ConfigurationManagerTest.java +++ b/ccm-core/src/test/java/org/libreccm/configuration/ConfigurationManagerTest.java @@ -118,7 +118,7 @@ public class ConfigurationManagerTest { .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.web.CcmApplication.class.getPackage()) .addPackage(org.libreccm.workflow.Workflow.class.getPackage()) .addPackage(org.libreccm.tests.categories.IntegrationTest.class diff --git a/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java b/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java index 4179e1b50..b98467be4 100644 --- a/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java +++ b/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java @@ -106,7 +106,7 @@ public class CcmObjectRepositoryTest { .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.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.tests.categories.IntegrationTest.class .getPackage()) diff --git a/ccm-core/src/test/java/org/libreccm/security/EqualsAndHashCodeTest.java b/ccm-core/src/test/java/org/libreccm/security/EqualsAndHashCodeTest.java index 0a5195afa..1829d784e 100644 --- a/ccm-core/src/test/java/org/libreccm/security/EqualsAndHashCodeTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/EqualsAndHashCodeTest.java @@ -42,7 +42,7 @@ public class EqualsAndHashCodeTest extends EqualsVerifier { Group.class, GroupMembership.class, Party.class, - Permission.class, + Privilege.class, OneTimeAuthToken.class, Role.class, RoleMembership.class, diff --git a/ccm-core/src/test/java/org/libreccm/security/ExamplePrivileges.java b/ccm-core/src/test/java/org/libreccm/security/ExamplePrivileges.java new file mode 100644 index 000000000..f661d4a69 --- /dev/null +++ b/ccm-core/src/test/java/org/libreccm/security/ExamplePrivileges.java @@ -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 Jens Pelzetter + */ +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"; + } +} diff --git a/ccm-core/src/test/java/org/libreccm/security/PrivilegeTest.java b/ccm-core/src/test/java/org/libreccm/security/PrivilegeTest.java new file mode 100644 index 000000000..9e78f584f --- /dev/null +++ b/ccm-core/src/test/java/org/libreccm/security/PrivilegeTest.java @@ -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 Jens Pelzetter + */ +@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"))); + } + +} diff --git a/ccm-core/src/test/java/org/libreccm/security/ToStringTest.java b/ccm-core/src/test/java/org/libreccm/security/ToStringTest.java index 1055edd78..be8355fcf 100644 --- a/ccm-core/src/test/java/org/libreccm/security/ToStringTest.java +++ b/ccm-core/src/test/java/org/libreccm/security/ToStringTest.java @@ -42,7 +42,7 @@ public class ToStringTest extends ToStringVerifier { GroupMembership.class, Party.class, OneTimeAuthToken.class, - Permission.class, + Privilege.class, Role.class, RoleMembership.class, User.class diff --git a/ccm-core/src/test/resources/org/libreccm/security/ExamplePrivilegesBundle.properties b/ccm-core/src/test/resources/org/libreccm/security/ExamplePrivilegesBundle.properties new file mode 100644 index 000000000..c1a024b2a --- /dev/null +++ b/ccm-core/src/test/resources/org/libreccm/security/ExamplePrivilegesBundle.properties @@ -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 diff --git a/ccm-core/src/test/resources/org/libreccm/security/ExamplePrivilegesBundle_de.properties b/ccm-core/src/test/resources/org/libreccm/security/ExamplePrivilegesBundle_de.properties new file mode 100644 index 000000000..38cbffc8d --- /dev/null +++ b/ccm-core/src/test/resources/org/libreccm/security/ExamplePrivilegesBundle_de.properties @@ -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