}
@Override
protected AuthenticationInfo doGetAuthenticationInfo(final AuthenticationToken token) throws AuthenticationException {
final String rutUserId = token.getPrincipal().toString();
final SimplePrincipalCollection principals = new SimplePrincipalCollection();
final List<String> configuredRealms = securitySystem.getRealms();
for (UserManager userManager : userManagers) {
if (configuredRealms.contains(userManager.getAuthenticationRealmName())) {
try {
final User user = userManager.getUser(rutUserId);
principals.add(user.getUserId(), userManager.getAuthenticationRealmName());
}
catch (UserNotFoundException e) {
// ignore and continue searching
}
}
}
if (!principals.isEmpty()) {
log.debug("Found principals for RUT user '{}': '{}' from realms '{}'", rutUserId, principals,
principals.getRealmNames());
// make RUT the primary one, but keep all the found ones too
final SimplePrincipalCollection principalCollection = new SimplePrincipalCollection(token.getPrincipal(), getName());
principalCollection.addAll(principals);
return new SimpleAuthenticationInfo(principalCollection, null);
}
log.debug("No found principals for RUT user '{}'", rutUserId);
return null;
}