Author: amarkhel
Date: 2009-04-30 07:32:18 -0400 (Thu, 30 Apr 2009)
New Revision: 13937
Added:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/UserManager.java
trunk/examples/photoalbum/source/web/src/main/webapp/WEB-INF/components.xml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/image/imageEditInfo.xhtml
trunk/examples/photoalbum/source/web/src/main/webapp/includes/userPrefs/userPrefsEdit.xhtml
Log:
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java 2009-04-30
10:47:31 UTC (rev 13936)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/Authenticator.java 2009-04-30
11:32:18 UTC (rev 13937)
@@ -43,6 +43,7 @@
import org.richfaces.photoalbum.domain.User;
import org.richfaces.photoalbum.service.Constants;
import org.richfaces.photoalbum.service.IUserAction;
+import org.richfaces.photoalbum.util.HashUtils;
@Name("authenticator")
@Scope(ScopeType.CONVERSATION)
@@ -61,30 +62,7 @@
@In IUserAction userAction;
private boolean loginFailed = false;
-
- private String digestAlgorithm;
- private String charset;
-
- public void setDigestAlgorithm(String algorithm) {
- this.digestAlgorithm = algorithm;
- }
-
- public void setCharset(String charset) {
- this.charset = charset;
- }
-
- public String hash(String plainTextPassword) {
- try {
- MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
- digest.update(plainTextPassword.getBytes(charset));
- byte[] rawHash = digest.digest();
- return new String(Hex.encodeHex(rawHash));
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
public void login(){
if(identity.hasRole(Constants.ADMIN_ROLE)){
return;
@@ -111,7 +89,7 @@
if(checkPassword(user) || checkUserExist(user)){
return;
}
- user.setPasswordHash(hash(user.getPassword()));
+ user.setPasswordHash(HashUtils.hash(user.getPassword()));
user.setPreDefined(false);
File avatarData =
(File)Contexts.getConversationContext().get(Constants.AVATAR_DATA_COMPONENT);
if(avatarData != null){
@@ -172,7 +150,7 @@
return true;
}
try {
- User user = userAction.login(credentials.getUsername(),
hash(credentials.getPassword()));
+ User user = userAction.login(credentials.getUsername(),
HashUtils.hash(credentials.getPassword()));
if (user != null) {
identity.addRole(Constants.ADMIN_ROLE);
Events.instance().raiseEvent(Constants.AUTHENTICATED_EVENT, user);
Modified:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/UserManager.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/UserManager.java 2009-04-30
10:47:31 UTC (rev 13936)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/manager/UserManager.java 2009-04-30
11:32:18 UTC (rev 13937)
@@ -34,6 +34,7 @@
import org.richfaces.photoalbum.domain.User;
import org.richfaces.photoalbum.service.Constants;
import org.richfaces.photoalbum.service.IUserAction;
+import org.richfaces.photoalbum.util.HashUtils;
@Name("userManager")
@Scope(ScopeType.EVENT)
@@ -60,8 +61,9 @@
avatarData.delete();
avatarData = null;
user.setHasAvatar(true);
+ }try{
user.setPreDefined(false);
- }try{
+ user.setPasswordHash(HashUtils.hash(user.getPassword()));
user = userAction.updateUser();
}catch(Exception e){
Events.instance().raiseEvent(Constants.ADD_ERROR_EVENT, Constants.UPDATE_USER_ERROR);
Added:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java
===================================================================
---
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java
(rev 0)
+++
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java 2009-04-30
11:32:18 UTC (rev 13937)
@@ -0,0 +1,22 @@
+package org.richfaces.photoalbum.util;
+
+import java.security.MessageDigest;
+
+import org.jboss.seam.util.Hex;
+
+public class HashUtils {
+ private static String digestAlgorithm = "SHA-1";
+
+ private static String charset = "UTF-8";
+
+ public static String hash(String plainTextPassword) {
+ try {
+ MessageDigest digest = MessageDigest.getInstance(digestAlgorithm);
+ digest.update(plainTextPassword.getBytes(charset));
+ byte[] rawHash = digest.digest();
+ return new String(Hex.encodeHex(rawHash));
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+}
Property changes on:
trunk/examples/photoalbum/source/web/src/main/java/org/richfaces/photoalbum/util/HashUtils.java
___________________________________________________________________
Name: svn:mime-type
+ text/plain
Name: svn:keywords
+ Author Id Revision Date
Name: svn:eol-style
+ native
Modified: trunk/examples/photoalbum/source/web/src/main/webapp/WEB-INF/components.xml
===================================================================
--- trunk/examples/photoalbum/source/web/src/main/webapp/WEB-INF/components.xml 2009-04-30
10:47:31 UTC (rev 13936)
+++ trunk/examples/photoalbum/source/web/src/main/webapp/WEB-INF/components.xml 2009-04-30
11:32:18 UTC (rev 13937)
@@ -30,7 +30,6 @@
persistence-unit-jndi-name="java:/photoalbumEntityManager"/>
<transaction:ejb-transaction/>
<security:identity
authenticate-method="#{authenticator.authenticate}"/>
- <component name="authenticator" digestAlgorithm="SHA-1"
charset="UTF-8"/>
<component name="org.jboss.seam.ui.entityConverter">
<property name="entityManager">#{em}</property>
</component>
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/image/imageEditInfo.xhtml
===================================================================
(Binary files differ)
Modified:
trunk/examples/photoalbum/source/web/src/main/webapp/includes/userPrefs/userPrefsEdit.xhtml
===================================================================
(Binary files differ)
Show replies by date