/**
*
* @param authentication
* @return Authentication
*/
@Override
public Authentication authenticate(Authentication authentication) {
Realm realm;
Set<GrantedAuthority> auths = new HashSet<>();
try {
realm = getTomcatContextRealm();
if(realm instanceof NullRealm) {
throw new ProviderNotFoundException("No Realms configured for Jwala to Authenticate");
}
Principal principal = realm.authenticate(authentication.getName(),
authentication.getCredentials().toString());
if (principal == null) {
throw new BadCredentialsException("Username or Password not found.");
} else {
if (principal instanceof GenericPrincipal) {
String[] roles = ((GenericPrincipal) principal).getRoles();
for (String role : roles) {
auths.add(new SimpleGrantedAuthority(role));
}
}
GrantedAuthoritiesMapperImpl grantedAuthoritiesMapper = new GrantedAuthoritiesMapperImpl();
return new UsernamePasswordAuthenticationToken(authentication.getName(),
authentication.getCredentials(), grantedAuthoritiesMapper.mapAuthorities(auths));
}
} catch (AttributeNotFoundException | InstanceNotFoundException | MBeanException | ReflectionException e) {
LOGGER.error("Error getting realms", e);
throw new ProviderNotFoundException(e.getMessage());
}
}
JwalaAuthenticationProvider.java 文件源码
java
阅读 26
收藏 0
点赞 0
评论 0
项目:jwala
作者:
评论列表
文章目录