Author: shane.bryzak(a)jboss.com
Date: 2010-07-21 04:30:31 -0400 (Wed, 21 Jul 2010)
New Revision: 13454
Added:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/ChangePasswordAction.java
Modified:
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/action/UserAction.java
Log:
remove dependency on IdentityManager, add ChangePasswordAction
Modified:
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 2010-07-20
22:31:51 UTC (rev 13453)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/IdentityManagerImpl.java 2010-07-21
08:30:31 UTC (rev 13454)
@@ -9,11 +9,11 @@
import javax.enterprise.inject.spi.BeanManager;
import javax.inject.Inject;
+import org.jboss.seam.persistence.transaction.Transactional;
import org.jboss.seam.security.GroupImpl;
import org.jboss.seam.security.Identity;
import org.jboss.seam.security.UserImpl;
import org.jboss.seam.security.util.Strings;
-import org.jboss.seam.persistence.transaction.Transactional;
import org.picketlink.idm.api.Credential;
import org.picketlink.idm.api.Group;
import org.picketlink.idm.api.IdentitySearchCriteria;
@@ -21,9 +21,6 @@
import org.picketlink.idm.api.Role;
import org.picketlink.idm.api.RoleType;
import org.picketlink.idm.api.User;
-import org.picketlink.idm.api.query.QueryException;
-import org.picketlink.idm.api.query.UserQuery;
-import org.picketlink.idm.api.query.UserQueryBuilder;
import org.picketlink.idm.common.exception.FeatureNotSupportedException;
import org.picketlink.idm.common.exception.IdentityException;
import org.picketlink.idm.impl.api.IdentitySearchCriteriaImpl;
Added:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/ChangePasswordAction.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/ChangePasswordAction.java
(rev 0)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/ChangePasswordAction.java 2010-07-21
08:30:31 UTC (rev 13454)
@@ -0,0 +1,76 @@
+package org.jboss.seam.security.management.action;
+
+import java.io.Serializable;
+
+import javax.enterprise.inject.Model;
+import javax.inject.Inject;
+
+import org.jboss.seam.persistence.transaction.Transactional;
+import org.jboss.seam.security.Identity;
+import org.picketlink.idm.api.Credential;
+import org.picketlink.idm.api.IdentitySession;
+import org.picketlink.idm.common.exception.IdentityException;
+import org.picketlink.idm.impl.api.PasswordCredential;
+
+public @Transactional @Model class ChangePasswordAction implements Serializable
+{
+ private static final long serialVersionUID = -8727330690588109980L;
+
+ private String oldPassword;
+ private String newPassword;
+ private String confirmPassword;
+
+ @Inject Identity identity;
+ @Inject IdentitySession identitySession;
+
+ public String changePassword() throws IdentityException
+ {
+ if (!identitySession.getAttributesManager().validateCredentials(identity.getUser(),
+ new Credential[] { new PasswordCredential(oldPassword)}))
+ {
+ // TODO add a message
+
+ return "failed";
+ }
+
+ if (!confirmPassword.equals(newPassword))
+ {
+ // TODO add a message
+
+ return "failed";
+ }
+
+ identitySession.getAttributesManager().updatePassword(identity.getUser(),
newPassword);
+ return "success";
+ }
+
+ public String getOldPassword()
+ {
+ return oldPassword;
+ }
+
+ public void setOldPassword(String oldPassword)
+ {
+ this.oldPassword = oldPassword;
+ }
+
+ public String getNewPassword()
+ {
+ return newPassword;
+ }
+
+ public void setNewPassword(String newPassword)
+ {
+ this.newPassword = newPassword;
+ }
+
+ public String getConfirmPassword()
+ {
+ return confirmPassword;
+ }
+
+ public void setConfirmPassword(String confirmPassword)
+ {
+ this.confirmPassword = confirmPassword;
+ }
+}
Modified:
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java
===================================================================
---
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java 2010-07-20
22:31:51 UTC (rev 13453)
+++
modules/security/trunk/impl/src/main/java/org/jboss/seam/security/management/action/UserAction.java 2010-07-21
08:30:31 UTC (rev 13454)
@@ -10,19 +10,27 @@
import javax.inject.Inject;
import javax.inject.Named;
-import org.jboss.seam.security.management.IdentityManager;
+import org.jboss.seam.persistence.transaction.Transactional;
+import org.jboss.seam.security.UserImpl;
+import org.picketlink.idm.api.Attribute;
+import org.picketlink.idm.api.IdentitySession;
import org.picketlink.idm.api.Role;
-import org.picketlink.idm.impl.api.PasswordCredential;
+import org.picketlink.idm.api.RoleType;
+import org.picketlink.idm.api.User;
+import org.picketlink.idm.common.exception.FeatureNotSupportedException;
+import org.picketlink.idm.common.exception.IdentityException;
/**
* A conversation-scoped component for creating and managing user accounts
*
* @author Shane Bryzak
*/
-public @Named @ConversationScoped class UserAction implements Serializable
+public @Transactional @Named @ConversationScoped class UserAction implements
Serializable
{
private static final long serialVersionUID = 5820385095080724087L;
+ private static final String ATTRIBUTE_NAME_USER_ENABLED = "USER_ENABLED";
+
private String firstname;
private String lastname;
private String username;
@@ -33,7 +41,7 @@
private boolean newUserFlag;
- @Inject IdentityManager identityManager;
+ @Inject IdentitySession identitySession;
@Inject Conversation conversation;
public void createUser()
@@ -43,21 +51,31 @@
newUserFlag = true;
}
- public void editUser(String username)
+ public void editUser(String username) throws IdentityException,
FeatureNotSupportedException
{
conversation.begin();
this.username = username;
- roles = identityManager.getUserRoles(username);
- enabled = identityManager.isUserEnabled(username);
+
+ Collection<RoleType> roleTypes =
identitySession.getRoleManager().findUserRoleTypes(new UserImpl(username));
+
+ for (RoleType roleType : roleTypes)
+ {
+ roles.addAll(identitySession.getRoleManager().findRoles(username,
roleType.getName()));
+ }
+
+ Attribute enabledAttr =
identitySession.getAttributesManager().getAttribute(username,
+ ATTRIBUTE_NAME_USER_ENABLED);
+ enabled = enabledAttr != null ? (Boolean) enabledAttr.getValue() : true;
+
newUserFlag = false;
}
- public void deleteUser(String username)
+ public void deleteUser(String username) throws IdentityException
{
- identityManager.deleteUser(username);
+ identitySession.getPersistenceManager().removeUser(new UserImpl(username), true);
}
- public String save()
+ public String save() throws IdentityException, FeatureNotSupportedException
{
if (newUserFlag)
{
@@ -74,7 +92,7 @@
conversation.end();
}
- private String saveNewUser()
+ private String saveNewUser() throws IdentityException
{
if (password == null || !password.equals(confirm))
{
@@ -83,29 +101,15 @@
return "failure";
}
- boolean success = identityManager.createUser(username, new
PasswordCredential(password));
-
- if (success)
- {
- /*for (String role : roles)
- {
- identityManager.grantRole(username, role);
- }*/
+ User user = identitySession.getPersistenceManager().createUser(username);
+ identitySession.getAttributesManager().updatePassword(user, password);
+
+ conversation.end();
- if (!enabled)
- {
- identityManager.disableUser(username);
- }
-
- conversation.end();
-
- return "success";
- }
-
- return "failure";
+ return "success";
}
- private String saveExistingUser()
+ private String saveExistingUser() throws IdentityException,
FeatureNotSupportedException
{
// Check if a new password has been entered
if (password != null && !"".equals(password))
@@ -118,19 +122,27 @@
}
else
{
- identityManager.updateCredential(username, new
PasswordCredential(password));
+ identitySession.getAttributesManager().updatePassword(new UserImpl(username),
password);
}
}
- Collection<Role> grantedRoles = identityManager.getUserRoles(username);
+ Collection<Role> grantedRoles = new ArrayList<Role>();
+ Collection<RoleType> roleTypes =
identitySession.getRoleManager().findUserRoleTypes(new UserImpl(username));
+
+ for (RoleType roleType : roleTypes)
+ {
+ grantedRoles.addAll(identitySession.getRoleManager().findRoles(username,
roleType.getName()));
+ }
+
if (grantedRoles != null)
{
for (Role role : grantedRoles)
{
- if (!roles.contains(role)) identityManager.revokeRole(username,
- role.getRoleType().getName(), role.getGroup().getName(),
- role.getGroup().getGroupType());
+ if (!roles.contains(role))
+ {
+ identitySession.getRoleManager().removeRole(role);
+ }
}
}
@@ -138,18 +150,17 @@
{
if (grantedRoles == null || !grantedRoles.contains(role))
{
- identityManager.grantRole(username, role.getRoleType().getName(),
- role.getGroup().getName(), role.getGroup().getGroupType());
+ identitySession.getRoleManager().createRole(role.getRoleType(),
role.getUser(), role.getGroup());
}
}
if (enabled)
{
- identityManager.enableUser(username);
+ //identityManager.enableUser(username);
}
else
{
- identityManager.disableUser(username);
+ //identityManager.disableUser(username);
}
conversation.end();
Show replies by date