Search in sources :

Example 6 with ShaPasswordEncoder

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();
}
Also used : EhCacheBasedUserCache(org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache) ShaPasswordEncoder(org.springframework.security.authentication.encoding.ShaPasswordEncoder) Test(org.junit.Test)

Example 7 with ShaPasswordEncoder

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");
}
Also used : ShaPasswordEncoder(org.springframework.security.authentication.encoding.ShaPasswordEncoder) Test(org.junit.Test)

Example 8 with ShaPasswordEncoder

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();
}
Also used : ShaPasswordEncoder(org.springframework.security.authentication.encoding.ShaPasswordEncoder) Test(org.junit.Test)

Example 9 with ShaPasswordEncoder

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;
}
Also used : ShaPasswordEncoder(org.springframework.security.authentication.encoding.ShaPasswordEncoder) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Example 10 with ShaPasswordEncoder

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;
}
Also used : ShaPasswordEncoder(org.springframework.security.authentication.encoding.ShaPasswordEncoder) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap)

Aggregations

ShaPasswordEncoder (org.springframework.security.authentication.encoding.ShaPasswordEncoder)11 Test (org.junit.Test)5 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2 Student (ba.isss.models.Student)1 URL (java.net.URL)1 Calendar (java.util.Calendar)1 Date (java.util.Date)1 FormLayoutMedia (org.akaza.openclinica.domain.datamap.FormLayoutMedia)1 HttpEntity (org.springframework.http.HttpEntity)1 HttpHeaders (org.springframework.http.HttpHeaders)1 PreAuthorize (org.springframework.security.access.prepost.PreAuthorize)1 EhCacheBasedUserCache (org.springframework.security.core.userdetails.cache.EhCacheBasedUserCache)1 RestTemplate (org.springframework.web.client.RestTemplate)1