You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@shiro.apache.org by lh...@apache.org on 2012/05/18 20:11:44 UTC
svn commit: r1340197 - in /shiro/trunk/core/src:
main/java/org/apache/shiro/authc/credential/PasswordMatcher.java
test/groovy/org/apache/shiro/authc/credential/PasswordMatcherTest.groovy
Author: lhazlewood
Date: Fri May 18 18:11:44 2012
New Revision: 1340197
URL: http://svn.apache.org/viewvc?rev=1340197&view=rev
Log:
SHIRO-363: merged fix from the 1.2.x branch into trunk
Modified:
shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/PasswordMatcher.java
shiro/trunk/core/src/test/groovy/org/apache/shiro/authc/credential/PasswordMatcherTest.groovy
Modified: shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/PasswordMatcher.java
URL: http://svn.apache.org/viewvc/shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/PasswordMatcher.java?rev=1340197&r1=1340196&r2=1340197&view=diff
==============================================================================
--- shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/PasswordMatcher.java (original)
+++ shiro/trunk/core/src/main/java/org/apache/shiro/authc/credential/PasswordMatcher.java Fri May 18 18:11:44 2012
@@ -92,7 +92,12 @@ public class PasswordMatcher implements
}
protected Object getStoredPassword(AuthenticationInfo storedAccountInfo) {
- return storedAccountInfo != null ? storedAccountInfo.getCredentials() : null;
+ Object stored = storedAccountInfo != null ? storedAccountInfo.getCredentials() : null;
+ //fix for https://issues.apache.org/jira/browse/SHIRO-363
+ if (stored instanceof char[]) {
+ stored = new String((char[])stored);
+ }
+ return stored;
}
public PasswordService getPasswordService() {
Modified: shiro/trunk/core/src/test/groovy/org/apache/shiro/authc/credential/PasswordMatcherTest.groovy
URL: http://svn.apache.org/viewvc/shiro/trunk/core/src/test/groovy/org/apache/shiro/authc/credential/PasswordMatcherTest.groovy?rev=1340197&r1=1340196&r2=1340197&view=diff
==============================================================================
--- shiro/trunk/core/src/test/groovy/org/apache/shiro/authc/credential/PasswordMatcherTest.groovy (original)
+++ shiro/trunk/core/src/test/groovy/org/apache/shiro/authc/credential/PasswordMatcherTest.groovy Fri May 18 18:11:44 2012
@@ -21,6 +21,7 @@ package org.apache.shiro.authc.credentia
import org.apache.shiro.authc.AuthenticationInfo
import org.apache.shiro.authc.AuthenticationToken
import org.apache.shiro.crypto.hash.Sha256Hash
+
import static org.easymock.EasyMock.*
/**
@@ -114,6 +115,34 @@ class PasswordMatcherTest extends Groovy
verify token, info, service
}
+ /**
+ * Asserts fix for https://issues.apache.org/jira/browse/SHIRO-363
+ */
+ void testCharArrayComparison() {
+ def service = createMock(PasswordService)
+ def token = createMock(AuthenticationToken)
+ def info = createMock(AuthenticationInfo)
+ //generate a stored password just for this test:
+ def submittedPassword = "foo"
+ def savedPasswordAsString = "foo";
+ def savedPassword = savedPasswordAsString.toCharArray()
+
+ expect(token.credentials).andReturn submittedPassword
+ expect(info.credentials).andReturn savedPassword
+
+ expect(service.passwordsMatch(eq(submittedPassword), eq(savedPasswordAsString))).andReturn true
+
+ replay token, info, service
+
+ def matcher = new PasswordMatcher()
+ matcher.passwordService = service
+ assertSame service, matcher.passwordService
+
+ assertTrue matcher.doCredentialsMatch(token, info)
+
+ verify token, info, service
+ }
+
void testUnexpectedSavedCredentialsType() {
def service = createMock(HashingPasswordService)
def token = createMock(AuthenticationToken)