本文整理汇总了Java中org.apache.catalina.realm.NullRealm类的典型用法代码示例。如果您正苦于以下问题:Java NullRealm类的具体用法?Java NullRealm怎么用?Java NullRealm使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NullRealm类属于org.apache.catalina.realm包,在下文中一共展示了NullRealm类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import org.apache.catalina.realm.NullRealm; //导入依赖的package包/类
/**
*
* @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());
}
}