Interface UserResolver
public interface UserResolver
Maps a proven identity onto the application's user entity.
This is the application-specific counterpart of the AuthenticationProvider: the provider
proves who the caller is, the resolver decides which user of this application
that is, by setting Authentication.setUserId(long) and
Authentication.setUserClassId(int).
The resolver is optional and only consulted when the provider chain left the user id at zero, which is the normal case for a generic single sign-on provider that only knows a token's subject. The built-in password provider found the user entity anyway and sets the ids itself.
@Service(UserResolver.class)
public class MyUserResolver implements UserResolver {
@Override
public void resolveUser(Authentication authentication) {
DomainContext context = Pdo.createDomainContext(Session.getSession());
User user = Pdo.create(User.class, context).selectByUniqueDomainKey(authentication.getName());
if (user == null || !user.isLoginAllowed()) {
throw new AuthenticationException("login refused");
}
authentication.setUserId(user.getId());
authentication.setUserClassId(user.getClassId());
}
}
- Author:
- harald
-
Method Summary
Modifier and TypeMethodDescriptionstatic UserResolverGets the optional application-specific user resolver singleton.voidresolveUser(Authentication authentication) Resolves the application's user for a proven identity.
-
Method Details
-
getInstance
Gets the optional application-specific user resolver singleton.- Returns:
- the resolver, null if no
@Service(UserResolver.class)configured
-
resolveUser
Resolves the application's user for a proven identity.Implementations set the user id and the user class id on the given authentication. The invocation runs on the server, within the freshly opened session, so the persistence layer is available.
- Parameters:
authentication- the proven identity- Throws:
LoginFailedException- if there is no such user or the login must be refused
-