use of org.springframework.security.authentication.encoding.Md5PasswordEncoder 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.encoding.Md5PasswordEncoder in project commons-dao by reportportal.
the class HashFuctionTest method checkHashFunction.
@Test
public void checkHashFunction() {
String testPassword = "value to encode";
EncodePasswordTrigger trigger = new EncodePasswordTrigger();
User user = new User();
user.setPassword(testPassword);
trigger.onBeforeConvert(new BeforeConvertEvent<>(user, null));
Assert.assertEquals(user.getPassword(), new Md5PasswordEncoder().encodePassword(testPassword, null));
}
use of org.springframework.security.authentication.encoding.Md5PasswordEncoder in project paascloud-master by paascloud.
the class MD5Test method md5_SystemWideSaltSource.
/**
* Md 5 system wide salt source.
*/
private static void md5_SystemWideSaltSource() {
Md5PasswordEncoder md5 = new Md5PasswordEncoder();
md5.setEncodeHashAsBase64(false);
// 使用动态加密盐的只需要在注册用户的时候将第二个参数换成用户名即可
String pwd = md5.encodePassword("123456", "acegisalt");
log.info("MD5 SystemWideSaltSource: " + pwd + " len=" + pwd.length());
}
use of org.springframework.security.authentication.encoding.Md5PasswordEncoder in project paascloud-master by paascloud.
the class MD5Test method md5.
/**
* Md 5.
*/
private static void md5() {
Md5PasswordEncoder md5 = new Md5PasswordEncoder();
// false 表示:生成32位的Hex版, 这也是encodeHashAsBase64的, Acegi 默认配置; true 表示:生成24位的Base64版
md5.setEncodeHashAsBase64(false);
String pwd = md5.encodePassword("123456", null);
log.info("MD5: " + pwd + " len=" + pwd.length());
}
Aggregations