use of com.haulmont.cuba.security.entity.RememberMeToken in project cuba by cuba-platform.
the class RememberMeAuthenticationProvider method loadRememberMeToken.
@Nullable
protected RememberMeToken loadRememberMeToken(User user, String rememberMeToken) {
EntityManager em = persistence.getEntityManager();
TypedQuery<RememberMeToken> query = em.createQuery("select rt from sec$RememberMeToken rt where rt.token = :token and rt.user.id = :userId", RememberMeToken.class);
query.setParameter("token", rememberMeToken);
query.setParameter("userId", user.getId());
return query.getFirstResult();
}
use of com.haulmont.cuba.security.entity.RememberMeToken in project cuba by cuba-platform.
the class RememberMeAuthenticationProvider method authenticate.
@Override
public AuthenticationDetails authenticate(Credentials credentials) throws LoginException {
RememberMeCredentials rememberMe = (RememberMeCredentials) credentials;
String login = rememberMe.getLogin();
Locale credentialsLocale = rememberMe.getLocale() == null ? messages.getTools().getDefaultLocale() : rememberMe.getLocale();
if (Strings.isNullOrEmpty(login)) {
// empty login is not valid
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
checkUserCredentials(credentials);
User user = loadUser(login);
if (user == null) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
RememberMeToken loginToken = loadRememberMeToken(user, rememberMe.getRememberMeToken());
if (loginToken == null) {
throw new LoginException(getInvalidCredentialsMessage(login, credentialsLocale));
}
Locale userLocale = getUserLocale(rememberMe, user);
UserSession session = createSession(rememberMe, user, userLocale);
setClientSessionParams(rememberMe, session);
AuthenticationDetails authenticationDetails = new SimpleAuthenticationDetails(session);
checkUserAccess(rememberMe, authenticationDetails);
return authenticationDetails;
}
Aggregations