move and rename password encoding classes.

change saltSource arument to salt argument, which impl may or may not use.
This commit is contained in:
Colin Sampaleanu
2004-04-16 03:44:04 +00:00
parent 5d9d734735
commit 3d089aaa67
13 changed files with 415 additions and 70 deletions

View File

@@ -37,7 +37,6 @@ import org.springframework.dao.DataRetrievalFailureException;
* @version $Id$
*/
public class DaoAuthenticationProviderTests extends TestCase {
//~ Methods ================================================================
public final void setUp() throws Exception {

View File

@@ -12,10 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.acegisecurity.providers.dao;
import junit.framework.TestCase;
import net.sf.acegisecurity.providers.encoding.*;
/**
* <p>
* TestCase for PlaintextPasswordEncoder.
@@ -25,23 +29,22 @@ import junit.framework.TestCase;
* @version $Id$
*/
public class MD5PasswordEncoderTest extends TestCase {
//~ Methods ================================================================
public void testBasicFunctionality() {
MD5PasswordEncoder pe = new MD5PasswordEncoder();
String raw = "abc123";
String badRaw = "abc321";
String encoded = pe.encodePassword(raw, null); // no SALT source
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
assertTrue(encoded.length() == 32);
// now try Base64
pe.setEncodeHashAsBase64(true);
encoded = pe.encodePassword(raw, null); // no SALT source
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
assertTrue(encoded.length() != 32);
}
public void testBasicFunctionality() {
Md5PasswordEncoder pe = new Md5PasswordEncoder();
String raw = "abc123";
String badRaw = "abc321";
String encoded = pe.encodePassword(raw, null); // no SALT source
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
assertTrue(encoded.length() == 32);
// now try Base64
pe.setEncodeHashAsBase64(true);
encoded = pe.encodePassword(raw, null); // no SALT source
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
assertTrue(encoded.length() != 32);
}
}

View File

@@ -12,10 +12,14 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.acegisecurity.providers.dao;
import junit.framework.TestCase;
import net.sf.acegisecurity.providers.encoding.*;
/**
* <p>
* TestCase for PlaintextPasswordEncoder.
@@ -25,35 +29,36 @@ import junit.framework.TestCase;
* @version $Id$
*/
public class PlaintextPasswordEncoderTest extends TestCase {
//~ Methods ================================================================
public void testBasicFunctionality() {
PlaintextPasswordEncoder pe = new PlaintextPasswordEncoder();
public void testBasicFunctionality() {
PlaintextPasswordEncoder pe = new PlaintextPasswordEncoder();
String raw = "abc123";
String rawDiffCase = "AbC123";
String badRaw = "abc321";
// should be able to validate even without encoding
String encoded = raw;
assertTrue(pe.isPasswordValid(encoded, raw, null)); // no SALT source
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
String raw = "abc123";
String rawDiffCase = "AbC123";
String badRaw = "abc321";
// now make sure encoded version it gives us back is comparable as well
encoded = pe.encodePassword(raw, null);
assertTrue(pe.isPasswordValid(encoded, raw, null)); // no SALT source
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
// make sure default is not to ignore password case
encoded = pe.encodePassword(rawDiffCase, null);
assertFalse(pe.isPasswordValid(encoded, raw, null));
// now check for ignore password case
pe = new PlaintextPasswordEncoder();
pe.setIgnorePasswordCase(true);
// should be able to validate even without encoding
String encoded = raw;
assertTrue(pe.isPasswordValid(encoded, raw, null)); // no SALT source
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
// should be able to validate even without encoding
encoded = pe.encodePassword(rawDiffCase, null);
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
}
// now make sure encoded version it gives us back is comparable as well
encoded = pe.encodePassword(raw, null);
assertTrue(pe.isPasswordValid(encoded, raw, null)); // no SALT source
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
}
// make sure default is not to ignore password case
encoded = pe.encodePassword(rawDiffCase, null);
assertFalse(pe.isPasswordValid(encoded, raw, null));
// now check for ignore password case
pe = new PlaintextPasswordEncoder();
pe.setIgnorePasswordCase(true);
// should be able to validate even without encoding
encoded = pe.encodePassword(rawDiffCase, null);
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
}
}

View File

@@ -12,36 +12,39 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package net.sf.acegisecurity.providers.dao;
import junit.framework.TestCase;
import net.sf.acegisecurity.providers.encoding.*;
/**
* <p>
* TestCase for SHAPasswordEncoder.
* TestCase for ShaPasswordEncoder.
* </p>
*
* @author colin sampaleanu
* @version $Id$
*/
public class SHAPasswordEncoderTest extends TestCase {
//~ Methods ================================================================
public void testBasicFunctionality() {
SHAPasswordEncoder pe = new SHAPasswordEncoder();
String raw = "abc123";
String badRaw = "abc321";
String encoded = pe.encodePassword(raw, null); // no SALT source
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
assertTrue(encoded.length() == 40);
// now try Base64
pe.setEncodeHashAsBase64(true);
encoded = pe.encodePassword(raw, null); // no SALT source
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
assertTrue(encoded.length() != 40);
}
public void testBasicFunctionality() {
ShaPasswordEncoder pe = new ShaPasswordEncoder();
String raw = "abc123";
String badRaw = "abc321";
String encoded = pe.encodePassword(raw, null); // no SALT source
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
assertTrue(encoded.length() == 40);
// now try Base64
pe.setEncodeHashAsBase64(true);
encoded = pe.encodePassword(raw, null); // no SALT source
assertTrue(pe.isPasswordValid(encoded, raw, null));
assertFalse(pe.isPasswordValid(encoded, badRaw, null));
assertTrue(encoded.length() != 40);
}
}