appConfigs) {
- this.appConfigs = appConfigs;
- }
-
- @Override
- public AppConfigurationEntry[] getAppConfigurationEntry(final String name) {
- return appConfigs.get(name);
- }
-
- @Override
- public void refresh() {
- // Nothing
- }
-
-}
diff --git a/ccm-core/src/main/java/org/libreccm/core/authentication/LoginConfigBuilder.java.nolongerinuse b/ccm-core/src/main/java/org/libreccm/core/authentication/LoginConfigBuilder.java.nolongerinuse
deleted file mode 100644
index 078acc3e3..000000000
--- a/ccm-core/src/main/java/org/libreccm/core/authentication/LoginConfigBuilder.java.nolongerinuse
+++ /dev/null
@@ -1,311 +0,0 @@
-/*
- * Copyright (C) 2015 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.authentication;
-
-import com.arsdigita.kernel.security.SecurityConfig;
-import com.arsdigita.runtime.ConfigError;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Locale;
-import java.util.Map;
-
-import javax.security.auth.login.AppConfigurationEntry;
-import javax.security.auth.spi.LoginModule;
-
-/**
- * Creates a {@link LoginConfig} instance from an array or an list of strings.
- *
- * The process of creating a {@link LoginConfig} instance from the string values
- * like those stored in the {@link SecurityConfig} is a complex process.
- * Originally the constructor of the
- * {@code com.arsdigita.kernel.security.LoginConfig} class has done all this
- * work. Some parts were outsourced to private methods.
- *
- * The problem with this approach is that several of this method may throw an
- * exception/error. But throwing exceptions from a constructor is considered a
- * bad practise. Also the private support methods made the original
- * {@code LoginConfig} class quite big and complex. Therefore the code has been
- * split up. The construction process is now done by this class which creates
- * {@code LoginConfig} from a provided list or array of strings. The strings
- * must be in the correct format:
- *
- *
- * context:moduleName:controlFlag[:option1[:option2[:...]]]
- *
- *
- *
- * - {@code context}
- * - String
- *
- * - {@code moduleName}
- * - Fully qualified class name of a {@link LoginModule}.
- *
- * - {@code controlFlag}
- * -
- * One of the following flags:
- *
- * - {@code required}
- * - {@code requisite}
- * - {@code sufficient}
- * - {@code optional}
- *
- *
- *
- * - option
- * - Options for the module in the following format: {@code key=value}
- *
- *
- * Examples:
- *
- *
- * Request:com.arsdigita.kernel.security.CredentialLoginModule:requisite:debug=true
- * Register:com.arsdigita.kernel.security.LocalLoginModule:requisite
- * Register:com.arsdigita.kernel.security.UserIDLoginModule:requisite
- * Register:com.arsdigita.kernel.security.CredentialLoginModule:optional
- *
- *
- * The build a {@link LoginConfig} first construct an instance of this class and
- * pass the string array containing the configuration. For example:
- *
- *
- * final LoginConfigBuilder loginConfigBuilder =
- * new LoginConfigBuilder(SecurityConfig.getInstance().getLoginConfig());
- *
- *
- * Then call the {@link #build()} method which does all the work:
- *
- *
- * final LoginConfig loginConfig = loginConfigBuilder.build();
- *
- *
- * @author Jens Pelzetter
- */
-public class LoginConfigBuilder {
-
- private final transient String[] config;
-
- /**
- * Creates a new {@code LoginConfigBuilder} for the provided configuration.
- *
- * @param config The configuration for which an {@link LoginConfig} should
- * be created, as array of strings as provided by
- * {@link SecurityConfig#getLoginConfig()}.
- */
- @SuppressWarnings("PMD.UseVarargs") //Can't use varargs here
- public LoginConfigBuilder(final String[] config) {
- this.config = new String[config.length];
- System.arraycopy(config, 0, this.config, 0, config.length);
- }
-
- /**
- * Creates a {@link LoginConfig} from {@link #config}.
- *
- * If one entry of the {@link #config} is malformed a {@link ConfigError}
- * will be thrown.
- *
- * @return A {@link LoginConfig} object.
- */
- public LoginConfig build() {
- //Temporary storage for the data extracted from the config string array.
- final Map> contextConfigs = new HashMap<>();
-
- //Parse the tuples in the config string array.
- for (final String tuple : config) {
- //Find the index of the first ':'.
- final int index = tuple.indexOf(':');
- //Extract context and module config parts from the tuple.
- final String context = tuple.substring(0, index);
- final String moduleConfig = tuple.substring(index + 1);
-
- //Put them in the list for the context.
- final List contextConfig = retrieveContextConfig(
- context, contextConfigs);
- contextConfig.add(moduleConfig);
-
- }
-
- //Create the map of AppConfigurationEntry objects.
- final Map appConfigs = new HashMap<>();
- for (final Map.Entry> entry : contextConfigs
- .entrySet()) {
- //Add the config entry. The helper method called creates the
- //AppConfigurationEntry object from the string value.
- addAppConfig(appConfigs, entry.getKey(), entry.getValue());
- }
-
- //Create the LoginConfig object with the Map of AppConfigurationEntries.
- return new LoginConfig(appConfigs);
-
- }
-
- /**
- * Helper method for retrieving a list for specific context from the context
- * maps. Used by {@link #build()}. If the map has no entry with the provided
- * name a new list is created a put into the list.
- *
- * @param context The name of the context, used as key in the
- * provided map.
- * @param contextConfigs The map of context configs.
- *
- * @return The context configs list for the provided context.
- */
- private List retrieveContextConfig(
- final String context, final Map> contextConfigs) {
- List contextConfig = contextConfigs.get(context);
-
- if (contextConfig == null) {
- contextConfig = new ArrayList<>();
- contextConfigs.put(context, contextConfig);
- }
-
- return contextConfig;
- }
-
- /**
- * Helper method for creating an {@link AppConfigurationEntry} object from a
- * string.
- *
- * @param appConfigs The map of {@link AppConfigurationEntry} objects in
- * which the created entry will be stored.
- * @param name The name of the context for which the
- * {@link AppConfigurationEntry} is created.
- * @param entries The list of configuration entries to parse.
- */
- private void addAppConfig(
- final Map appConfigs,
- final String name,
- final List entries) {
-
- //Map containing the parsed entries
- final AppConfigurationEntry[] configEntries
- = new AppConfigurationEntry[entries
- .size()];
-
- //Parse all entries. We use a "traditional" for loop here because we
- //need the position in the array.
- for (int i = 0; i < entries.size(); i++) {
- //Load the current configuration entry.
- configEntries[i] = loadAppConfigEntry(entries.get(i));
- }
-
- //Put the parsed entires into the map
- appConfigs.put(name, configEntries);
- }
-
- /**
- * Helper method for parsing a single configuration entry. The
- *
- * tokens entry
- *
- * @return
- */
- private AppConfigurationEntry loadAppConfigEntry(final String entry) {
- //Split the string tokens. The tokens are limited by the ':' character.
- final String[] tokens = entry.split(":");
-
- //If there less then two tokens the entry is malformed and we throw an
- //ConfigError.
- if (tokens.length < 2) {
- final StringBuilder builder = new StringBuilder();
- for (final String str : tokens) {
- builder.append(str);
- }
- throw new ConfigError(String.format(
- "Malformed SecurityConfig entry: %s", builder.toString()));
- }
-
- //Extract the name of the configured module (the first token)
- final String name = tokens[0];
- //Extract the flat (second token)
- final AppConfigurationEntry.LoginModuleControlFlag flag = parseFlag(
- tokens[1]);
-
- //Extract the provided options if any
- final Map options = new HashMap<>();
- if (tokens.length > 2) {
- for (int i = 2; i < tokens.length; i++) {
- //The the option to the map of options.
- addOption(tokens[i], options);
- }
- }
-
- //Create an AppConfguration using the extracted data.
- return new AppConfigurationEntry(name, flag, options);
- }
-
- /**
- * Helper method to convert a string to a
- * {@link AppConfigurationEntry.LoginModuleControlFlag}. If the provided
- * string is not a valid flag a {@link ConfigError} is thrown.
- *
- * @param flag The string to convert.
- *
- * @return {@link AppConfigurationEntry.LoginModuleControlFlag} instance.
- */
- private AppConfigurationEntry.LoginModuleControlFlag parseFlag(
- final String flag) {
- switch (flag.toUpperCase(Locale.ROOT)) {
- case "REQUISITE":
- return AppConfigurationEntry.LoginModuleControlFlag.REQUISITE;
-
- case "REQUIRED":
- return AppConfigurationEntry.LoginModuleControlFlag.REQUIRED;
-
- case "SUFFICIENT":
- return AppConfigurationEntry.LoginModuleControlFlag.SUFFICIENT;
-
- case "OPTIONAL":
- return AppConfigurationEntry.LoginModuleControlFlag.OPTIONAL;
-
- default:
- throw new ConfigError(String.format(
- "Unknown flag \"%s\". Valid flags are: REQUISITE, "
- + "REQUIRED, SUFFICIENT, OPTIONAL",
- flag));
- }
-
- }
-
- /**
- * Helper method for extracting the key and value parts from an module
- * option string. If the option string is malformed an {@link ConfigError}
- * is thrown.
- *
- * @param option The option string to parse.
- * @param options The map of options to which the parsed option we be added.
- */
- private void addOption(final String option,
- final Map options) {
- //Find the index of the '=' character.
- final int index = option.indexOf('=');
- //If there is no '=' in the string the option string is invalid
- if (index == -1) {
- throw new ConfigError(String.format(
- "The option string \"%s\" is malformed.", option));
- }
-
- //Extract key and value an put them into the options map.
- final String key = option.substring(0, index);
- final String value = option.substring(index + 1);
- options.put(key, value);
- }
-
-}
diff --git a/ccm-core/src/main/java/org/libreccm/core/authentication/LoginManager.java.nolongerinuse b/ccm-core/src/main/java/org/libreccm/core/authentication/LoginManager.java.nolongerinuse
deleted file mode 100644
index ae9464d01..000000000
--- a/ccm-core/src/main/java/org/libreccm/core/authentication/LoginManager.java.nolongerinuse
+++ /dev/null
@@ -1,121 +0,0 @@
-/*
- * Copyright (C) 2015 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.authentication;
-
-import org.libreccm.core.CcmSessionContext;
-import org.libreccm.core.User;
-
-import java.io.IOException;
-import java.util.Iterator;
-import java.util.Set;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-import javax.security.auth.Subject;
-import javax.security.auth.callback.Callback;
-import javax.security.auth.callback.CallbackHandler;
-import javax.security.auth.callback.NameCallback;
-import javax.security.auth.callback.PasswordCallback;
-import javax.security.auth.callback.UnsupportedCallbackException;
-import javax.security.auth.login.LoginContext;
-import javax.security.auth.login.LoginException;
-
-/**
- * Provides methods for authenticating a user and for logging out a user.
- *
- * Under the hood JAAS is used for authentication.
- *
- * If a user is authenticated successfully the user object is stored in the
- * session scoped bean {@link CcmSessionContext}.
- *
- * @author Jens Pelzetter
- */
-@RequestScoped
-public class LoginManager {
-
- /**
- * Name of the register login context.
- */
- private static final String LOGIN_CONTEXT = "Register";
-
- @Inject
- private transient CcmSessionContext sessionContext;
-
-// @Inject
-// private transient UserRepository userRepository;
-
- public void login(final String username, final String password)
- throws LoginException {
-
- final CallbackHandler callbackHandler = new LoginCallbackHandler(
- username, password);
- final LoginContext loginContext = new LoginContext(
- LOGIN_CONTEXT,
- callbackHandler);
- loginContext.login();
- final Subject subject = loginContext.getSubject();
-
- final Set principals = subject.getPrincipals(
- UserPrincipal.class);
- if (principals.isEmpty()) {
- throw new LoginException("No principal set");
- } else {
- final Iterator iterator = principals.iterator();
- final UserPrincipal principal = iterator.next();
- final User user = principal.getUser();
-
- sessionContext.setCurrentSubject(user);
- }
- }
-
- public void logout() {
- sessionContext.setCurrentSubject(null);
- }
-
- private static class LoginCallbackHandler implements CallbackHandler {
-
- private final transient String username;
- private final transient String password;
-
- public LoginCallbackHandler(final String username,
- final String password) {
- this.username = username;
- this.password = password;
- }
-
- @Override
- @SuppressWarnings("PMD.UseVarargs") //Can't use varargs here
- public void handle(final Callback[] callbacks)
- throws IOException, UnsupportedCallbackException {
-
- for (final Callback callback : callbacks) {
- if (callback instanceof NameCallback) {
- ((NameCallback) callback).setName(username);
- } else if (callback instanceof PasswordCallback) {
- ((PasswordCallback) callback).setPassword(password
- .toCharArray());
- } else {
- throw new UnsupportedCallbackException(callback);
- }
- }
- }
-
- }
-
-}
diff --git a/ccm-core/src/main/java/org/libreccm/core/authentication/UserPrincipal.java.nolongerinuse b/ccm-core/src/main/java/org/libreccm/core/authentication/UserPrincipal.java.nolongerinuse
deleted file mode 100644
index cdc97391e..000000000
--- a/ccm-core/src/main/java/org/libreccm/core/authentication/UserPrincipal.java.nolongerinuse
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (C) 2015 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.authentication;
-
-import java.security.Principal;
-import java.util.Objects;
-import org.libreccm.core.User;
-
-/**
- *
- * @author Jens Pelzetter
- */
-public final class UserPrincipal implements Principal {
-
- private final User user;
-
- public UserPrincipal(final User user) {
- this.user = user;
- }
-
- public User getUser() {
- return user;
- }
-
- @Override
- public String getName() {
- return user.getScreenName();
- }
-
- @Override
- public int hashCode() {
- int hash = 5;
- hash = 41 * Objects.hash(user);
- return hash;
- }
-
- @Override
- public boolean equals(final Object obj) {
- if (obj == null) {
- return false;
- }
- if (getClass() != obj.getClass()) {
- return false;
- }
- final UserPrincipal other = (UserPrincipal) obj;
- return Objects.equals(user, other.getUser());
- }
-
- @Override
- public String toString() {
- return String.format("%s{ "
- + "user = %s"
- + " }",
- super.toString(),
- Objects.toString(user));
- }
-
-}
diff --git a/ccm-core/src/main/java/org/libreccm/security/PermissionChecker.java b/ccm-core/src/main/java/org/libreccm/security/PermissionChecker.java
index 380e20a9c..f324462e8 100644
--- a/ccm-core/src/main/java/org/libreccm/security/PermissionChecker.java
+++ b/ccm-core/src/main/java/org/libreccm/security/PermissionChecker.java
@@ -18,6 +18,8 @@
*/
package org.libreccm.security;
+import static org.libreccm.core.CoreConstants.*;
+
import org.apache.shiro.authz.AuthorizationException;
import org.apache.shiro.subject.Subject;
import org.libreccm.core.CcmObject;
@@ -50,14 +52,14 @@ public class PermissionChecker {
* @param privilege The privilege granted by the permission.
*
* @return {@code true} if the current subject has as permission granting
- * the provided {@code privilege}, {@code false} otherwise.
+ * the provided {@code privilege}, {@code false} otherwise.
*/
public boolean isPermitted(final String privilege) {
if (subject.isAuthenticated()) {
return subject.isPermitted(generatePermissionString(privilege));
} else {
return shiro.getPublicUser().isPermitted(generatePermissionString(
- privilege));
+ privilege));
}
}
@@ -67,19 +69,19 @@ public class PermissionChecker {
* implements the {@link InheritsPermissions} interface.
*
* @param privilege The granted privilege.
- * @param object The object on which the privilege is granted.
+ * @param object The object on which the privilege is granted.
*
* @return {@code true} if the there is a permission granting the provided
- * {@code privilege} on the provided {@code subject}.
+ * {@code privilege} on the provided {@code subject}.
*/
public boolean isPermitted(final String privilege, final CcmObject object) {
final boolean result;
if (subject.isAuthenticated()) {
result = subject.isPermitted(generatePermissionString(
- privilege, object));
+ privilege, object));
} else {
result = shiro.getPublicUser().isPermitted(generatePermissionString(
- privilege, object));
+ privilege, object));
}
if (result) {
return result;
@@ -101,48 +103,38 @@ public class PermissionChecker {
* privilege an {@link AuthorizationExeeption} is thrown.
*
* @param privilege The privilege to check for.
+ *
* @throws AuthorizationException If the current subject has not permission
- * granting the provided privilege.
+ * granting the provided privilege.
*/
public void checkPermission(final String privilege)
- throws AuthorizationException {
+ throws AuthorizationException {
if (subject.isAuthenticated()) {
subject.checkPermission(generatePermissionString(privilege));
} else {
shiro.getPublicUser().checkPermission(generatePermissionString(
- privilege));
+ privilege));
}
}
/**
* Checks if the current subject has a permission granting the provided
- * privilege on the provided object. If there is a permission which grants
- * the current subject the provided privilege on the provided object the
- * method returns the object. Otherwise an {@link AuthorizationException} is
- * thrown. This also the use this method in methods which are loading
- * objects from the database like this
- *
- * public CcmObject findBy(...) {
- * // Do JPA stuff
- *
- * return permissionChecker.checkPermission($privilege, object);
- * }
- *
+ * privilege on the provided object.
*
* If the object implements the {@link InheritsPermissions} interface the
* method also checks the parent objects for a permission granting the
* provided privilege.
*
* @param privilege The privilige to check for.
- * @param object The object on which the privilege is granted.
- * @return Th provided object if there is permission granting the current
- * subject the provided privilege on the object.
- * @throws AuthorizationException If there is not permission granting the
- * current subject the provided privilege on the provided object.
+ * @param object The object on which the privilege is granted.
+ *
+ * @throws AuthorizationException If there is no permission granting the
+ * provided privilege to the current subject
+ * on the provided object..
*/
- public CcmObject checkPermission(final String privilege,
- final CcmObject object)
- throws AuthorizationException {
+ public void checkPermission(final String privilege,
+ final CcmObject object)
+ throws AuthorizationException {
if (object instanceof InheritsPermissions) {
final boolean result = isPermitted(privilege, object);
@@ -160,16 +152,53 @@ public class PermissionChecker {
subject.checkPermission(generatePermissionString(privilege, object));
} else {
shiro.getPublicUser().checkPermission(generatePermissionString(
- privilege, object));
+ privilege, object));
}
+ }
- return object;
+ /**
+ * Checks if the current subject has a permission granting the provided
+ * privilege on the provided object. Returns the object of the current
+ * subject is permitted to access the object. Otherwise a virtual
+ * placeholder object is returned with the {@link CcmObject#displayName}
+ * property set the {@code Access denied}.
+ *
+ * @param The type of the object to check.
+ * @param privilege The privilige to check for.
+ * @param object The object on which the privilege is granted.
+ * @param clazz The class of the object.
+ *
+ * @return The object if the current subject is permitted to access, a
+ * placeholder object if not.
+ */
+ public T checkPermission(final String privilege,
+ final T object,
+ final Class clazz) {
+ final SecuredHelper securedHelper = new SecuredHelper<>(clazz,
+ privilege);
+ return securedHelper.canAccess(object);
+ }
+
+ /**
+ * Checks if a CcmObject is a virtual Access Denied object.
+ *
+ * @param object The object to check.
+ *
+ * @return {@code true} if the object is a Access denied object,
+ * {@code false} if not.
+ */
+ public boolean isAccessDeniedObject(final CcmObject object) {
+ if (object == null) {
+ return false;
+ }
+ return ACCESS_DENIED.equals(object.getDisplayName());
}
/**
* Helper method for converting a privilege into a permission string.
*
* @param privilege
+ *
* @return
*/
public String generatePermissionString(final String privilege) {
@@ -181,6 +210,7 @@ public class PermissionChecker {
*
* @param privilege
* @param object
+ *
* @return
*/
public String generatePermissionString(final String privilege,
diff --git a/ccm-core/src/main/java/org/libreccm/security/SecuredHelper.java b/ccm-core/src/main/java/org/libreccm/security/SecuredHelper.java
index 1011e663d..9cebf420d 100644
--- a/ccm-core/src/main/java/org/libreccm/security/SecuredHelper.java
+++ b/ccm-core/src/main/java/org/libreccm/security/SecuredHelper.java
@@ -19,6 +19,9 @@
package org.libreccm.security;
import com.arsdigita.util.UncheckedWrapperException;
+
+import static org.libreccm.core.CoreConstants.*;
+
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.libreccm.cdi.utils.CdiLookupException;
@@ -90,8 +93,8 @@ class SecuredHelper {
protected E generateAccessDeniedObject() {
try {
final E placeholder = clazz.newInstance();
- placeholder.setDisplayName("Access denied");
-
+ placeholder.setDisplayName(ACCESS_DENIED);
+
return placeholder;
} catch (InstantiationException | IllegalAccessException ex) {
LOGGER.error(
diff --git a/ccm-core/src/main/java/org/libreccm/security/SecuredIterator.java b/ccm-core/src/main/java/org/libreccm/security/SecuredIterator.java
index eeb4c1832..625d58505 100644
--- a/ccm-core/src/main/java/org/libreccm/security/SecuredIterator.java
+++ b/ccm-core/src/main/java/org/libreccm/security/SecuredIterator.java
@@ -32,7 +32,7 @@ import java.util.Iterator;
public class SecuredIterator implements Iterator {
private final Iterator iterator;
-
+
private final SecuredHelper securedHelper;
/**
@@ -62,7 +62,7 @@ public class SecuredIterator implements Iterator {
/**
* Returns the next object of the current subject it permitted to access it
- * or a special "Access denied" object if not.
+ * or a special Access denied object if not.
*
* The method gets the next object from the wrapped {@code Iterator} and
* checks if the current subject has a permission granting the privilege
@@ -73,7 +73,8 @@ public class SecuredIterator implements Iterator {
* {@link CcmObject#displayName} of these placeholder objects is set the
* {@code Access denied}.
*
- * @return The next object or a special "Access denied" placeholder object.
+ * @return The next object or a special Access denied placeholder
+ * object.
*/
@Override
public E next() {
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 d30e09728..290acc341 100644
--- a/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java
+++ b/ccm-core/src/test/java/org/libreccm/core/CcmObjectRepositoryTest.java
@@ -18,6 +18,8 @@
*/
package org.libreccm.core;
+import static org.libreccm.core.CoreConstants.*;
+
import static org.hamcrest.CoreMatchers.*;
import org.jboss.arquillian.container.test.api.Deployment;
diff --git a/ccm-core/src/test/java/org/libreccm/core/GroupManagerTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/GroupManagerTest.java.nolongerinuse
deleted file mode 100644
index f36f56aaf..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/GroupManagerTest.java.nolongerinuse
+++ /dev/null
@@ -1,348 +0,0 @@
-/*
- * Copyright (C) 2015 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 static org.hamcrest.Matchers.*;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.ShouldThrowException;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.ShouldMatchDataSet;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.io.File;
-
-import javax.inject.Inject;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class GroupManagerTest {
-
- @Inject
- private transient GroupManager groupManager;
-
- @Inject
- private transient UserRepository userRepository;
-
- @Inject
- private transient GroupRepository groupRepository;
-
- public GroupManagerTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom.
- importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- "LibreCCM-org.libreccm.core.GroupManagerTest.war")
- .addPackage(User.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
- addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
- }
-
- /**
- * Verify the
- * {@link GroupManager#isMemberOfGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * method.
- */
- @Test
- @InSequence(10)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- public void isMemberOfGroup() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final Group admins = groupRepository.findByGroupName("admins");
- final Group users = groupRepository.findByGroupName("users");
- final Group authors = groupRepository.findByGroupName("authors");
-
- assertThat(groupManager.isMemberOfGroup(jdoe, admins), is(false));
- assertThat(groupManager.isMemberOfGroup(jdoe, users), is(true));
- assertThat(groupManager.isMemberOfGroup(jdoe, authors), is(true));
- }
-
- /**
- * Verify that
- * {@link GroupManager#isMemberOfGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * throws an {@link IllegalArgumentException} if the provided {@code user}
- * is {@code null}.
- */
- @Test(expected = IllegalArgumentException.class)
- @InSequence(20)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- public void isMemberOfGroupNullUser() {
- final Group admins = groupRepository.findByGroupName("admins");
-
- groupManager.isMemberOfGroup(null, admins);
- }
-
- /**
- * Verify that
- * {@link GroupManager#isMemberOfGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * throws an {@link IllegalArgumentException} if the provided {@code group}
- * is {@code null}.
- */
- @Test(expected = IllegalArgumentException.class)
- @InSequence(30)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- public void isMemberOfGroupNullGroup() {
- final User jdoe = userRepository.findByScreenName("jdoe");
-
- groupManager.isMemberOfGroup(jdoe, null);
- }
-
- /**
- * Verify that the
- * {@link GroupManager#addUserToGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * method adds an user to a group and stores the changed group and user
- * correctly to the database.
- */
- @Test
- @InSequence(40)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/GroupManagerTest/"
- + "after-add-to-group.yml",
- excludeColumns = {"membership_id"})
- public void addUserToGroup() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final Group admins = groupRepository.findByGroupName("admins");
-
- groupManager.addUserToGroup(jdoe, admins);
-
- assertThat(groupManager.isMemberOfGroup(jdoe, admins), is(true));
- }
-
- /**
- * Verify that
- * {@link GroupManager#addUserToGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * throws an {@link IllegalArgumentException} if the provided {@code user}
- * is {@code null}.
- */
- @Test(expected = IllegalArgumentException.class)
- @InSequence(50)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml",
- excludeColumns = {"membership_id"})
- @ShouldThrowException(IllegalArgumentException.class)
- public void addUserToGroupNullUser() {
- final Group admins = groupRepository.findByGroupName("admins");
-
- groupManager.addUserToGroup(null, admins);
- }
-
- /**
- * Verify that
- * {@link GroupManager#addUserToGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * throws an {@link IllegalArgumentException} if the provided {@code group}
- * is {@code null}.
- */
- @Test(expected = IllegalArgumentException.class)
- @InSequence(60)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml",
- excludeColumns = {"membership_id"})
- @ShouldThrowException(IllegalArgumentException.class)
- public void addUserToGroupNullGroup() {
- final User jdoe = userRepository.findByScreenName("jdoe");
-
- groupManager.addUserToGroup(jdoe, null);
- }
-
- /**
- * Verify that the
- * {@link GroupManager#addUserToGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * does nothing if the provided user is already a member of the provided
- * group.
- */
- @Test
- @InSequence(70)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml",
- excludeColumns = {"membership_id"})
- public void addUserToGroupAlreadyMember() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final Group authors = groupRepository.findByGroupName("authors");
-
- groupManager.addUserToGroup(jdoe, authors);
- }
-
- /**
- * Verify that
- * {@link GroupManager#removeUserFromGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * really removes a user from a group and stores the changed user and group
- * in the database.
- */
- @Test
- @InSequence(80)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/GroupManagerTest/"
- + "after-remove-from-group.yml",
- excludeColumns = {"membership_id"})
- public void removeUserFromGroup() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final Group authors = groupRepository.findByGroupName("authors");
-
- groupManager.removeUserFromGroup(jdoe, authors);
-
- assertThat(groupManager.isMemberOfGroup(jdoe, authors), is(false));
- }
-
- /**
- * Verify that
- * {@link GroupManager#removeUserFromGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * throws an {@link IllegalArgumentException} if the provided {@code user}
- * is {@code null}.
- */
- @Test(expected = IllegalArgumentException.class)
- @InSequence(90)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml",
- excludeColumns = {"membership_id"})
- @ShouldThrowException(IllegalArgumentException.class)
- public void removeUserFromGroupNullUser() {
- final Group authors = groupRepository.findByGroupName("authors");
-
- groupManager.removeUserFromGroup(null, authors);
- }
-
- /**
- * Verify that
- * {@link GroupManager#removeUserFromGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * throws an {@link IllegalArgumentException} if the provided {@code group}
- * is {@code null}.
- */
- @Test(expected = IllegalArgumentException.class)
- @InSequence(100)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml",
- excludeColumns = {"membership_id"})
- @ShouldThrowException(IllegalArgumentException.class)
- public void removeUserFromGroupNullGroup() {
- final User jdoe = userRepository.findByScreenName("jdoe");
-
- groupManager.removeUserFromGroup(jdoe, null);
- }
-
- /**
- * Verify that
- * {@link GroupManager#removeUserFromGroup(org.libreccm.core.User, org.libreccm.core.Group)}
- * does nothing if the provided {@code user} is not a member of the provided
- * {@code group}.
- */
- @Test
- @InSequence(110)
- @UsingDataSet("datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/GroupManagerTest/"
- + "users-groups.yml",
- excludeColumns = {"membership_id"})
- public void removeUserFromGroupNotMember() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final Group admins = groupRepository.findByGroupName("admins");
-
- groupManager.removeUserFromGroup(jdoe, admins);
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/GroupRepositoryTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/GroupRepositoryTest.java.nolongerinuse
deleted file mode 100644
index 5fde99ef5..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/GroupRepositoryTest.java.nolongerinuse
+++ /dev/null
@@ -1,209 +0,0 @@
-/*
- * Copyright (C) 2015 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 static org.hamcrest.Matchers.*;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.ShouldThrowException;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.ShouldMatchDataSet;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.io.File;
-
-import javax.inject.Inject;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class GroupRepositoryTest {
-
- @Inject
- private transient GroupRepository groupRepository;
-
- public GroupRepositoryTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom.
- importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- "LibreCCM-org.libreccm.core.UserRepositoryTest.war")
- .addPackage(User.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
- addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
- }
-
- private void verifyGroups(final Group admins,
- final Group users,
- final Group authors,
- final Group none) {
- assertThat(admins, is(not(nullValue())));
- assertThat(admins.getName(), is(equalTo("admins")));
-
- assertThat(users, is(not(nullValue())));
- assertThat(users.getName(), is(equalTo("users")));
-
- assertThat(authors, is(not(nullValue())));
- assertThat(authors.getName(), is(equalTo("authors")));
-
- assertThat(none, is(nullValue()));
-
- }
-
- @Test
- @InSequence
- @UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.yml")
- public void findGroupById() {
- final Group admins = groupRepository.findById(-10L);
- final Group users = groupRepository.findById(-20L);
- final Group authors = groupRepository.findById(-30L);
- final Group none = groupRepository.findById(-999L);
-
- verifyGroups(admins, users, authors, none);
- }
-
- @Test
- @InSequence(20)
- @UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.yml")
- public void findGroupByName() {
- final Group admins = groupRepository.findByGroupName("admins");
- final Group users = groupRepository.findByGroupName("users");
- final Group authors = groupRepository.findByGroupName("authors");
- final Group none = groupRepository.findByGroupName("none");
-
- verifyGroups(admins, users, authors, none);
- }
-
- @Test
- @InSequence(30)
- @UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.yml")
- @ShouldMatchDataSet(value
- = "datasets/org/libreccm/core/GroupRepositoryTest/after-save-new.yml",
- excludeColumns = "subject_id")
- public void saveNewGroup() {
- final Group publishers = new Group();
- publishers.setName("publishers");
-
- groupRepository.save(publishers);
- }
-
- @Test
- @InSequence(40)
- @UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.yml")
- @ShouldMatchDataSet(value
- = "datasets/org/libreccm/core/GroupRepositoryTest/after-save-changed.yml",
- excludeColumns = {"subject_id"})
- public void saveChangedGroup() {
- final Group group = groupRepository.findByGroupName("authors");
- group.setName("editors");
-
- groupRepository.save(group);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(50)
- public void saveNullValue() {
- groupRepository.save(null);
- }
-
- @Test
- @InSequence(60)
- @UsingDataSet("datasets/org/libreccm/core/GroupRepositoryTest/data.yml")
- @ShouldMatchDataSet(
- "datasets/org/libreccm/core/GroupRepositoryTest/after-delete.yml")
- public void deleteGroup() {
- final Group group = groupRepository.findByGroupName("users");
-
- groupRepository.delete(group);
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/PermissionManagerTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/PermissionManagerTest.java.nolongerinuse
deleted file mode 100644
index 82e9ac3ee..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/PermissionManagerTest.java.nolongerinuse
+++ /dev/null
@@ -1,632 +0,0 @@
-/*
- * Copyright (C) 2015 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 static org.hamcrest.Matchers.*;
-
-import java.io.File;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.ShouldThrowException;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.ShouldMatchDataSet;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import javax.inject.Inject;
-
-import static org.junit.Assert.*;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class PermissionManagerTest {
-
- private static final String TEST_OBJECT_1 = "Test Object 1";
- private static final String TEST_OBJECT_2 = "Test Object 2";
- private static final String TEST_OBJECT_3 = "Test Object 3";
- private static final String TEST_OBJECT_4 = "Test Object 4";
- private static final String TEST_OBJECT_5 = "Test Object 5";
- private static final String TEST_OBJECT_6 = "Test Object 6";
- private static final String TEST_OBJECT_7 = "Test Object 7";
- private static final String TEST_OBJECT_8 = "Test Object 8";
-
- private static final String ADMIN = "admin";
- private static final String READ = "read";
- private static final String WRITE = "write";
-
- @Inject
- private transient PermissionManager permissionManager;
-
- @Inject
- private transient PrivilegeRepository privilegeRepository;
-
- @Inject
- private transient CcmObjectRepository ccmObjectRepository;
-
- @Inject
- private transient UserRepository userRepository;
-
- @Inject
- private transient GroupRepository groupRepository;
-
- public PermissionManagerTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom.
- importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- String.format("LibreCCM-%s.war",
- PermissionManagerTest.class.getName()))
- .addPackage(User.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
- addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
- }
-
- private Map retrieveTestObjects() {
- final long[] objectIds = {-10, -20, -30, -40, -50, -60, -70, -80};
-
- final Map objects = new LinkedHashMap<>();
-
- for (final long objectId : objectIds) {
- final CcmObject object = ccmObjectRepository.findById(objectId);
- objects.put(object.getDisplayName(), object);
- }
-
- return objects;
- }
-
- private Map retrievePrivileges() {
- final String[] privilegLabels = {"admin", "read", "write"};
-
- final Map privileges = new LinkedHashMap<>();
-
- for (final String label : privilegLabels) {
- final Privilege privilege = privilegeRepository.retrievePrivilege(
- label);
- privileges.put(label, privilege);
- }
-
- return privileges;
- }
-
- private void verifyIsPermitted(final Subject subject,
- final Privilege privilege,
- final Map expected) {
- final String subjectName;
- if (subject instanceof User) {
- subjectName = ((User) subject).getScreenName();
- } else if (subject instanceof Group) {
- subjectName = ((Group) subject).getName();
- } else {
- subjectName = "???";
- }
- for (Map.Entry entry : expected.entrySet()) {
- assertThat(String.format("isPermitted should return %b for subject "
- + "%s and privilege %s on object %s.",
- entry.getValue(),
- subjectName,
- privilege.getLabel(),
- entry.getKey().getDisplayName()),
- permissionManager.isPermitted(privilege,
- entry.getKey(),
- subject),
- is(entry.getValue()));
- }
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(10)
- public void isPermittedWebmasterAdmin() {
- final User webmaster = userRepository.findByScreenName("webmaster");
- final Map testObjects = retrieveTestObjects();
- final Map privileges = retrievePrivileges();
-
- final Map expected = new LinkedHashMap<>();
- expected.put(testObjects.get(TEST_OBJECT_1), true);
- expected.put(testObjects.get(TEST_OBJECT_2), true);
- expected.put(testObjects.get(TEST_OBJECT_3), true);
- expected.put(testObjects.get(TEST_OBJECT_4), true);
- expected.put(testObjects.get(TEST_OBJECT_5), true);
- expected.put(testObjects.get(TEST_OBJECT_6), true);
- expected.put(testObjects.get(TEST_OBJECT_7), true);
- expected.put(testObjects.get(TEST_OBJECT_8), true);
-
- verifyIsPermitted(webmaster, privileges.get(ADMIN), expected);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(11)
- public void isPermittedWebmasterRead() {
- final User webmaster = userRepository.findByScreenName("webmaster");
- final Map testObjects = retrieveTestObjects();
- final Map privileges = retrievePrivileges();
-
- final Map expected = new LinkedHashMap<>();
- expected.put(testObjects.get(TEST_OBJECT_1), true);
- expected.put(testObjects.get(TEST_OBJECT_2), true);
- expected.put(testObjects.get(TEST_OBJECT_3), true);
- expected.put(testObjects.get(TEST_OBJECT_4), true);
- expected.put(testObjects.get(TEST_OBJECT_5), true);
- expected.put(testObjects.get(TEST_OBJECT_6), true);
- expected.put(testObjects.get(TEST_OBJECT_7), true);
- expected.put(testObjects.get(TEST_OBJECT_8), true);
-
- verifyIsPermitted(webmaster, privileges.get(READ), expected);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(12)
- public void isPermittedWebmasterWrite() {
- final User webmaster = userRepository.findByScreenName("webmaster");
- final Map testObjects = retrieveTestObjects();
- final Map privileges = retrievePrivileges();
-
- final Map expected = new LinkedHashMap<>();
- expected.put(testObjects.get(TEST_OBJECT_1), true);
- expected.put(testObjects.get(TEST_OBJECT_2), true);
- expected.put(testObjects.get(TEST_OBJECT_3), true);
- expected.put(testObjects.get(TEST_OBJECT_4), true);
- expected.put(testObjects.get(TEST_OBJECT_5), true);
- expected.put(testObjects.get(TEST_OBJECT_6), true);
- expected.put(testObjects.get(TEST_OBJECT_7), true);
- expected.put(testObjects.get(TEST_OBJECT_8), true);
-
- verifyIsPermitted(webmaster, privileges.get(WRITE), expected);
- }
-
-
-
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(20)
- public void isPermittedJdoe() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final Map testObjects = retrieveTestObjects();
- final Map privileges = retrievePrivileges();
-
- final Map expectedRead = new LinkedHashMap<>();
- expectedRead.put(testObjects.get(TEST_OBJECT_1), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_2), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_3), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_4), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_5), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_6), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_7), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_8), true);
-
- final Map expectedWrite = new LinkedHashMap<>();
- expectedWrite.put(testObjects.get(TEST_OBJECT_1), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_2), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_3), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_4), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_5), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_6), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_7), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_8), true);
-
- verifyIsPermitted(jdoe, privileges.get(READ), expectedRead);
- verifyIsPermitted(jdoe, privileges.get(WRITE), expectedWrite);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(30)
- public void isPermittedMmuster() {
- final User mmuster = userRepository.findByScreenName("mmuster");
- final Map testObjects = retrieveTestObjects();
- final Map privileges = retrievePrivileges();
-
- final Map expectedRead = new LinkedHashMap<>();
- expectedRead.put(testObjects.get(TEST_OBJECT_1), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_2), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_3), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_4), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_5), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_6), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_7), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_8), true);
-
- final Map expectedWrite = new LinkedHashMap<>();
- expectedWrite.put(testObjects.get(TEST_OBJECT_1), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_2), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_3), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_4), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_5), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_6), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_7), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_8), true);
-
- verifyIsPermitted(mmuster, privileges.get(READ), expectedRead);
- verifyIsPermitted(mmuster, privileges.get(WRITE), expectedWrite);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(40)
- public void isPermittedPublicUser() {
- final User publicUser = userRepository.findByScreenName("public-user");
- final Map testObjects = retrieveTestObjects();
- final Map privileges = retrievePrivileges();
-
- final Map expectedRead = new LinkedHashMap<>();
- expectedRead.put(testObjects.get(TEST_OBJECT_1), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_2), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_3), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_4), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_5), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_6), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_7), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_8), true);
-
- final Map expectedWrite = new LinkedHashMap<>();
- expectedWrite.put(testObjects.get(TEST_OBJECT_1), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_2), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_3), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_4), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_5), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_6), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_7), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_8), false);
-
- verifyIsPermitted(publicUser, privileges.get(READ), expectedRead);
- verifyIsPermitted(publicUser, privileges.get(WRITE), expectedWrite);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(50)
- public void isPermittedUsers() {
- final Group users = groupRepository.findByGroupName("users");
- final Map testObjects = retrieveTestObjects();
- final Map privileges = retrievePrivileges();
-
- final Map expectedRead = new LinkedHashMap<>();
- expectedRead.put(testObjects.get(TEST_OBJECT_1), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_2), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_3), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_4), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_5), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_6), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_7), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_8), true);
-
- final Map expectedWrite = new LinkedHashMap<>();
- expectedWrite.put(testObjects.get(TEST_OBJECT_1), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_2), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_3), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_4), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_5), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_6), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_7), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_8), false);
-
- verifyIsPermitted(users, privileges.get(READ), expectedRead);
- verifyIsPermitted(users, privileges.get(WRITE), expectedWrite);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(60)
- public void isPermittedAuthors() {
- final Group authors = groupRepository.findByGroupName("authors");
- final Map testObjects = retrieveTestObjects();
- final Map privileges = retrievePrivileges();
-
- final Map expectedRead = new LinkedHashMap<>();
- expectedRead.put(testObjects.get(TEST_OBJECT_1), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_2), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_3), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_4), true);
- expectedRead.put(testObjects.get(TEST_OBJECT_5), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_6), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_7), false);
- expectedRead.put(testObjects.get(TEST_OBJECT_8), true);
-
- final Map expectedWrite = new LinkedHashMap<>();
- expectedWrite.put(testObjects.get(TEST_OBJECT_1), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_2), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_3), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_4), true);
- expectedWrite.put(testObjects.get(TEST_OBJECT_5), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_6), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_7), false);
- expectedWrite.put(testObjects.get(TEST_OBJECT_8), true);
-
- verifyIsPermitted(authors, privileges.get(READ), expectedRead);
- verifyIsPermitted(authors, privileges.get(WRITE), expectedWrite);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(70)
- public void isPermittedNullPrivilege() {
- final CcmObject object = ccmObjectRepository.findById(-10L);
- final User user = userRepository.findByScreenName("webmaster");
-
- permissionManager.isPermitted(null, object, user);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(80)
- public void isPermittedNullObject() {
- final Privilege privilege = privilegeRepository
- .retrievePrivilege(READ);
- final User user = userRepository.findByScreenName("webmaster");
-
- assertThat(permissionManager.isPermitted(privilege, null, user), is(true));
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(100)
- public void checkPermissionValid() throws UnauthorizedAcccessException {
- final Privilege privilege = privilegeRepository
- .retrievePrivilege(READ);
- final CcmObject object = ccmObjectRepository.findById(-10L);
- final User user = userRepository.findByScreenName("jdoe");
-
- permissionManager.checkPermission(privilege, object, user);
- }
-
- @Test(expected = UnauthorizedAcccessException.class)
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldThrowException(UnauthorizedAcccessException.class)
- @InSequence(110)
- public void checkPermissionInValid() throws UnauthorizedAcccessException {
- final Privilege privilege = privilegeRepository
- .retrievePrivilege(READ);
- final CcmObject object = ccmObjectRepository.findById(-60L);
- final User user = userRepository.findByScreenName("jdoe");
-
- permissionManager.checkPermission(privilege, object, user);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(120)
- public void checkPermissionNullPrivilege() throws
- UnauthorizedAcccessException {
- final CcmObject object = ccmObjectRepository.findById(-10L);
- final User user = userRepository.findByScreenName("webmaster");
-
- permissionManager.checkPermission(null, object, user);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(130)
- public void checkPermissionNullObject() throws UnauthorizedAcccessException {
- final Privilege privilege = privilegeRepository
- .retrievePrivilege(READ);
- final User user = userRepository.findByScreenName("webmaster");
-
- permissionManager.checkPermission(privilege, null, user);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @InSequence(140)
- public void checkPermissionNullSubject() throws UnauthorizedAcccessException {
- final Privilege privilege = privilegeRepository
- .retrievePrivilege(READ);
- final CcmObject object = ccmObjectRepository.findById(-10L);
-
- permissionManager.checkPermission(privilege, object, null);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/"
- + "PermissionManagerTest/after-grant.yml",
- excludeColumns = {"permission_id"})
- @InSequence(150)
- public void grantPermission() {
- final Privilege read = privilegeRepository.retrievePrivilege(READ);
- final Privilege write = privilegeRepository.retrievePrivilege(WRITE);
-
- final User jdoe = userRepository.findByScreenName("jdoe");
- final User mmuster = userRepository.findByScreenName("mmuster");
-
- final CcmObject object6 = ccmObjectRepository.findById(-60L);
- final CcmObject object7 = ccmObjectRepository.findById(-70L);
-
- permissionManager.grantPermission(read, object6, jdoe);
-
- permissionManager.grantPermission(read, object7, mmuster);
- permissionManager.grantPermission(write, object7, mmuster);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/"
- + "PermissionManagerTest/after-grant-wildcard.yml",
- excludeColumns = {"permission_id"})
- @InSequence(160)
- public void grantWildcardPermission() {
- final Privilege read = privilegeRepository.retrievePrivilege(READ);
- final User jdoe = userRepository.findByScreenName("jdoe");
-
- permissionManager.grantPermission(read, null, jdoe);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(170)
- public void grantPermissionNullPrivilege() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final CcmObject object6 = ccmObjectRepository.findById(-60L);
-
- permissionManager.grantPermission(null, object6, jdoe);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(180)
- public void grantPermissionNullSubject() {
- final Privilege read = privilegeRepository.retrievePrivilege(READ);
- final CcmObject object6 = ccmObjectRepository.findById(-60L);
-
- permissionManager.grantPermission(read, object6, null);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/"
- + "PermissionManagerTest/after-revoke.yml",
- excludeColumns = {"permission_id"})
- @InSequence(190)
- public void revokePermission() {
- final Privilege read = privilegeRepository.retrievePrivilege(READ);
- final Privilege write = privilegeRepository.retrievePrivilege(WRITE);
-
- final User jdoe = userRepository.findByScreenName("jdoe");
- final User mmuster = userRepository.findByScreenName("mmuster");
-
- final CcmObject object5 = ccmObjectRepository.findById(-50L);
- final CcmObject object6 = ccmObjectRepository.findById(-60L);
-
- permissionManager.revokePermission(read, object5, jdoe);
- permissionManager.revokePermission(write, object6, mmuster);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(200)
- public void revokePermissionNullPrivilege() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final CcmObject object5 = ccmObjectRepository.findById(-50L);
-
- permissionManager.revokePermission(null, object5, jdoe);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet("datasets/org/libreccm/core/PermissionManagerTest/"
- + "data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(210)
- public void revokePermissionNullSubject() {
- final Privilege read = privilegeRepository.retrievePrivilege(READ);
- final CcmObject object6 = ccmObjectRepository.findById(-60L);
-
- permissionManager.revokePermission(read, object6, null);
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/PermissionRepositoryTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/PermissionRepositoryTest.java.nolongerinuse
deleted file mode 100644
index 4c1ecc5f3..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/PermissionRepositoryTest.java.nolongerinuse
+++ /dev/null
@@ -1,447 +0,0 @@
-/*
- * Copyright (C) 2015 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 static org.hamcrest.Matchers.*;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.io.File;
-import java.util.Comparator;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Set;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.TypedQuery;
-
-import org.jboss.arquillian.container.test.api.ShouldThrowException;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.jboss.arquillian.persistence.ShouldMatchDataSet;
-
-import java.util.Collections;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class PermissionRepositoryTest {
-
- @Inject
- private transient PermissionRepository permissionRepository;
-
- @Inject
- private transient UserRepository userRepository;
-
- @Inject
- private transient GroupRepository groupRepository;
-
- @Inject
- private transient CcmObjectRepository ccmObjectRepository;
-
- @Inject
- private transient EntityManager entityManager;
-
- public PermissionRepositoryTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom.
- importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- "LibreCCM-org.libreccm.core.UserRepositoryTest.war")
- .addPackage(User.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
- addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionRepositoryTest/"
- + "data.yml")
- @InSequence(10)
- public void findPermissionsForSubject() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final User mmuster = userRepository.findByScreenName("mmuster");
- final Group admins = groupRepository.findByGroupName("admins");
- final Group users = groupRepository.findByGroupName("users");
- final Group authors = groupRepository.findByGroupName("authors");
-
- assertThat(jdoe, is(not(nullValue())));
- assertThat(mmuster, is(not(nullValue())));
- assertThat(admins, is(not(nullValue())));
- assertThat(users, is(not(nullValue())));
- assertThat(authors, is(not(nullValue())));
-
- final List permissionsJdoe = permissionRepository
- .findPermissionsForSubject(jdoe);
- assertThat(permissionsJdoe.size(), is(1));
- assertThat(permissionsJdoe.get(0).getObject().getDisplayName(),
- is(equalTo("Test Object 2")));
- assertThat(permissionsJdoe.get(0).getGrantedPrivilege().getLabel(),
- is(equalTo("read")));
-
- final List permissionsMmuster = permissionRepository
- .findPermissionsForSubject(mmuster);
- assertThat(permissionsMmuster.size(), is(0));
-
- final List permissionsAdmins = permissionRepository
- .findPermissionsForSubject(admins);
- assertThat(permissionsAdmins.size(), is(1));
- assertThat(permissionsAdmins.get(0).getObject(), is(nullValue()));
- assertThat(permissionsAdmins.get(0).getGrantedPrivilege().getLabel(),
- is("admin"));
-
- final List permissionsUsers = permissionRepository
- .findPermissionsForSubject(users);
- assertThat(permissionsUsers.size(), is(1));
- assertThat(permissionsUsers.get(0).getObject().getDisplayName(),
- is(equalTo("Test Object 1")));
- assertThat(permissionsUsers.get(0).getGrantedPrivilege().getLabel(),
- is(equalTo("read")));
-
- final List permissionsAuthors = permissionRepository
- .findPermissionsForSubject(authors);
- assertThat(permissionsAuthors.size(), is(2));
- assertThat(permissionsAuthors.get(0).getObject().getDisplayName(),
- is(equalTo("Test Object 1")));
- assertThat(permissionsAuthors.get(1).getObject().getDisplayName(),
- is(equalTo("Test Object 1")));
- final Set privileges = new HashSet<>();
- privileges.add(permissionsAuthors.get(0).getGrantedPrivilege()
- .getLabel());
- privileges.add(permissionsAuthors.get(1).getGrantedPrivilege()
- .getLabel());
- assertThat(privileges, hasItem("read"));
- assertThat(privileges, hasItem("write"));
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet(
- "datasets/org/libreccm/core/PermissionRepositoryTest/data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(11)
- public void findPermissionsForNullSubject() {
- permissionRepository.findPermissionsForSubject(null);
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/PermissionRepositoryTest/data.yml")
- @InSequence(20)
- public void findPermissionsForUser() {
- final User jdoe = userRepository.findByScreenName("jdoe");
- final User mmuster = userRepository.findByScreenName("mmuster");
- assertThat(jdoe, is(not(nullValue())));
- assertThat(mmuster, is(not(nullValue())));
-
- final List jdoePermissions = permissionRepository
- .findPermissionsForUser(jdoe);
- assertThat(jdoePermissions.size(), is(4));
- Collections.sort(jdoePermissions, new Comparator() {
-
- @Override
- public int compare(final Permission permission1,
- final Permission permission2) {
- int result = permission1.getGrantedPrivilege().getLabel()
- .compareToIgnoreCase(permission2.getGrantedPrivilege()
- .getLabel());
-
- if (result == 0) {
- result = permission1.getObject().getDisplayName().compareTo(
- permission2.getObject().getDisplayName());
- } else {
- return result;
- }
-
- if (result == 0) {
- return permission1.getGrantee().getClass().getName()
- .compareTo(permission2.getGrantee().getClass().
- getName());
- } else {
- return result;
- }
-
- }
-
- });
-
- assertThat(jdoePermissions.get(0).getGrantedPrivilege().getLabel(),
- is(equalTo("read")));
- assertThat(jdoePermissions.get(0).getObject().getDisplayName(),
- is(equalTo("Test Object 1")));
- assertThat(jdoePermissions.get(1).getGrantedPrivilege().getLabel(),
- is(equalTo("read")));
- assertThat(jdoePermissions.get(1).getObject().getDisplayName(),
- is(equalTo("Test Object 1")));
- assertThat(jdoePermissions.get(2).getGrantedPrivilege().getLabel(),
- is(equalTo("read")));
- assertThat(jdoePermissions.get(2).getObject().getDisplayName(),
- is(equalTo("Test Object 2")));
- assertThat(jdoePermissions.get(3).getGrantedPrivilege().getLabel(),
- is(equalTo("write")));
- assertThat(jdoePermissions.get(3).getObject().getDisplayName(),
- is(equalTo("Test Object 1")));
-
- final List mmusterPermissions = permissionRepository
- .findPermissionsForUser(mmuster);
- assertThat(mmusterPermissions.size(), is(1));
- assertThat(mmusterPermissions.get(0).getGrantedPrivilege()
- .getLabel(),
- is(equalTo("admin")));
- assertThat(mmusterPermissions.get(0).getObject(), is(nullValue()));
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet(
- "datasets/org/libreccm/core/PermissionRepositoryTest/data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(21)
- public void findPermissionsForNullUser() {
- permissionRepository.findPermissionsForUser(null);
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/PermissionRepositoryTest/data.yml")
- @InSequence(30)
- public void findPermissionsForCcmObject() {
- final CcmObject object1 = ccmObjectRepository.findById(-10L);
- final CcmObject object2 = ccmObjectRepository.findById(-20L);
- final CcmObject object3 = ccmObjectRepository.findById(-30L);
-
- final List object1Permissions = permissionRepository
- .findPermissionsForCcmObject(object1);
- assertThat(object1Permissions.size(), is(3));
- Collections.sort(object1Permissions, new Comparator() {
-
- @Override
- public int compare(final Permission permission1,
- final Permission permission2) {
- return Long.compare(permission1.getPermissionId(),
- permission2.getPermissionId());
- }
-
- });
- assertThat(object1Permissions.get(0).getGrantedPrivilege()
- .getLabel(),
- is(equalTo("read")));
- assertThat(object1Permissions.get(0).getGrantee(),
- is(instanceOf(Group.class)));
- assertThat(((Group) object1Permissions.get(0).getGrantee()).getName(),
- is(equalTo("authors")));
- assertThat(object1Permissions.get(1).getGrantedPrivilege()
- .getLabel(),
- is(equalTo("write")));
- assertThat(object1Permissions.get(1).getGrantee(),
- is(instanceOf(Group.class)));
- assertThat(((Group) object1Permissions.get(1).getGrantee()).getName(),
- is(equalTo("authors")));
- assertThat(object1Permissions.get(2).getGrantedPrivilege()
- .getLabel(),
- is(equalTo("read")));
- assertThat(object1Permissions.get(2).getGrantee(),
- is(instanceOf(Group.class)));
- assertThat(((Group) object1Permissions.get(2).getGrantee()).getName(),
- is(equalTo("users")));
-
- final List object2Permissions = permissionRepository
- .findPermissionsForCcmObject(object2);
- assertThat(object2Permissions.size(), is(1));
- assertThat(object2Permissions.get(0).getGrantedPrivilege()
- .getLabel(),
- is(equalTo("read")));
- assertThat(object2Permissions.get(0).getGrantee(),
- is(instanceOf(User.class)));
- assertThat(((User) object2Permissions.get(0).getGrantee())
- .getScreenName(),
- is(equalTo("jdoe")));
-
- final List object3Permissions = permissionRepository
- .findPermissionsForCcmObject(object3);
- assertThat(object3Permissions, is(empty()));
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet(
- "datasets/org/libreccm/core/PermissionRepositoryTest/data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(31)
- public void findPermissionsForNullObject() {
- permissionRepository.findPermissionsForCcmObject(null);
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/PermissionRepositoryTest/data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/"
- + "PermissionRepositoryTest/after-save-new.yml",
- excludeColumns = {"permission_id"})
- @InSequence(40)
- public void saveNewPermission() {
- final User mmuster = userRepository.findByScreenName("mmuster");
-
- final TypedQuery query1 = entityManager.createQuery(
- "SELECT p FROM Privilege p WHERE p.label = 'read'",
- Privilege.class);
- final TypedQuery query2 = entityManager.createQuery(
- "SELECT p FROM Privilege p WHERE p.label = 'write'",
- Privilege.class);
-
- final CcmObject object = ccmObjectRepository.findById(-40L);
-
- final Privilege read = query1.getSingleResult();
- final Privilege write = query2.getSingleResult();
-
- assertThat(mmuster, is(not(nullValue())));
- assertThat(read, is(not(nullValue())));
- assertThat(write, is(not(nullValue())));
- assertThat(object, is(not(nullValue())));
-
- final Permission permission1 = new Permission();
- permission1.setGrantee(mmuster);
- permission1.setGrantedPrivilege(read);
- permission1.setObject(object);
-
- final Permission permission2 = new Permission();
- permission2.setGrantee(mmuster);
- permission2.setGrantedPrivilege(write);
- permission2.setObject(object);
-
- permissionRepository.save(permission1);
- permissionRepository.save(permission2);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(41)
- public void saveNullPermission() {
- permissionRepository.save(null);
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/PermissionRepositoryTest/data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/"
- + "PermissionRepositoryTest/after-save-changed.yml",
- excludeColumns = {"permission_id"})
- @InSequence(50)
- public void saveChangedPermission() {
- final Permission permission = entityManager.find(Permission.class, -40L);
- final Group users = groupRepository.findByGroupName("users");
-
- assertThat(permission, is(not(nullValue())));
- assertThat(users, is(not(nullValue())));
-
- permission.setGrantee(users);
-
- permissionRepository.save(permission);
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/PermissionRepositoryTest/data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/"
- + "PermissionRepositoryTest/after-delete.yml",
- excludeColumns = {"permission_id"})
- @InSequence(60)
- public void deletePermission() {
- final Permission permission = entityManager.find(Permission.class, -35L);
-
- permissionRepository.delete(permission);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(61)
- public void deleteNullPermission() {
- permissionRepository.delete(null);
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/PrivilegeRepositoryTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/PrivilegeRepositoryTest.java.nolongerinuse
deleted file mode 100644
index 5455a834b..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/PrivilegeRepositoryTest.java.nolongerinuse
+++ /dev/null
@@ -1,201 +0,0 @@
-/*
- * Copyright (C) 2015 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 static org.hamcrest.Matchers.*;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.ShouldThrowException;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.ShouldMatchDataSet;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.io.File;
-
-import javax.inject.Inject;
-
-import static org.junit.Assert.*;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class PrivilegeRepositoryTest {
-
- @Inject
- private transient PrivilegeRepository privilegeRepository;
-
- public PrivilegeRepositoryTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom.
- importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- "LibreCCM-org.libreccm.core.UserRepositoryTest.war")
- .addPackage(User.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
- addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PrivilegeRepositoryTest/"
- + "data.yml")
- @InSequence(10)
- public void retrievePrivilege() {
- final Privilege admin = privilegeRepository.retrievePrivilege("admin");
- final Privilege read = privilegeRepository.retrievePrivilege("read");
- final Privilege write = privilegeRepository.retrievePrivilege("write");
-
- assertThat(admin, is(not(nullValue())));
- assertThat(read, is(not(nullValue())));
- assertThat(write, is(not(nullValue())));
-
- assertThat(admin.getLabel(), is(equalTo("admin")));
- assertThat(read.getLabel(), is(equalTo("read")));
- assertThat(write.getLabel(), is(equalTo("write")));
- }
-
- @Test(expected = UnknownPrivilegeException.class)
- @UsingDataSet("datasets/org/libreccm/core/PrivilegeRepositoryTest/"
- + "data.yml")
- @ShouldThrowException(UnknownPrivilegeException.class)
- @InSequence(20)
- public void retrieveNotExitingPrivilege() {
- privilegeRepository.retrievePrivilege("publish");
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PrivilegeRepositoryTest/"
- + "data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/"
- + "PrivilegeRepositoryTest/after-create.yml",
- excludeColumns = {"privilege_id"})
- @InSequence(30)
- public void createNewPrivilege() {
- privilegeRepository.createPrivilege("publish");
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PrivilegeRepositoryTest/"
- + "data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/"
- + "PrivilegeRepositoryTest/after-delete.yml",
- excludeColumns = {"privilege_id"})
- @InSequence(40)
- public void deletePrivilege() {
- privilegeRepository.deletePrivilege("write");
- }
-
- @Test(expected = UnknownPrivilegeException.class)
- @UsingDataSet("datasets/org/libreccm/core/PrivilegeRepositoryTest/"
- + "data.yml")
- @ShouldThrowException(UnknownPrivilegeException.class)
- @InSequence(41)
- public void deleteNullPrivilege() {
- privilegeRepository.deletePrivilege(null);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/PermissionRepositoryTest/"
- + "data.yml")
- @InSequence(50)
- public void checkIsPermissionInUse() {
- assertThat(privilegeRepository.isPrivilegeInUse("admin"), is(true));
- assertThat(privilegeRepository.isPrivilegeInUse("write"), is(true));
- assertThat(privilegeRepository.isPrivilegeInUse("read"), is(true));
- assertThat(privilegeRepository.isPrivilegeInUse("used"), is(false));
- }
-
- @Test(expected = IllegalArgumentException.class)
- @UsingDataSet("datasets/org/libreccm/core/PermissionRepositoryTest/"
- + "data.yml")
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(60)
- public void deleteInUsePrivilege() {
- privilegeRepository.deletePrivilege("admin");
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/RoleRepositoryTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/RoleRepositoryTest.java.nolongerinuse
deleted file mode 100644
index 1146d06e9..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/RoleRepositoryTest.java.nolongerinuse
+++ /dev/null
@@ -1,368 +0,0 @@
-/*
- * Copyright (C) 2015 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 static org.hamcrest.Matchers.*;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.ShouldThrowException;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.ShouldMatchDataSet;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.io.File;
-import java.util.List;
-
-import javax.inject.Inject;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class RoleRepositoryTest {
-
- @Inject
- private transient RoleRepository roleRepository;
-
- @Inject
- private transient GroupRepository groupRepository;
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom.
- importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- "LibreCCM-org.libreccm.core.RoleRepositoryTest.war")
- .addPackage(User.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
- addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
- }
-
- private void verifyAuthor(final Role author) {
- assertThat(author, is(not(nullValue())));
- assertThat(author.getName(), is(equalTo("Author")));
- assertThat(author.getDescription(),
- is(equalTo("Creates new content")));
- assertThat(author.getImplicitGroup().getName(),
- is(equalTo("info Administration Author")));
- assertThat(author.getSourceGroup().getName(),
- is(equalTo("info Administration")));
- }
-
- private void verifyEditor(final Role editor) {
- assertThat(editor, is(not(nullValue())));
- assertThat(editor.getName(), is(equalTo("Editor")));
- assertThat(editor.getDescription(),
- is(equalTo("Reviews and approves the author's work")));
- assertThat(editor.getImplicitGroup().getName(),
- is(equalTo("info Administration Editor")));
- assertThat(editor.getSourceGroup().getName(),
- is(equalTo("info Administration")));
- }
-
- private void verifyPublisher(final Role publisher) {
- assertThat(publisher, is(not(nullValue())));
- assertThat(publisher.getName(), is(equalTo("Publisher")));
- assertThat(publisher.getDescription(),
- is(equalTo("Deploys the content to the web site")));
- assertThat(publisher.getImplicitGroup().getName(),
- is(equalTo("info Administration Publisher")));
- assertThat(publisher.getSourceGroup().getName(),
- is(equalTo("info Administration")));
- }
-
- private void verifyManager(final Role manager) {
- assertThat(manager, is(not(nullValue())));
- assertThat(manager.getName(), is(equalTo("Manager")));
- assertThat(manager.getDescription(),
- is(equalTo("Manages the overall content section")));
- assertThat(manager.getImplicitGroup().getName(),
- is(equalTo("info Administration Manager")));
- assertThat(manager.getSourceGroup().getName(),
- is(equalTo("info Administration")));
- }
-
- private void verifyTrustedUser(final Role trustedUser) {
- assertThat(trustedUser, is(not(nullValue())));
- assertThat(trustedUser.getName(), is(equalTo("Trusted User")));
- assertThat(trustedUser.getDescription(),
- is(equalTo("A trusted user is allowed to create and publish "
- + "items without review")));
- assertThat(trustedUser.getImplicitGroup().getName(),
- is(equalTo("info Administration Trusted User")));
- assertThat(trustedUser.getSourceGroup().getName(),
- is(equalTo("info Administration")));
- }
-
- private void verifyContentReader(final Role contentReader) {
- assertThat(contentReader, is(not(nullValue())));
- assertThat(contentReader.getName(), is(equalTo("Content Reader")));
- assertThat(contentReader.getDescription(),
- is(equalTo("Can view published pages within this section")));
- assertThat(contentReader.getImplicitGroup().getName(),
- is(equalTo("info Viewers Content Reader")));
- assertThat(contentReader.getSourceGroup().getName(),
- is(equalTo("info Viewers")));
- }
-
- private void verifyAlertRecipient(final Role alertRecipient) {
- assertThat(alertRecipient, is(not(nullValue())));
- assertThat(alertRecipient.getName(), is(equalTo("Alert Recipient")));
- assertThat(alertRecipient.getDescription(),
- is(equalTo("Receive alerts regarding expiration of "
- + "published content")));
- assertThat(alertRecipient.getImplicitGroup().getName(),
- is(equalTo("info Administration Alert Recipient")));
- assertThat(alertRecipient.getSourceGroup().getName(),
- is(equalTo("info Viewers")));
- }
-
- @Test
- @InSequence(10)
- @UsingDataSet("datasets/org/libreccm/core/RoleRepositoryTest/data.yml")
- public void findRoleById() {
- final Role author = roleRepository.findById(-10L);
- final Role editor = roleRepository.findById(-20L);
- final Role publisher = roleRepository.findById(-30L);
- final Role manager = roleRepository.findById(-40L);
- final Role trustedUser = roleRepository.findById(-50L);
- final Role contentReader = roleRepository.findById(-60L);
- final Role alertRecipient = roleRepository.findById(-70L);
-
- verifyAuthor(author);
- verifyEditor(editor);
- verifyPublisher(publisher);
- verifyManager(manager);
- verifyTrustedUser(trustedUser);
- verifyContentReader(contentReader);
- verifyAlertRecipient(alertRecipient);
- }
-
- @Test
- @InSequence(20)
- @UsingDataSet("datasets/org/libreccm/core/RoleRepositoryTest/data.yml")
- public void findRoleByName() {
- final List authors = roleRepository.findRolesForName("Author");
- final List editors = roleRepository.findRolesForName("Editor");
- final List publishers = roleRepository.findRolesForName(
- "Publisher");
- final List managers = roleRepository.findRolesForName("Manager");
- final List trustedUsers = roleRepository.findRolesForName(
- "Trusted User");
- final List contentReaders = roleRepository.findRolesForName(
- "Content Reader");
- final List alertRecipients = roleRepository.findRolesForName(
- "Alert Recipient");
-
- assertThat(authors.size(), is(1));
- assertThat(editors.size(), is(1));
- assertThat(publishers.size(), is(1));
- assertThat(managers.size(), is(1));
- assertThat(trustedUsers.size(), is(1));
- assertThat(contentReaders.size(), is(1));
- assertThat(alertRecipients.size(), is(1));
-
- final Role author = authors.get(0);
- final Role editor = editors.get(0);
- final Role publisher = publishers.get(0);
- final Role manager = managers.get(0);
- final Role trustedUser = trustedUsers.get(0);
- final Role contentReader = contentReaders.get(0);
- final Role alertRecipient = alertRecipients.get(0);
-
- verifyAuthor(author);
- verifyEditor(editor);
- verifyPublisher(publisher);
- verifyManager(manager);
- verifyTrustedUser(trustedUser);
- verifyContentReader(contentReader);
- verifyAlertRecipient(alertRecipient);
- }
-
- @Test
- @InSequence(30)
- @UsingDataSet("datasets/org/libreccm/core/RoleRepositoryTest/data.yml")
- public void findRolesForSourceGroup() {
- final Group group = groupRepository.findByGroupName(
- "info Administration");
-
- assertThat(group, is(not(nullValue())));
-
- final List roles = roleRepository.findRolesForSourceGroup(group);
-
- assertThat(roles.size(), is(5));
-
- verifyAuthor(roles.get(0));
- verifyEditor(roles.get(1));
- verifyManager(roles.get(2));
- verifyPublisher(roles.get(3));
- verifyTrustedUser(roles.get(4));
- }
-
- @Test
- @InSequence(40)
- @UsingDataSet("datasets/org/libreccm/core/RoleRepositoryTest/data.yml")
- public void findRolesForImplicitGroup() {
- final Group authorsGroup = groupRepository.findByGroupName(
- "info Administration Author");
- assertThat(authorsGroup, is(not(nullValue())));
- final List authors = roleRepository.findRolesForImplicitGroup(
- authorsGroup);
- assertThat(authors.size(), is(1));
- verifyAuthor(authors.get(0));
-
- final Group editorsGroup = groupRepository.findByGroupName(
- "info Administration Editor");
- assertThat(editorsGroup, is(not(nullValue())));
- final List editors = roleRepository.findRolesForImplicitGroup(
- editorsGroup);
- assertThat(editors.size(), is(1));
- verifyEditor(editors.get(0));
-
- final Group publisherGroup = groupRepository.findByGroupName(
- "info Administration Publisher");
- assertThat(publisherGroup, is(not(nullValue())));
- final List publishers = roleRepository.findRolesForImplicitGroup(
- publisherGroup);
- assertThat(publishers.size(), is(1));
- verifyPublisher(publishers.get(0));
- }
-
- @Test
- @InSequence(50)
- @UsingDataSet("datasets/org/libreccm/core/RoleRepositoryTest/data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/RoleRepositoryTest/"
- + "after-save-new.yml",
- excludeColumns = {"role_id"})
- public void saveNewRole() {
- final Group infoAdmin = groupRepository.findByGroupName(
- "info Administration");
- final Group readers = groupRepository.findByGroupName(
- "info Viewers Content Reader");
-
- final Role role = new Role();
- role.setName("Test");
- role.setDescription("New role for testing");
- role.setImplicitGroup(infoAdmin);
- role.setSourceGroup(readers);
-
- roleRepository.save(role);
- }
-
- @Test
- @InSequence(60)
- @UsingDataSet("datasets/org/libreccm/core/RoleRepositoryTest/data.yml")
- @ShouldMatchDataSet(value = "datasets/org/libreccm/core/RoleRepositoryTest/"
- + "after-save-changed.yml",
- excludeColumns = {"role_id"})
- public void saveChangedRole() {
- final Role role = roleRepository.findById(-60L);
- role.setName("Reader");
-
- roleRepository.save(role);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(70)
- @UsingDataSet("datasets/org/libreccm/core/RoleRepositoryTest/data.yml")
- public void saveNullValue() {
- roleRepository.save(null);
- }
-
- @Test
- @InSequence(80)
- @UsingDataSet("datasets/org/libreccm/core/RoleRepositoryTest/data.yml")
- @ShouldMatchDataSet("datasets/org/libreccm/core/RoleRepositoryTest/"
- + "after-delete.yml")
- public void deleteRole() {
- final Role role = roleRepository.findById(-50L);
-
- roleRepository.delete(role);
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/UserManagerTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/UserManagerTest.java.nolongerinuse
deleted file mode 100644
index ea727b836..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/UserManagerTest.java.nolongerinuse
+++ /dev/null
@@ -1,290 +0,0 @@
-/*
- * Copyright (C) 2015 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 static org.hamcrest.Matchers.*;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-
-
-import org.apache.commons.codec.binary.Base64;
-import org.jboss.arquillian.container.test.api.ShouldThrowException;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.io.File;
-import java.io.UnsupportedEncodingException;
-import java.nio.charset.StandardCharsets;
-import java.security.MessageDigest;
-import java.security.NoSuchAlgorithmException;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-import static org.junit.Assert.*;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class UserManagerTest {
-
- @Inject
- private transient UserRepository userRepository;
-
- @Inject
- private transient UserManager userManager;
-
- @PersistenceContext
- private transient EntityManager entityManager;
-
- public UserManagerTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom.
- importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- "LibreCCM-org.libreccm.core.UserManagerTest.war")
- .addPackage(User.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
- addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
-
- }
-
- @Test
- @InSequence(10)
- public void userRepoIsInjected() {
- assertThat(userRepository, is(not(nullValue())));
- }
-
- @Test
- @InSequence(20)
- public void userManagerIsInjected() {
- assertThat(userManager, is(not(nullValue())));
- }
-
- @Test
- @InSequence(30)
- public void entityManagerIsInjected() {
- assertThat(entityManager, is(not(nullValue())));
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/UserRepositoryTest/data.yml")
- @InSequence(100)
- public void updatePassword() throws NoSuchAlgorithmException,
- UnsupportedEncodingException {
-
- final User jdoe = userRepository.findById(-10L);
-
- assertThat(jdoe, is(not(nullValue())));
- assertThat(jdoe.getScreenName(), is("jdoe"));
-
- final String newPassword = "foobar";
-
- userManager.updatePassword(jdoe, newPassword);
-
- final Base64 base64 = new Base64();
- final User user = entityManager.find(User.class, -10L);
- final byte[] passwordBytes = newPassword.getBytes(
- StandardCharsets.UTF_8);
- final String salt = user.getSalt();
- final byte[] saltBytes = base64.decode(salt);
-
- assertThat(saltBytes.length, is(userManager.getSaltLength()));
-
- final MessageDigest digest = MessageDigest.getInstance(userManager
- .getHashAlgorithm());
-
- final byte[] saltedPassword = new byte[passwordBytes.length
- + saltBytes.length];
- System.arraycopy(passwordBytes,
- 0,
- saltedPassword,
- 0,
- passwordBytes.length);
- System.arraycopy(saltBytes,
- 0,
- saltedPassword,
- passwordBytes.length,
- saltBytes.length);
- final byte[] hashedBytes = digest.digest(saltedPassword);
-
- final String hashed = base64.encodeToString(hashedBytes);
- assertThat(user.getPassword(), is(equalTo(hashed)));
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/UserManagerTest/verify-password.yml")
- @InSequence(200)
- public void verifyPasswordForUser() {
- final User user = userRepository.findById(-10L);
-
- //userManager.updatePassword(user, "foobar");
- final boolean result = userManager.verifyPasswordForUser(user, "foobar");
-
- assertThat(result, is(true));
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/UserManagerTest/verify-password.yml")
- @InSequence(300)
- public void verifyPasswordForScreenname() throws UserNotFoundException {
- final boolean result = userManager.verifyPasswordForScreenname(
- "jdoe", "foobar");
-
- assertThat(result, is(true));
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/UserManagerTest/verify-password.yml")
- @InSequence(400)
- public void verifyPasswordForEmail() throws UserNotFoundException {
- final boolean result = userManager.verifyPasswordForEmail(
- "john.doe@example.com", "foobar");
-
- assertThat(result, is(true));
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/UserManagerTest/verify-password.yml")
- @InSequence(500)
- public void verifyPasswordForUserWrongPassword() {
- final User user = userRepository.findById(-10L);
-
- final boolean result = userManager.verifyPasswordForUser(user, "wrong");
-
- assertThat(result, is(false));
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/UserManagerTest/verify-password.yml")
- @InSequence(600)
- public void verifyPasswordForScreennameWrongPassword() throws
- UserNotFoundException {
- final boolean result = userManager.verifyPasswordForScreenname(
- "jdoe", "wrong");
-
- assertThat(result, is(false));
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/UserManagerTest/verify-password.yml")
- @InSequence(400)
- public void verifyPasswordForEmailWrongPassword() throws
- UserNotFoundException {
- final boolean result = userManager.verifyPasswordForEmail(
- "john.doe@example.com", "wrong");
-
- assertThat(result, is(false));
- }
-
- @Test(expected = UserNotFoundException.class)
- @ShouldThrowException(UserNotFoundException.class)
- @UsingDataSet(
- "datasets/org/libreccm/core/UserManagerTest/verify-password.yml")
- @InSequence(700)
- public void verifyPasswordForScreennameNoUser() throws UserNotFoundException {
- userManager.verifyPasswordForScreenname("nobody", "foobar");
- }
-
- @Test(expected = UserNotFoundException.class)
- @ShouldThrowException(UserNotFoundException.class)
- @UsingDataSet(
- "datasets/org/libreccm/core/UserManagerTest/verify-password.yml")
- @InSequence(800)
- public void verifyPasswordForEmailNoUser() throws UserNotFoundException {
- userManager.verifyPasswordForEmail("nobody@example.com", "foobar");
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/UserRepositoryTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/UserRepositoryTest.java.nolongerinuse
deleted file mode 100644
index 011b8d8c2..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/UserRepositoryTest.java.nolongerinuse
+++ /dev/null
@@ -1,337 +0,0 @@
-/*
- * Copyright (C) 2015 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 java.io.File;
-
-import javax.inject.Inject;
-import javax.persistence.EntityManager;
-import javax.persistence.PersistenceContext;
-
-import org.junit.Test;
-
-import static org.hamcrest.Matchers.*;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.container.test.api.ShouldThrowException;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.ShouldMatchDataSet;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.util.List;
-
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class UserRepositoryTest {
-
- private static final String NOBODY = "nobody";
- private static final String JOE = "joe";
- private static final String MMUSTER = "mmuster";
- private static final String JDOE = "jdoe";
-
- @Inject
- private transient UserRepository userRepository;
-
- @PersistenceContext
- private transient EntityManager entityManager;
-
- public UserRepositoryTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom.
- importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- "LibreCCM-org.libreccm.core.UserRepositoryTest.war")
- .addPackage(User.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage()).
- addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
- }
-
- @Test
- public void repoIsInjected() {
- assertThat(userRepository, is(not(nullValue())));
- }
-
- @Test
- public void entityManagerIsInjected() {
- assertThat(entityManager, is(not(nullValue())));
- }
-
- private void checkUsers(final User jdoe,
- final User mmuster,
- final User joe,
- final User nobody) {
- assertThat(jdoe, is(not(nullValue())));
- assertThat(jdoe.getSubjectId(), is(-10L));
- assertThat(jdoe.getScreenName(), is(JDOE));
- assertThat(jdoe.getName().getFamilyName(), is(equalTo("Doe")));
- assertThat(jdoe.getName().getMiddleName(), is(nullValue()));
- assertThat(jdoe.getName().getGivenName(), is(equalTo("John")));
- assertThat(jdoe.getHashAlgorithm(), is("MD5"));
- assertThat(jdoe.getPassword(), is("604622dc8a888eb093454ebd77ca1675"));
- assertThat(jdoe.getSalt(), is("axg8ira8fa"));
-
- assertThat(mmuster, is(not(nullValue())));
- assertThat(mmuster.getSubjectId(), is(-20L));
- assertThat(mmuster.getScreenName(), is(equalTo(MMUSTER)));
- assertThat(mmuster.getName().getFamilyName(), is(equalTo("Mustermann")));
- assertThat(mmuster.getName().getMiddleName(), is(nullValue()));
- assertThat(mmuster.getName().getGivenName(), is(equalTo("Max")));
- assertThat(mmuster.getHashAlgorithm(), is(equalTo("SHA-512")));
- assertThat(mmuster.getPassword(), is(equalTo(
- "1c9626af429a6291766d15cbfb38689bd8d49450520765973de70aecaf644b7d4fda711266ba9ec8fb6df30c8ab391d40330829aa85adf371bcde6b4c9bc01e6")));
- assertThat(mmuster.getSalt(), is(equalTo("fjiajhigafgapoa")));
-
- assertThat(joe, is(not(nullValue())));
- assertThat(joe.getSubjectId(), is(-30L));
- assertThat(joe.getScreenName(), is(equalTo(JOE)));
- assertThat(joe.getName().getFamilyName(), is(equalTo("Public")));
- assertThat(joe.getName().getMiddleName(), is(nullValue()));
- assertThat(joe.getName().getGivenName(), is(equalTo("Joe")));
- assertThat(joe.getHashAlgorithm(), is(equalTo("SHA-512")));
- assertThat(joe.getPassword(), is(equalTo(
- "4e39eba7f2927182a532cd8700bf251e58d4b0359fbb832e6af21db7501d7a49e6d8b950e0d4b15b1841af0f786c8edaa0c09ef7f474804254f7e895969d2975")));
- assertThat(joe.getSalt(), is(equalTo("axg8ira8fa")));
-
- assertThat(nobody, is(nullValue()));
-
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/UserRepositoryTest/data.yml")
- @InSequence(100)
- public void findUserById() {
- final User jdoe = userRepository.findById(-10L);
- final User mmuster = userRepository.findById(-20L);
- final User joe = userRepository.findById(-30L);
- final User nobody = userRepository.findById(-999L);
-
- checkUsers(jdoe, mmuster, joe, nobody);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/UserRepositoryTest/data.yml")
- @InSequence(200)
- public void findUserByScreenName() {
- final User jdoe = userRepository.findByScreenName(JDOE);
- final User mmuster = userRepository.findByScreenName(MMUSTER);
- final User joe = userRepository.findByScreenName(JOE);
- final User nobody = userRepository.findByScreenName(NOBODY);
-
- checkUsers(jdoe, mmuster, joe, nobody);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/UserRepositoryTest/data.yml")
- @InSequence(300)
- public void findUserByEmail() {
- final User jdoe = userRepository.findByEmailAddress(
- "john.doe@example.com");
- final User mmuster1 = userRepository.findByEmailAddress(
- "max.mustermann@example.org");
- final User mmuster2 = userRepository
- .findByEmailAddress("mm@example.com");
- final User joe = userRepository.findByEmailAddress(
- "joe.public@example.com");
- final User nobody = userRepository
- .findByEmailAddress("nobody@example.org");
-
- checkUsers(jdoe, mmuster1, joe, nobody);
-
- assertThat(mmuster2, is(equalTo(mmuster1)));
- }
-
- @Test(expected = MultipleMatchingUserException.class)
- @ShouldThrowException(MultipleMatchingUserException.class)
- @UsingDataSet(
- "datasets/org/libreccm/core/UserRepositoryTest/data-email-duplicate.yml")
- @InSequence(350)
- public void findByEmailAddressDuplicate() {
- userRepository.findByEmailAddress("max.mustermann@example.org");
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/UserRepositoryTest/data.yml")
- @InSequence(400)
- public void findAllUsers() {
- final List users = userRepository.findAll();
-
- assertThat(users.size(), is(3));
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/UserRepositoryTest/data.yml")
- @ShouldMatchDataSet(value
- = "datasets/org/libreccm/core/UserRepositoryTest/after-save-new.yml",
- excludeColumns = {"subject_id", "user_id"})
- @InSequence(500)
- public void saveNewUser() {
- final User user = new User();
-
- final PersonName personName = new PersonName();
- personName.setGivenName("Jane");
- personName.setMiddleName("Anna");
- personName.setFamilyName("Doe");
- personName.setTitlePre("Dr.");
- user.setName(personName);
-
- final EmailAddress emailAddress = new EmailAddress();
- emailAddress.setAddress("jane.doe@example.org");
- emailAddress.setBouncing(false);
- emailAddress.setVerified(false);
- user.addEmailAddress(emailAddress);
-
- user.setScreenName("jane");
- user.setPassword(
- "32d2a830fb03f201bda975ae70a62c207716705a049e054cf6701de1cec546d3a9e03a094be2e98e4d125af996ebbfa5a7754754a1e9d2fe063a0d9921cb201d");
- user.setHashAlgorithm("SHA-512");
- user.setSalt("maifgaoapafga9");
- user.setPasswordResetRequired(false);
-
- userRepository.save(user);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/UserRepositoryTest/data.yml")
- @ShouldMatchDataSet(value
- = "datasets/org/libreccm/core/UserRepositoryTest/after-save-changed.yml",
- excludeColumns = {"subject_id"})
- @InSequence(600)
- public void saveChangedUser() {
- final User user = userRepository.findById(-10L);
-
- user.getName().setTitlePre("Dr.");
-
- user.setHashAlgorithm("SHA-512");
- user.setPassword(
- "19f69a0f8eab3e6124d1b40ca2ae1fc3ece311cf86dde4e9560521e881fb8f063817cf1da1234144825f40fc9b9acd1563cafcb35fb8533544a1b6c3615160e3");
- user.setSalt("fafjiaddfja0a");
-
- final EmailAddress emailAddress = new EmailAddress();
- emailAddress.setAddress("jd@example.com");
- emailAddress.setBouncing(false);
- emailAddress.setVerified(true);
- user.addEmailAddress(emailAddress);
-
- final EmailAddress old = user.getEmailAddresses().get(0);
- user.removeEmailAddress(old);
-
- userRepository.save(user);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(700)
- public void saveNullValue() {
- userRepository.save(null);
- }
-
- @Test
- @UsingDataSet("datasets/org/libreccm/core/UserRepositoryTest/data.yml")
- @ShouldMatchDataSet(value
- = "datasets/org/libreccm/core/UserRepositoryTest/after-delete.yml",
- excludeColumns = {"subject_id"})
- @InSequence(800)
- public void deleteUser() {
- final User user = userRepository.findByScreenName("mmuster");
-
- userRepository.delete(user);
- }
-
- @Test(expected = IllegalArgumentException.class)
- @ShouldThrowException(IllegalArgumentException.class)
- @InSequence(900)
- public void deleteNullValue() {
- userRepository.delete(null);
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/authentication/EqualsAndHashCodeTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/authentication/EqualsAndHashCodeTest.java.nolongerinuse
deleted file mode 100644
index 9adf57106..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/authentication/EqualsAndHashCodeTest.java.nolongerinuse
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2015 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.authentication;
-
-import java.util.Arrays;
-import java.util.Collection;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
-import org.libreccm.tests.categories.UnitTest;
-import org.libreccm.testutils.EqualsVerifier;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@RunWith(Parameterized.class)
-@Category(UnitTest.class)
-public class EqualsAndHashCodeTest extends EqualsVerifier {
-
- @Parameterized.Parameters(name = "{0}")
- public static Collection> data() {
- return Arrays.asList(new Class>[] {
- UserPrincipal.class
- });
- }
-
- public EqualsAndHashCodeTest(final Class> entityClass) {
- super(entityClass);
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/authentication/LoginManagerTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/authentication/LoginManagerTest.java.nolongerinuse
deleted file mode 100644
index 7213bd70e..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/authentication/LoginManagerTest.java.nolongerinuse
+++ /dev/null
@@ -1,270 +0,0 @@
-/*
- * Copyright (C) 2015 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.authentication;
-
-import static org.hamcrest.Matchers.*;
-
-import org.jboss.arquillian.container.test.api.Deployment;
-import org.jboss.arquillian.junit.Arquillian;
-import org.jboss.arquillian.junit.InSequence;
-import org.jboss.arquillian.persistence.CreateSchema;
-import org.jboss.arquillian.persistence.PersistenceTest;
-import org.jboss.arquillian.persistence.UsingDataSet;
-import org.jboss.arquillian.transaction.api.annotation.TransactionMode;
-import org.jboss.arquillian.transaction.api.annotation.Transactional;
-import org.jboss.shrinkwrap.api.ShrinkWrap;
-import org.jboss.shrinkwrap.api.asset.EmptyAsset;
-import org.jboss.shrinkwrap.api.spec.WebArchive;
-import org.jboss.shrinkwrap.resolver.api.maven.Maven;
-import org.jboss.shrinkwrap.resolver.api.maven.PomEquippedResolveStage;
-import org.junit.After;
-import org.junit.AfterClass;
-
-import static org.junit.Assert.*;
-
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.experimental.categories.Category;
-import org.junit.runner.RunWith;
-import org.libreccm.core.CcmObject;
-import org.libreccm.core.CcmSessionContext;
-import org.libreccm.core.EmailAddress;
-import org.libreccm.core.Subject;
-import org.libreccm.core.User;
-import org.libreccm.tests.categories.IntegrationTest;
-
-import java.io.File;
-
-import javax.inject.Inject;
-import javax.security.auth.login.Configuration;
-import javax.security.auth.login.LoginException;
-
-/**
- *
- * @author Jens Pelzetter
- */
-@Category(IntegrationTest.class)
-@RunWith(Arquillian.class)
-@PersistenceTest
-@Transactional(TransactionMode.COMMIT)
-@CreateSchema({"create_ccm_core_schema.sql"})
-public class LoginManagerTest {
-
- @Inject
- private transient LoginManager loginManager;
-
- @Inject
- private transient CcmSessionContext ccmSessionContext;
-
- public LoginManagerTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- final String[] config = new String[]{
- String.format("Register:%s:requisite",
- LocalLoginModule.class.getName())};
- final LoginConfigBuilder loginConfigBuilder = new LoginConfigBuilder(
- config);
- Configuration.setConfiguration(loginConfigBuilder.build());
- }
-
- @After
- public void tearDown() {
- }
-
- @Deployment
- public static WebArchive createDeployment() {
- final PomEquippedResolveStage pom = Maven
- .resolver()
- .loadPomFromFile("pom.xml");
- final PomEquippedResolveStage dependencies = pom
- .importCompileAndRuntimeDependencies();
- final File[] libs = dependencies.resolve().withTransitivity().asFile();
-
- for (File lib : libs) {
- System.err.printf("Adding file '%s' to test archive...%n",
- lib.getName());
- }
-
- return ShrinkWrap
- .create(WebArchive.class,
- "LibreCCM-org.libreccm.core.authentication.LoginManagerTest.war")
- .addPackage(CcmObject.class.getPackage())
- .addPackage(org.libreccm.web.CcmApplication.class.getPackage())
- .addPackage(org.libreccm.categorization.Category.class.
- getPackage())
- .addPackage(org.libreccm.l10n.LocalizedString.class.getPackage())
- .addPackage(org.libreccm.cdi.utils.CdiUtil.class.getPackage())
- .addPackage(org.libreccm.jpa.EntityManagerProducer.class
- .getPackage())
- .addPackage(org.libreccm.jpa.utils.MimeTypeConverter.class
- .getPackage())
- .addPackage(org.libreccm.testutils.EqualsVerifier.class.
- getPackage())
- .addPackage(org.libreccm.core.authentication.LoginManager.class
- .getPackage())
- .addPackage(com.arsdigita.kernel.KernelConfig.class.getPackage())
- .addPackage(com.arsdigita.runtime.AbstractConfig.class.getPackage())
- .addPackage(com.arsdigita.util.parameter.AbstractParameter.class
- .getPackage())
- .addPackage(com.arsdigita.util.UncheckedWrapperException.class
- .getPackage())
- .addPackage(com.arsdigita.xml.XML.class
- .getPackage())
- .addPackage(com.arsdigita.xml.formatters.DateTimeFormatter.class
- .getPackage())
- .addPackage(org.libreccm.tests.categories.IntegrationTest.class
- .getPackage())
- .addPackage(com.arsdigita.web.CCMApplicationContextListener.class
- .getPackage())
- .addAsLibraries(libs)
- .addAsResource("test-persistence.xml",
- "META-INF/persistence.xml")
- .addAsResource(
- "configtests/com/arsdigita/kernel/KernelConfigTest/ccm-core.config",
- "ccm-core.config")
- .addAsWebInfResource(
- "configtests/com/arsdigita/kernel/KernelConfigTest/registry.properties",
- "conf/registry/registry.properties")
- .addAsWebInfResource(
- "configtests/com/arsdigita/kernel/KernelConfigTest/kernel.properties",
- "conf/registry/ccm-core/kernel.properties")
- .addAsResource(
- "com/arsdigita/kernel/KernelConfig_parameter.properties",
- "com/arsdigita/kernel/KernelConfig_parameter.properties")
- .addAsWebInfResource("test-web.xml", "WEB-INF/web.xml")
- .addAsWebInfResource(EmptyAsset.INSTANCE, "WEB-INF/beans.xml");
- }
-
- @InSequence(1)
- public void isLoginManagerInjected() {
- assertThat(loginManager, is(not(nullValue())));
- }
-
- @InSequence(2)
- public void isCcmSessionContextInjected() {
- assertThat(ccmSessionContext, is(not(nullValue())));
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/authentication/LoginManagerTest/data.yml")
- @InSequence(10)
- public void loginValidCredentials() throws LoginException {
- loginManager.login("jdoe@example.com", "foobar");
-
- assertThat(ccmSessionContext.getCurrentSubject(), is(not(nullValue())));
- final EmailAddress emailAddress = new EmailAddress();
- emailAddress.setAddress("jdoe@example.com");
- emailAddress.setBouncing(false);
- emailAddress.setVerified(true);
-
- final Subject subject = ccmSessionContext.getCurrentSubject();
- assertThat(subject, is(instanceOf(User.class)));
-
- final User user = (User) subject;
- assertThat(user.getEmailAddresses(), contains(equalTo(emailAddress)));
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/authentication/LoginManagerTest/data.yml")
- @InSequence(20)
- public void loginWrongCredentials() throws LoginException {
- try {
- loginManager.login("jdoe@example.com", "wrong-pw");
- } catch (LoginException ex) {
- assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
- return;
- }
-
- fail("No login exception was thrown.");
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/authentication/LoginManagerTest/data.yml")
- @InSequence(30)
- public void loginEmptyPassword() {
- try {
- loginManager.login("jdoe@example.com", "");
- } catch (LoginException ex) {
- assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
- return;
- }
-
- fail("No login exception was thrown.");
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/authentication/LoginManagerTest/data.yml")
- @InSequence(40)
- public void loginEmptyUserName() {
- try {
- loginManager.login("", "correct-pw");
- } catch (LoginException ex) {
- assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
- return;
- }
-
- fail("No login exception was thrown.");
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/authentication/LoginManagerTest/data.yml")
- @InSequence(50)
- public void loginNullPassword() {
- try {
- loginManager.login("jdoe@example.com", null);
- } catch (LoginException ex) {
- assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
- return;
- }
-
- fail("No login exception was thrown.");
- }
-
- @Test
- @UsingDataSet(
- "datasets/org/libreccm/core/authentication/LoginManagerTest/data.yml")
- @InSequence(60)
- public void loginNullUsername() {
- try {
- loginManager.login(null, "correct-pw");
- } catch (LoginException ex) {
- assertThat(ccmSessionContext.getCurrentSubject(), is(nullValue()));
- return;
- }
-
- fail("No login exception was thrown.");
- }
-
-}
diff --git a/ccm-core/src/test/java/org/libreccm/core/authentication/UserPrincipalToStringTest.java.nolongerinuse b/ccm-core/src/test/java/org/libreccm/core/authentication/UserPrincipalToStringTest.java.nolongerinuse
deleted file mode 100644
index 73b3bb755..000000000
--- a/ccm-core/src/test/java/org/libreccm/core/authentication/UserPrincipalToStringTest.java.nolongerinuse
+++ /dev/null
@@ -1,85 +0,0 @@
-/*
- * Copyright (C) 2015 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.authentication;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-import java.lang.reflect.Field;
-import java.lang.reflect.Modifier;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Assert;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-/**
- *
- * @author Jens Pelzetter
- */
-public class UserPrincipalToStringTest {
-
- public UserPrincipalToStringTest() {
- }
-
- @BeforeClass
- public static void setUpClass() {
- }
-
- @AfterClass
- public static void tearDownClass() {
- }
-
- @Before
- public void setUp() {
- }
-
- @After
- public void tearDown() {
- }
-
- @Test
- public void verifyToString() throws IllegalArgumentException,
- IllegalAccessException {
- final UserPrincipal principal = new UserPrincipal(null);
-
- final Field[] fields = principal.getClass().getDeclaredFields();
- for (Field field : fields) {
- if (!Modifier.isStatic(field.getModifiers())
- && !field.getType().isPrimitive()) {
- field.setAccessible(true);
- field.set(principal, null);
- }
- }
-
- try {
- principal.toString();
- } catch (NullPointerException ex) {
- final StringWriter strWriter = new StringWriter();
- final PrintWriter writer = new PrintWriter(strWriter);
- ex.printStackTrace(writer);
- Assert.fail(String.format(
- "toString() implementation of of class \"%s\" "
- + "is not null safe:%n %s",
- principal.getClass().getName(),
- strWriter.toString()));
-
- }
- }
-}
diff --git a/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java b/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java
index 5cf5f8690..dbef8b8d8 100644
--- a/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java
+++ b/ccm-core/src/test/java/org/libreccm/security/PermissionCheckerTest.java
@@ -27,6 +27,8 @@ import com.arsdigita.web.CCMApplicationContextListener;
import com.arsdigita.xml.XML;
import com.arsdigita.xml.formatters.DateTimeFormatter;
+import static org.libreccm.core.CoreConstants.*;
+
import java.io.File;
import java.util.concurrent.Callable;
@@ -57,6 +59,7 @@ import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.junit.runner.RunWith;
import org.libreccm.categorization.Categorization;
+import org.libreccm.cdi.utils.CdiUtil;
import org.libreccm.core.CcmObject;
import org.libreccm.core.CcmObjectRepository;
import org.libreccm.jpa.EntityManagerProducer;
@@ -68,6 +71,9 @@ import org.libreccm.testutils.EqualsVerifier;
import org.libreccm.web.CcmApplication;
import org.libreccm.workflow.Workflow;
+import java.util.ArrayList;
+import java.util.List;
+
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
@@ -129,8 +135,8 @@ public class PermissionCheckerTest {
return ShrinkWrap
.create(WebArchive.class,
- "LibreCCM-org.libreccm.security.PermissionCheckerTest.war")
- .addPackage(User.class.getPackage())
+ "LibreCCM-org.libreccm.security.PermissionCheckerTest.war").
+ addPackage(User.class.getPackage())
.addPackage(CcmObject.class.getPackage())
.addPackage(Categorization.class.getPackage())
.addPackage(LocalizedString.class.getPackage())
@@ -148,6 +154,7 @@ public class PermissionCheckerTest {
.addPackage(CCMApplicationContextListener.class.getPackage())
.addPackage(XML.class.getPackage())
.addPackage(DateTimeFormatter.class.getPackage())
+ .addPackage(CdiUtil.class.getPackage())
.addAsLibraries(libs)
.addAsResource("test-persistence.xml",
"META-INF/persistence.xml")
@@ -184,7 +191,7 @@ public class PermissionCheckerTest {
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(100)
+ @InSequence(1100)
public void isPermittedAuthenticatedUser() {
final UsernamePasswordToken token = new UsernamePasswordToken("jdoe",
"foo123");
@@ -198,7 +205,7 @@ public class PermissionCheckerTest {
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(200)
+ @InSequence(1200)
public void isPermittedUnAuthenticatedUser() {
assertThat(permissionChecker.isPermitted("privilege1"), is(false));
assertThat(permissionChecker.isPermitted("privilege2"), is(false));
@@ -207,7 +214,7 @@ public class PermissionCheckerTest {
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(200)
+ @InSequence(1300)
public void isPermittedSystemUser() {
final CcmObject object1 = objectRepository.findById(-20001L);
final CcmObject object2 = objectRepository.findById(-20002L);
@@ -243,7 +250,7 @@ public class PermissionCheckerTest {
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(400)
+ @InSequence(1400)
public void isPermittedObjectAuthenticatedUser() {
final CcmObject object1 = objectRepository.findById(-20001L);
final CcmObject object2 = objectRepository.findById(-20002L);
@@ -264,7 +271,7 @@ public class PermissionCheckerTest {
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(500)
+ @InSequence(1500)
public void isPermittedObjectUnAuthenticatedUser() {
final CcmObject object1 = objectRepository.findById(-20001L);
final CcmObject object2 = objectRepository.findById(-20002L);
@@ -281,7 +288,7 @@ public class PermissionCheckerTest {
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(600)
+ @InSequence(2100)
public void checkPermissionAuthenticatedUser() {
final UsernamePasswordToken token = new UsernamePasswordToken("mmuster",
"foo123");
@@ -294,14 +301,14 @@ public class PermissionCheckerTest {
@Test(expected = AuthorizationException.class)
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
@ShouldThrowException(AuthorizationException.class)
- @InSequence(600)
+ @InSequence(2200)
public void checkPermissionUnAuthenticatedUser() {
permissionChecker.checkPermission("privilege1");
}
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(600)
+ @InSequence(2300)
public void checkPermissionObjectAuthenticatedUser() {
final CcmObject object2 = objectRepository.findById(-20002L);
@@ -316,7 +323,7 @@ public class PermissionCheckerTest {
@Test(expected = AuthorizationException.class)
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
@ShouldThrowException(AuthorizationException.class)
- @InSequence(600)
+ @InSequence(2400)
public void checkPermissionObjectUnAuthenticatedUser() {
final CcmObject object2 = objectRepository.findById(-20002L);
@@ -325,7 +332,7 @@ public class PermissionCheckerTest {
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(600)
+ @InSequence(2500)
public void checkPermissionObjectPublicUser() {
final CcmObject object1 = objectRepository.findById(-20001L);
@@ -334,7 +341,7 @@ public class PermissionCheckerTest {
@Test
@UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
- @InSequence(600)
+ @InSequence(2600)
public void checkPermissionObjectSystemUser() {
final CcmObject object1 = objectRepository.findById(-20001L);
final CcmObject object2 = objectRepository.findById(-20002L);
@@ -358,4 +365,98 @@ public class PermissionCheckerTest {
});
}
+ @Test
+ @UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
+ @InSequence(3100)
+ public void checkPermissionReturnObjectAuthenticatedUser() {
+ final CcmObject object2 = objectRepository.findById(-20002L);
+
+ final UsernamePasswordToken token = new UsernamePasswordToken("jdoe",
+ "foo123");
+ token.setRememberMe(true);
+ subject.login(token);
+
+ final CcmObject result = permissionChecker.checkPermission(
+ "privilege2", object2, CcmObject.class);
+ assertThat(result.getDisplayName(), is(equalTo("object2")));
+ assertThat(permissionChecker.isAccessDeniedObject(result), is(false));
+ assertThat(result, is(equalTo(object2)));
+ }
+
+ @Test
+ @UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
+ @InSequence(3200)
+ public void checkPermissionReturnObjectUnAuthenticatedUser() {
+ final CcmObject object2 = objectRepository.findById(-20002L);
+
+ final CcmObject result = permissionChecker.checkPermission(
+ "privilege2", object2, CcmObject.class);
+ assertThat(result.getDisplayName(), is(equalTo(ACCESS_DENIED)));
+ assertThat(permissionChecker.isAccessDeniedObject(result), is(true));
+ assertThat(result, is(not(equalTo(object2))));
+ }
+
+ @Test
+ @UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
+ @InSequence(600)
+ public void checkPermissionReturnObjectPublicUser() {
+ final CcmObject object1 = objectRepository.findById(-20001L);
+
+ final CcmObject result = permissionChecker.checkPermission(
+ "privilege3", object1, CcmObject.class);
+ assertThat(result.getDisplayName(), is(equalTo("object1")));
+ assertThat(permissionChecker.isAccessDeniedObject(result), is(false));
+ assertThat(result, is(equalTo(object1)));
+ }
+
+ @Test
+ @UsingDataSet("datasets/org/libreccm/security/ShiroTest/data.yml")
+ @InSequence(3200)
+ public void checkPermissionReturnObjectSystemUser() {
+ final CcmObject object1 = objectRepository.findById(-20001L);
+ final CcmObject object2 = objectRepository.findById(-20002L);
+ final CcmObject object3 = objectRepository.findById(-20003L);
+
+ final List results = shiro.getSystemUser().execute(
+ new Callable>() {
+
+ @Override
+ public List call() {
+ permissionChecker.checkPermission("privilege1");
+ permissionChecker.checkPermission("privilege2");
+ permissionChecker.checkPermission("privilege3");
+
+ final CcmObject result3 = permissionChecker.checkPermission(
+ "privilege1", object3, CcmObject.class);
+ final CcmObject result1 = permissionChecker.checkPermission(
+ "privilege2", object1, CcmObject.class);
+ final CcmObject result2 = permissionChecker.checkPermission(
+ "privilege3", object2, CcmObject.class);
+
+ final List results = new ArrayList<>();
+ results.add(result1);
+ results.add(result2);
+ results.add(result3);
+
+ return results;
+ }
+ });
+
+ final CcmObject result1 = results.get(0);
+ final CcmObject result2 = results.get(1);
+ final CcmObject result3 = results.get(2);
+
+ assertThat(result1.getDisplayName(), is(equalTo("object1")));
+ assertThat(permissionChecker.isAccessDeniedObject(result1), is(false));
+ assertThat(result1, is(equalTo(object1)));
+
+ assertThat(result2.getDisplayName(), is(equalTo("object2")));
+ assertThat(permissionChecker.isAccessDeniedObject(result2), is(false));
+ assertThat(result2, is(equalTo(object2)));
+
+ assertThat(result3.getDisplayName(), is(equalTo("object3")));
+ assertThat(permissionChecker.isAccessDeniedObject(result3), is(false));
+ assertThat(result3, is(equalTo(object3)));
+ }
+
}