[seam-commits] Seam SVN: r12456 - in modules/security/trunk: impl/src/main/java/org/jboss/seam/security/management and 1 other directory.
seam-commits at lists.jboss.org
seam-commits at lists.jboss.org
Tue Apr 13 07:04:07 EDT 2010
Author: shane.bryzak at jboss.com
Date: 2010-04-13 07:04:07 -0400 (Tue, 13 Apr 2010)
New Revision: 12456
Added:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/IdentityManagerImpl.java
Modified:
modules/security/trunk/api/src/main/java/org/jboss/seam/security/management/IdentityManager.java
Log:
split IdentityManager interface from implementation
Modified: modules/security/trunk/api/src/main/java/org/jboss/seam/security/management/IdentityManager.java
===================================================================
--- modules/security/trunk/api/src/main/java/org/jboss/seam/security/management/IdentityManager.java 2010-04-13 10:47:35 UTC (rev 12455)
+++ modules/security/trunk/api/src/main/java/org/jboss/seam/security/management/IdentityManager.java 2010-04-13 11:04:07 UTC (rev 12456)
@@ -1,211 +1,52 @@
package org.jboss.seam.security.management;
-import java.io.Serializable;
import java.security.Principal;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
-import javax.annotation.PostConstruct;
-import javax.enterprise.context.ApplicationScoped;
-import javax.enterprise.inject.spi.BeanManager;
-import javax.inject.Inject;
-import javax.inject.Named;
-
-import org.jboss.seam.security.Identity;
-import org.jboss.seam.security.util.Strings;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
/**
* Identity Management API, deals with user name/password-based identity management.
*
* @author Shane Bryzak
*/
- at Named @ApplicationScoped
-public class IdentityManager implements Serializable
-{
- private static final long serialVersionUID = 6864253169970552893L;
-
- public static final String USER_PERMISSION_NAME = "seam.user";
- public static final String ROLE_PERMISSION_NAME = "seam.role";
-
- public static final String PERMISSION_CREATE = "create";
- public static final String PERMISSION_READ = "read";
- public static final String PERMISSION_UPDATE = "update";
- public static final String PERMISSION_DELETE = "delete";
-
- private Logger log = LoggerFactory.getLogger(IdentityManager.class);
-
- @Inject BeanManager manager;
- @Inject Identity identity;
-
- private IdentityStore identityStore;
- private IdentityStore roleIdentityStore;
-
- @PostConstruct
- public void create()
- {
- if (roleIdentityStore == null && identityStore != null)
- {
- roleIdentityStore = identityStore;
- }
-
- if (identityStore == null)
- {
- log.warn("No identity store available - please configure an identityStore if identity " +
- "management is required.");
- }
-
- if (roleIdentityStore == null)
- {
- log.warn("No role identity store available - please configure a roleIdentityStore if identity " +
- "management is required.");
- }
- }
-
- public boolean createUser(String name, String password)
- {
- return createUser(name, password, null, null);
- }
+public interface IdentityManager
+{
+ boolean createUser(String name, String password);
- public boolean createUser(String name, String password, String firstname, String lastname)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_CREATE);
- return identityStore.createUser(name, password, firstname, lastname);
- }
+ boolean createUser(String name, String password, String firstname, String lastname);
- public boolean deleteUser(String name)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_DELETE);
- return identityStore.deleteUser(name);
- }
+ boolean deleteUser(String name);
- public boolean enableUser(String name)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
- return identityStore.enableUser(name);
- }
+ boolean enableUser(String name);
- public boolean disableUser(String name)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
- return identityStore.disableUser(name);
- }
+ boolean disableUser(String name);
- public boolean changePassword(String name, String password)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
- return identityStore.changePassword(name, password);
- }
+ boolean changePassword(String name, String password);
- public boolean isUserEnabled(String name)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
- return identityStore.isUserEnabled(name);
- }
+ boolean isUserEnabled(String name);
- public boolean grantRole(String name, String role)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
- return roleIdentityStore.grantRole(name, role);
- }
+ boolean grantRole(String name, String role);
- public boolean revokeRole(String name, String role)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
- return roleIdentityStore.revokeRole(name, role);
- }
+ boolean revokeRole(String name, String role);
- public boolean createRole(String role)
- {
- identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_CREATE);
- return roleIdentityStore.createRole(role);
- }
+ boolean createRole(String role);
- public boolean deleteRole(String role)
- {
- identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_DELETE);
- return roleIdentityStore.deleteRole(role);
- }
+ boolean deleteRole(String role);
- public boolean addRoleToGroup(String role, String group)
- {
- identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_UPDATE);
- return roleIdentityStore.addRoleToGroup(role, group);
- }
+ boolean addRoleToGroup(String role, String group);
- public boolean removeRoleFromGroup(String role, String group)
- {
- identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_UPDATE);
- return roleIdentityStore.removeRoleFromGroup(role, group);
- }
+ boolean removeRoleFromGroup(String role, String group);
- public boolean userExists(String name)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
- return identityStore.userExists(name);
- }
+ boolean userExists(String name);
- public boolean roleExists(String name)
- {
- return roleIdentityStore.roleExists(name);
- }
+ boolean roleExists(String name);
- public List<String> getUsers()
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
- List<String> users = identityStore.listUsers();
-
- Collections.sort(users, new Comparator<String>() {
- public int compare(String value1, String value2) {
- return value1.compareTo(value2);
- }
- });
-
- return users;
- }
+ List<String> getUsers();
- public List<String> getUsers(String filter)
- {
- identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
- List<String> users = identityStore.listUsers(filter);
-
- Collections.sort(users, new Comparator<String>() {
- public int compare(String value1, String value2) {
- return value1.compareTo(value2);
- }
- });
-
- return users;
- }
+ List<String> getUsers(String filter);
- public List<String> getRoles()
- {
- identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_READ);
- List<String> roles = roleIdentityStore.listRoles();
-
- Collections.sort(roles, new Comparator<String>() {
- public int compare(String value1, String value2) {
- return value1.compareTo(value2);
- }
- });
-
- return roles;
- }
+ List<String> getRoles();
- public List<String> getGrantableRoles()
- {
- List<String> roles = roleIdentityStore.listGrantableRoles();
-
- Collections.sort(roles, new Comparator<String>() {
- public int compare(String value1, String value2) {
- return value1.compareTo(value2);
- }
- });
-
- return roles;
- }
+ List<String> getGrantableRoles();
/**
* Returns a list of the roles that are explicitly granted to the specified user;
@@ -213,10 +54,7 @@
* @param name The user for which to return a list of roles
* @return List containing the names of the granted roles
*/
- public List<String> getGrantedRoles(String name)
- {
- return roleIdentityStore.getGrantedRoles(name);
- }
+ List<String> getGrantedRoles(String name);
/**
* Returns a list of roles that are either explicitly or indirectly granted to the specified user.
@@ -224,51 +62,21 @@
* @param name The user for which to return the list of roles
* @return List containing the names of the implied roles
*/
- public List<String> getImpliedRoles(String name)
- {
- return roleIdentityStore.getImpliedRoles(name);
- }
+ List<String> getImpliedRoles(String name);
- public List<Principal> listMembers(String role)
- {
- identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_READ);
- return roleIdentityStore.listMembers(role);
- }
+ List<Principal> listMembers(String role);
- public List<String> getRoleGroups(String name)
- {
- return roleIdentityStore.getRoleGroups(name);
- }
+ List<String> getRoleGroups(String name);
- public boolean authenticate(String username, String password)
- {
- if (Strings.isEmpty(username)) return false;
- return identityStore.authenticate(username, password);
- }
+ boolean authenticate(String username, String password);
- public IdentityStore getIdentityStore()
- {
- return identityStore;
- }
+ IdentityStore getIdentityStore();
- public void setIdentityStore(IdentityStore identityStore)
- {
- this.identityStore = identityStore;
- }
+ void setIdentityStore(IdentityStore identityStore);
- public IdentityStore getRoleIdentityStore()
- {
- return roleIdentityStore;
- }
+ IdentityStore getRoleIdentityStore();
- public void setRoleIdentityStore(IdentityStore roleIdentityStore)
- {
- this.roleIdentityStore = roleIdentityStore;
- }
+ void setRoleIdentityStore(IdentityStore roleIdentityStore);
- public boolean isEnabled()
- {
- return identityStore != null && roleIdentityStore != null;
- }
-
+ boolean isEnabled();
}
Added: modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/IdentityManagerImpl.java
===================================================================
--- modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/IdentityManagerImpl.java (rev 0)
+++ modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/IdentityManagerImpl.java 2010-04-13 11:04:07 UTC (rev 12456)
@@ -0,0 +1,273 @@
+package org.jboss.seam.security.management;
+
+import java.io.Serializable;
+import java.security.Principal;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+
+import javax.annotation.PostConstruct;
+import javax.enterprise.context.ApplicationScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.inject.Inject;
+import javax.inject.Named;
+
+import org.jboss.seam.security.Identity;
+import org.jboss.seam.security.util.Strings;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Default IdentityManager implementation
+ *
+ * @author Shane Bryzak
+ */
+ at Named @ApplicationScoped
+public class IdentityManagerImpl implements IdentityManager, Serializable
+{
+ private static final long serialVersionUID = 6864253169970552893L;
+
+ public static final String USER_PERMISSION_NAME = "seam.user";
+ public static final String ROLE_PERMISSION_NAME = "seam.role";
+
+ public static final String PERMISSION_CREATE = "create";
+ public static final String PERMISSION_READ = "read";
+ public static final String PERMISSION_UPDATE = "update";
+ public static final String PERMISSION_DELETE = "delete";
+
+ private Logger log = LoggerFactory.getLogger(IdentityManager.class);
+
+ @Inject BeanManager manager;
+ @Inject Identity identity;
+
+ private IdentityStore identityStore;
+ private IdentityStore roleIdentityStore;
+
+ @PostConstruct
+ public void create()
+ {
+ if (roleIdentityStore == null && identityStore != null)
+ {
+ roleIdentityStore = identityStore;
+ }
+
+ if (identityStore == null)
+ {
+ log.warn("No identity store available - please configure an identityStore if identity " +
+ "management is required.");
+ }
+
+ if (roleIdentityStore == null)
+ {
+ log.warn("No role identity store available - please configure a roleIdentityStore if identity " +
+ "management is required.");
+ }
+ }
+
+ public boolean createUser(String name, String password)
+ {
+ return createUser(name, password, null, null);
+ }
+
+ public boolean createUser(String name, String password, String firstname, String lastname)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_CREATE);
+ return identityStore.createUser(name, password, firstname, lastname);
+ }
+
+ public boolean deleteUser(String name)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_DELETE);
+ return identityStore.deleteUser(name);
+ }
+
+ public boolean enableUser(String name)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
+ return identityStore.enableUser(name);
+ }
+
+ public boolean disableUser(String name)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
+ return identityStore.disableUser(name);
+ }
+
+ public boolean changePassword(String name, String password)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
+ return identityStore.changePassword(name, password);
+ }
+
+ public boolean isUserEnabled(String name)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
+ return identityStore.isUserEnabled(name);
+ }
+
+ public boolean grantRole(String name, String role)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
+ return roleIdentityStore.grantRole(name, role);
+ }
+
+ public boolean revokeRole(String name, String role)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_UPDATE);
+ return roleIdentityStore.revokeRole(name, role);
+ }
+
+ public boolean createRole(String role)
+ {
+ identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_CREATE);
+ return roleIdentityStore.createRole(role);
+ }
+
+ public boolean deleteRole(String role)
+ {
+ identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_DELETE);
+ return roleIdentityStore.deleteRole(role);
+ }
+
+ public boolean addRoleToGroup(String role, String group)
+ {
+ identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_UPDATE);
+ return roleIdentityStore.addRoleToGroup(role, group);
+ }
+
+ public boolean removeRoleFromGroup(String role, String group)
+ {
+ identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_UPDATE);
+ return roleIdentityStore.removeRoleFromGroup(role, group);
+ }
+
+ public boolean userExists(String name)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
+ return identityStore.userExists(name);
+ }
+
+ public boolean roleExists(String name)
+ {
+ return roleIdentityStore.roleExists(name);
+ }
+
+ public List<String> getUsers()
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
+ List<String> users = identityStore.listUsers();
+
+ Collections.sort(users, new Comparator<String>() {
+ public int compare(String value1, String value2) {
+ return value1.compareTo(value2);
+ }
+ });
+
+ return users;
+ }
+
+ public List<String> getUsers(String filter)
+ {
+ identity.checkPermission(USER_PERMISSION_NAME, PERMISSION_READ);
+ List<String> users = identityStore.listUsers(filter);
+
+ Collections.sort(users, new Comparator<String>() {
+ public int compare(String value1, String value2) {
+ return value1.compareTo(value2);
+ }
+ });
+
+ return users;
+ }
+
+ public List<String> getRoles()
+ {
+ identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_READ);
+ List<String> roles = roleIdentityStore.listRoles();
+
+ Collections.sort(roles, new Comparator<String>() {
+ public int compare(String value1, String value2) {
+ return value1.compareTo(value2);
+ }
+ });
+
+ return roles;
+ }
+
+ public List<String> getGrantableRoles()
+ {
+ List<String> roles = roleIdentityStore.listGrantableRoles();
+
+ Collections.sort(roles, new Comparator<String>() {
+ public int compare(String value1, String value2) {
+ return value1.compareTo(value2);
+ }
+ });
+
+ return roles;
+ }
+
+ /**
+ * Returns a list of the roles that are explicitly granted to the specified user;
+ *
+ * @param name The user for which to return a list of roles
+ * @return List containing the names of the granted roles
+ */
+ public List<String> getGrantedRoles(String name)
+ {
+ return roleIdentityStore.getGrantedRoles(name);
+ }
+
+ /**
+ * Returns a list of roles that are either explicitly or indirectly granted to the specified user.
+ *
+ * @param name The user for which to return the list of roles
+ * @return List containing the names of the implied roles
+ */
+ public List<String> getImpliedRoles(String name)
+ {
+ return roleIdentityStore.getImpliedRoles(name);
+ }
+
+ public List<Principal> listMembers(String role)
+ {
+ identity.checkPermission(ROLE_PERMISSION_NAME, PERMISSION_READ);
+ return roleIdentityStore.listMembers(role);
+ }
+
+ public List<String> getRoleGroups(String name)
+ {
+ return roleIdentityStore.getRoleGroups(name);
+ }
+
+ public boolean authenticate(String username, String password)
+ {
+ if (Strings.isEmpty(username)) return false;
+ return identityStore.authenticate(username, password);
+ }
+
+ public IdentityStore getIdentityStore()
+ {
+ return identityStore;
+ }
+
+ public void setIdentityStore(IdentityStore identityStore)
+ {
+ this.identityStore = identityStore;
+ }
+
+ public IdentityStore getRoleIdentityStore()
+ {
+ return roleIdentityStore;
+ }
+
+ public void setRoleIdentityStore(IdentityStore roleIdentityStore)
+ {
+ this.roleIdentityStore = roleIdentityStore;
+ }
+
+ public boolean isEnabled()
+ {
+ return identityStore != null && roleIdentityStore != null;
+ }
+}
More information about the seam-commits
mailing list