[jboss-svn-commits] JBL Code SVN: r11321 - labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Tue Apr 24 18:28:42 EDT 2007
Author: sohil.shah at jboss.com
Date: 2007-04-24 18:28:42 -0400 (Tue, 24 Apr 2007)
New Revision: 11321
Modified:
labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security/JBossCorpIdentityProvider.java
labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security/Tools.java
Log:
small bug to deal with user data migration from Nukes
Modified: labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security/JBossCorpIdentityProvider.java
===================================================================
--- labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security/JBossCorpIdentityProvider.java 2007-04-24 21:38:24 UTC (rev 11320)
+++ labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security/JBossCorpIdentityProvider.java 2007-04-24 22:28:42 UTC (rev 11321)
@@ -725,6 +725,41 @@
}
return identities;
}
+
+ /**
+ * Checks if the specified username should be successfully authenticated using the specified password
+ *
+ * @param username
+ * @param password
+ * @return
+ * @throws IdentityException
+ */
+ public boolean login(String username, byte[] password) throws IdentityException
+ {
+ try
+ {
+ boolean loginSuccess = false;
+
+ Identity identity = this.read(username);
+
+ String storedPassword = new String(identity.getPassword());
+ String inputPassword = new String(Tools.getEncodedPassword(new String(password),"MD5"));
+ String nukesPassword = new String(org.jboss.website.security.Tools.md5AsHexString(new String(password)));
+ if(identity.isActive()
+ &&
+ (storedPassword.equalsIgnoreCase(inputPassword) || storedPassword.equalsIgnoreCase(nukesPassword))
+ )
+ {
+ loginSuccess = true;
+ }
+
+ return loginSuccess;
+ }
+ catch(Exception e)
+ {
+ throw new IdentityException(e);
+ }
+ }
//-----private internal implementation-------------------------------------------------------------------------------------------------------------
/**
*
Modified: labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security/Tools.java
===================================================================
--- labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security/Tools.java 2007-04-24 21:38:24 UTC (rev 11320)
+++ labs/jbosslabs/branches/identity_integration/trunk/portal-extensions/jbwebsite-security/src/java/org/jboss/website/security/Tools.java 2007-04-24 22:28:42 UTC (rev 11321)
@@ -8,7 +8,10 @@
import java.util.Collection;
import java.util.Iterator;
import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import org.apache.log4j.Logger;
+
//jboss-identity-management framework
import org.jboss.security.idm.LoginProvider;
import org.jboss.security.idm.IdentityManager;
@@ -26,6 +29,11 @@
*/
public class Tools
{
+ /**
+ *
+ */
+ private static Logger log = Logger.getLogger(Tools.class);
+
public static String getEncodedPassword(String clearPassword) throws Exception
{
byte[] md5Hash = null;
@@ -112,4 +120,58 @@
}
}
}
+
+ /**
+ * Computes an md5 hash of a string.
+ * @param text the hashed string
+ * @return the string hash
+ * @exception NullPointerException if text is null
+ */
+ public static byte[] md5(String text)
+ {
+ // arguments check
+ if (text == null)
+ {
+ throw new NullPointerException("null text");
+ }
+
+ try
+ {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ md.update(text.getBytes());
+ return md.digest();
+ }
+ catch (NoSuchAlgorithmException e)
+ {
+ log.error("Cannot find MD5 algorithm", e);
+ throw new RuntimeException("Cannot find MD5 algorithm");
+ }
+ }
+
+ /**
+ * Computes an md5 hash and returns the result as a string in hexadecimal format.
+ * @param text the hashed string
+ * @return the string hash
+ * @exception NullPointerException if text is null
+ */
+ public static String md5AsHexString(String text)
+ {
+ return toHexString(md5(text));
+ }
+
+ /**
+ * Returns a string in the hexadecimal format.
+ * @param bytes the converted bytes
+ * @return the hexadecimal string representing the bytes data
+ */
+ public static String toHexString(byte[] bytes)
+ {
+ StringBuffer hex = new StringBuffer();
+ for (int i = 0;i < bytes.length;i++)
+ {
+ hex.append(Character.forDigit((bytes[i] & 0XF0) >> 4, 16));
+ hex.append(Character.forDigit((bytes[i] & 0X0F), 16));
+ }
+ return hex.toString();
+ }
}
More information about the jboss-svn-commits
mailing list