use of org.springframework.security.authentication.encoding.ShaPasswordEncoder in project spring-security by spring-projects.
the class DaoAuthenticationProviderTests method testGettersSetters.
@Test
public void testGettersSetters() {
DaoAuthenticationProvider provider = new DaoAuthenticationProvider();
provider.setPasswordEncoder(new ShaPasswordEncoder());
assertThat(provider.getPasswordEncoder().getClass()).isEqualTo(ShaPasswordEncoder.class);
provider.setSaltSource(new SystemWideSaltSource());
assertThat(provider.getSaltSource().getClass()).isEqualTo(SystemWideSaltSource.class);
provider.setUserCache(new EhCacheBasedUserCache());
assertThat(provider.getUserCache().getClass()).isEqualTo(EhCacheBasedUserCache.class);
assertThat(provider.isForcePrincipalAsString()).isFalse();
provider.setForcePrincipalAsString(true);
assertThat(provider.isForcePrincipalAsString()).isTrue();
}
use of org.springframework.security.authentication.encoding.ShaPasswordEncoder in project spring-security by spring-projects.
the class ShaPasswordEncoderTests method testBasicFunctionality.
// ~ Methods
// ========================================================================================================
@Test
public void testBasicFunctionality() {
ShaPasswordEncoder pe = new ShaPasswordEncoder();
String raw = "abc123";
String badRaw = "abc321";
String salt = "THIS_IS_A_SALT";
String encoded = pe.encodePassword(raw, salt);
assertThat(pe.isPasswordValid(encoded, raw, salt)).isTrue();
assertThat(pe.isPasswordValid(encoded, badRaw, salt)).isFalse();
assertThat(encoded).isEqualTo("b2f50ffcbd3407fe9415c062d55f54731f340d32");
}
use of org.springframework.security.authentication.encoding.ShaPasswordEncoder in project spring-security by spring-projects.
the class ShaPasswordEncoderTests method testBase64.
@Test
public void testBase64() throws Exception {
ShaPasswordEncoder pe = new ShaPasswordEncoder();
pe.setEncodeHashAsBase64(true);
String raw = "abc123";
String badRaw = "abc321";
String salt = "THIS_IS_A_SALT";
String encoded = pe.encodePassword(raw, salt);
assertThat(pe.isPasswordValid(encoded, raw, salt)).isTrue();
assertThat(pe.isPasswordValid(encoded, badRaw, salt)).isFalse();
assertThat(encoded.length() != 40).isTrue();
}
use of org.springframework.security.authentication.encoding.ShaPasswordEncoder in project OpenClinica by OpenClinica.
the class PFormCache method putSubjectContext.
public String putSubjectContext(String studySubjectOID, String studyEventDefinitionID, String studyEventOrdinal, String formLayoutOID, String userAccountID) {
HashMap<String, String> contextMap = new HashMap<String, String>();
contextMap.put("studySubjectOID", studySubjectOID);
contextMap.put("studyEventDefinitionID", studyEventDefinitionID);
contextMap.put("studyEventOrdinal", studyEventOrdinal);
contextMap.put("formLayoutOID", formLayoutOID);
contextMap.put("userAccountID", userAccountID);
String hashString = studySubjectOID + "." + studyEventDefinitionID + "." + studyEventOrdinal + "." + formLayoutOID;
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String hashOutput = encoder.encodePassword(hashString, null);
subjectContextCache.remove(hashOutput);
subjectContextCache.put(hashOutput, contextMap);
return hashOutput;
}
use of org.springframework.security.authentication.encoding.ShaPasswordEncoder in project OpenClinica by OpenClinica.
the class PFormCache method putAnonymousFormContext.
public String putAnonymousFormContext(String studyOID, String formLayoutOID, int studyEventDefinitionId) {
HashMap<String, String> contextMap = new HashMap<String, String>();
contextMap.put("studySubjectOID", null);
contextMap.put("studyOID", studyOID);
contextMap.put("formLayoutOID", formLayoutOID);
contextMap.put("studyEventDefinitionID", String.valueOf(studyEventDefinitionId));
contextMap.put("studyEventOrdinal", "1");
String hashString = studyOID + "." + formLayoutOID;
ShaPasswordEncoder encoder = new ShaPasswordEncoder(256);
String hashOutput = encoder.encodePassword(hashString, null);
subjectContextCache.put(hashOutput, contextMap);
return hashOutput;
}
Aggregations