use of org.springframework.security.authentication.encoding.PasswordEncoder in project spring-security by spring-projects.
the class PasswordComparisonAuthenticator method setPasswordEncoder.
public void setPasswordEncoder(Object passwordEncoder) {
if (passwordEncoder instanceof PasswordEncoder) {
this.usePasswordAttrCompare = false;
setPasswordEncoder((PasswordEncoder) passwordEncoder);
return;
}
if (passwordEncoder instanceof org.springframework.security.crypto.password.PasswordEncoder) {
final org.springframework.security.crypto.password.PasswordEncoder delegate = (org.springframework.security.crypto.password.PasswordEncoder) passwordEncoder;
setPasswordEncoder(new PasswordEncoder() {
public String encodePassword(String rawPass, Object salt) {
checkSalt(salt);
return delegate.encode(rawPass);
}
public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
checkSalt(salt);
return delegate.matches(rawPass, encPass);
}
private void checkSalt(Object salt) {
Assert.isNull(salt, "Salt value must be null when used with crypto module PasswordEncoder");
}
});
this.usePasswordAttrCompare = true;
return;
}
throw new IllegalArgumentException("passwordEncoder must be a PasswordEncoder instance");
}
use of org.springframework.security.authentication.encoding.PasswordEncoder in project spring-security by spring-projects.
the class DaoAuthenticationProvider method setPasswordEncoder.
/**
* Sets the PasswordEncoder instance to be used to encode and validate passwords. If
* not set, the password will be compared as plain text.
* <p>
* For systems which are already using salted password which are encoded with a
* previous release, the encoder should be of type
* {@code org.springframework.security.authentication.encoding.PasswordEncoder}.
* Otherwise, the recommended approach is to use
* {@code org.springframework.security.crypto.password.PasswordEncoder}.
*
* @param passwordEncoder must be an instance of one of the {@code PasswordEncoder}
* types.
*/
public void setPasswordEncoder(Object passwordEncoder) {
Assert.notNull(passwordEncoder, "passwordEncoder cannot be null");
if (passwordEncoder instanceof PasswordEncoder) {
setPasswordEncoder((PasswordEncoder) passwordEncoder);
return;
}
if (passwordEncoder instanceof org.springframework.security.crypto.password.PasswordEncoder) {
final org.springframework.security.crypto.password.PasswordEncoder delegate = (org.springframework.security.crypto.password.PasswordEncoder) passwordEncoder;
setPasswordEncoder(new PasswordEncoder() {
public String encodePassword(String rawPass, Object salt) {
checkSalt(salt);
return delegate.encode(rawPass);
}
public boolean isPasswordValid(String encPass, String rawPass, Object salt) {
checkSalt(salt);
return delegate.matches(rawPass, encPass);
}
private void checkSalt(Object salt) {
Assert.isNull(salt, "Salt value must be null when used with crypto module PasswordEncoder");
}
});
return;
}
throw new IllegalArgumentException("passwordEncoder must be a PasswordEncoder instance");
}
use of org.springframework.security.authentication.encoding.PasswordEncoder in project pentaho-platform by pentaho.
the class SpringSecurityHibernateConfigTest method testGetPasswordEncoder.
@Test
public void testGetPasswordEncoder() throws Exception {
config = new SpringSecurityHibernateConfig(document);
Node node = mock(Node.class);
when(node.getText()).thenReturn(DefaultPentahoPasswordEncoder.class.getName());
when(document.selectSingleNode(anyString())).thenReturn(node);
PasswordEncoder passwordEncoder = config.getPasswordEncoder();
assertTrue(passwordEncoder instanceof DefaultPentahoPasswordEncoder);
}
use of org.springframework.security.authentication.encoding.PasswordEncoder in project pentaho-platform by pentaho.
the class SpringSecurityHibernateConfigTest method testGetPasswordEncoder_ClassNotFound.
@Test
public void testGetPasswordEncoder_ClassNotFound() throws Exception {
config = new SpringSecurityHibernateConfig(document);
Node node = mock(Node.class);
when(node.getText()).thenReturn("org.pentaho.ClassNotFoundEncoder");
when(document.selectSingleNode(anyString())).thenReturn(node);
PasswordEncoder passwordEncoder = config.getPasswordEncoder();
assertNull(passwordEncoder);
}
use of org.springframework.security.authentication.encoding.PasswordEncoder in project pentaho-platform by pentaho.
the class AppConfigPropertiesTest method testGetPasswordEncoder.
@Test
public void testGetPasswordEncoder() throws Exception {
SpringSecurityHibernateConfig springSecurityConfig = mock(SpringSecurityHibernateConfig.class);
doReturn(springSecurityConfig).when(spyAppConfigProperties).getSpringSecurityHibernateConfig();
PasswordEncoder pwdEncoder = mock(PasswordEncoder.class);
when(springSecurityConfig.getPasswordEncoder()).thenReturn(pwdEncoder);
PasswordEncoder passwordEncoder = spyAppConfigProperties.getPasswordEncoder();
verify(springSecurityConfig).getPasswordEncoder();
assertEquals(pwdEncoder, passwordEncoder);
}
Aggregations