[jboss-cvs] jboss-seam/src/main/org/jboss/seam/security/management ...
Shane Bryzak
sbryzak at redhat.com
Thu Dec 13 21:36:38 EST 2007
User: sbryzak2
Date: 07/12/13 21:36:38
Modified: src/main/org/jboss/seam/security/management
IdentityStore.java JpaIdentityStore.java
Log:
minor refactor, added events
Revision Changes Path
1.4 +1 -22 jboss-seam/src/main/org/jboss/seam/security/management/IdentityStore.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: IdentityStore.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/management/IdentityStore.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- IdentityStore.java 10 Dec 2007 05:57:21 -0000 1.3
+++ IdentityStore.java 14 Dec 2007 02:36:38 -0000 1.4
@@ -1,10 +1,7 @@
package org.jboss.seam.security.management;
-import java.security.MessageDigest;
import java.util.List;
-import org.jboss.seam.util.Hex;
-
/**
* The identity store does the actual work of persisting user accounts in a
* database, LDAP directory, etc.
@@ -13,9 +10,6 @@
*/
public abstract class IdentityStore
{
- private String hashFunction = "MD5";
- private String hashCharset = "UTF-8";
-
protected abstract boolean createAccount(String username, String password);
protected abstract boolean deleteAccount(String name);
@@ -33,19 +27,4 @@
protected abstract List<String> getImpliedRoles(String name);
protected abstract boolean authenticate(String username, String password);
-
- protected String hashPassword(String password)
- {
- try {
- MessageDigest md = MessageDigest.getInstance(hashFunction);
- md.update(password.getBytes(hashCharset));
- byte[] raw = md.digest();
-
- // TODO - salt the hash, possibly using the user name?
- return new String(Hex.encodeHex(raw));
- }
- catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
}
1.4 +49 -1 jboss-seam/src/main/org/jboss/seam/security/management/JpaIdentityStore.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: JpaIdentityStore.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/security/management/JpaIdentityStore.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- JpaIdentityStore.java 10 Dec 2007 05:57:21 -0000 1.3
+++ JpaIdentityStore.java 14 Dec 2007 02:36:38 -0000 1.4
@@ -3,6 +3,7 @@
import static org.jboss.seam.ScopeType.APPLICATION;
import static org.jboss.seam.security.management.UserAccount.AccountType;
+import java.security.MessageDigest;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -15,6 +16,8 @@
import org.jboss.seam.annotations.Create;
import org.jboss.seam.annotations.Scope;
import org.jboss.seam.annotations.intercept.BypassInterceptors;
+import org.jboss.seam.core.Events;
+import org.jboss.seam.util.Hex;
/**
* The default identity store implementation, uses JPA as its persistence mechanism.
@@ -25,6 +28,12 @@
@BypassInterceptors
public class JpaIdentityStore extends IdentityStore
{
+ public static final String EVENT_ACCOUNT_CREATED = "org.jboss.seam.security.management.accountCreated";
+ public static final String EVENT_ACCOUNT_AUTHENTICATED = "org.jboss.seam.security.management.accountAuthenticated";
+
+ private String hashFunction = "MD5";
+ private String hashCharset = "UTF-8";
+
private Class<? extends UserAccount> accountClass;
private String entityManagerName = "entityManager";
@@ -74,6 +83,8 @@
persistAccount(account);
+ if (Events.exists()) Events.instance().raiseEvent(EVENT_ACCOUNT_CREATED, account);
+
return true;
}
catch (Exception ex)
@@ -223,9 +234,23 @@
return false;
}
- return hashPassword(password).equals(account.getPasswordHash());
+ boolean success = hashPassword(password).equals(account.getPasswordHash());
+
+ if (success && Events.exists())
+ {
+ Events.instance().raiseEvent(EVENT_ACCOUNT_AUTHENTICATED, account);
+ }
+
+ return success;
}
+ /**
+ * Retrieves a user UserAccount from persistent storage. If the UserAccount does
+ * not exist, an IdentityManagementException is thrown.
+ *
+ * @param name The user's username
+ * @return The UserAccount for the specified user
+ */
protected UserAccount validateUser(String name)
{
try
@@ -243,6 +268,13 @@
}
}
+ /**
+ * Retrieves a role UserAccount from persistent storage. If the UserAccount
+ * does not exist, an IdentityManagementException is thrown.
+ *
+ * @param name The role name
+ * @return The UserAccount for the specific role
+ */
protected UserAccount validateRole(String name)
{
// The role *should* be cached
@@ -340,4 +372,20 @@
{
this.accountClass = accountClass;
}
+
+
+ protected String hashPassword(String password)
+ {
+ try {
+ MessageDigest md = MessageDigest.getInstance(hashFunction);
+ md.update(password.getBytes(hashCharset));
+ byte[] raw = md.digest();
+
+ // TODO - salt the hash, possibly using the user name?
+ return new String(Hex.encodeHex(raw));
+ }
+ catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
}
More information about the jboss-cvs-commits
mailing list