use of org.springframework.security.authentication.dao.ReflectionSaltSource in project spring-security by spring-projects.
the class ReflectionSaltSourceTests method detectsMissingUserPropertyToUse.
// ~ Methods
// ========================================================================================================
@Test(expected = IllegalArgumentException.class)
public void detectsMissingUserPropertyToUse() throws Exception {
ReflectionSaltSource saltSource = new ReflectionSaltSource();
saltSource.afterPropertiesSet();
}
use of org.springframework.security.authentication.dao.ReflectionSaltSource in project spring-security by spring-projects.
the class ReflectionSaltSourceTests method methodNameAsPropertyToUseReturnsCorrectSaltValue.
@Test
public void methodNameAsPropertyToUseReturnsCorrectSaltValue() {
ReflectionSaltSource saltSource = new ReflectionSaltSource();
saltSource.setUserPropertyToUse("getUsername");
assertThat(saltSource.getSalt(user)).isEqualTo("scott");
}
use of org.springframework.security.authentication.dao.ReflectionSaltSource in project spring-security by spring-projects.
the class ReflectionSaltSourceTests method exceptionIsThrownWhenInvalidPropertyRequested.
@Test(expected = AuthenticationServiceException.class)
public void exceptionIsThrownWhenInvalidPropertyRequested() throws Exception {
ReflectionSaltSource saltSource = new ReflectionSaltSource();
saltSource.setUserPropertyToUse("getDoesNotExist");
saltSource.afterPropertiesSet();
saltSource.getSalt(user);
}
use of org.springframework.security.authentication.dao.ReflectionSaltSource in project ranger by apache.
the class RangerAuthenticationProvider method getJDBCAuthentication.
private Authentication getJDBCAuthentication(Authentication authentication, String encoder) throws AuthenticationException {
try {
ReflectionSaltSource saltSource = new ReflectionSaltSource();
saltSource.setUserPropertyToUse("username");
DaoAuthenticationProvider authenticator = new DaoAuthenticationProvider();
authenticator.setUserDetailsService(userDetailsService);
if (encoder != null && "SHA256".equalsIgnoreCase(encoder)) {
authenticator.setPasswordEncoder(new ShaPasswordEncoder(256));
} else if (encoder != null && "MD5".equalsIgnoreCase(encoder)) {
authenticator.setPasswordEncoder(new Md5PasswordEncoder());
}
authenticator.setSaltSource(saltSource);
String userName = "";
String userPassword = "";
if (authentication != null) {
userName = authentication.getName();
if (authentication.getCredentials() != null) {
userPassword = authentication.getCredentials().toString();
}
}
String rangerLdapDefaultRole = PropertiesUtil.getProperty("ranger.ldap.default.role", "ROLE_USER");
if (userName != null && userPassword != null && !userName.trim().isEmpty() && !userPassword.trim().isEmpty()) {
final List<GrantedAuthority> grantedAuths = new ArrayList<>();
grantedAuths.add(new SimpleGrantedAuthority(rangerLdapDefaultRole));
final UserDetails principal = new User(userName, userPassword, grantedAuths);
final Authentication finalAuthentication = new UsernamePasswordAuthenticationToken(principal, userPassword, grantedAuths);
authentication = authenticator.authenticate(finalAuthentication);
return authentication;
} else {
if (authentication != null && !authentication.isAuthenticated()) {
throw new BadCredentialsException("Bad credentials");
}
}
} catch (BadCredentialsException e) {
throw e;
} catch (AuthenticationServiceException e) {
throw e;
} catch (AuthenticationException e) {
throw e;
} catch (Exception e) {
throw e;
}
return authentication;
}
use of org.springframework.security.authentication.dao.ReflectionSaltSource in project spring-security by spring-projects.
the class ReflectionSaltSourceTests method propertyNameAsPropertyToUseReturnsCorrectSaltValue.
@Test
public void propertyNameAsPropertyToUseReturnsCorrectSaltValue() {
ReflectionSaltSource saltSource = new ReflectionSaltSource();
saltSource.setUserPropertyToUse("password");
assertThat(saltSource.getSalt(user)).isEqualTo("wombat");
}
Aggregations