use of com.haulmont.cuba.security.auth.AuthenticationDetails in project cuba by cuba-platform.
the class IdpServiceBean method login.
@Nonnull
@Override
public IdpLoginResult login(String login, String password, Locale locale, @Nullable Map<String, Object> parameters) throws LoginException {
log.debug("Authenticating CUBA user for IDP");
LoginPasswordCredentials credentials = new LoginPasswordCredentials(login, password, locale, parameters);
AuthenticationDetails sessionDetails = authenticationManager.authenticate(credentials);
User user = sessionDetails.getSession().getUser();
IdpSession session = new IdpSession(createIdpSessionId());
session.setLogin(user.getLogin());
session.setEmail(user.getEmail());
Locale userLocale = locale;
if (user.getLanguage() != null && !globalConfig.getLocaleSelectVisible()) {
userLocale = LocaleUtils.toLocale(user.getLanguage());
}
session.setLocale(userLocale.toLanguageTag());
String serviceProviderTicket = sessionStore.putSession(session);
return new IdpLoginResult(session.getId(), serviceProviderTicket);
}
use of com.haulmont.cuba.security.auth.AuthenticationDetails in project cuba by cuba-platform.
the class ConnectionImpl method loginInternal.
protected AuthenticationDetails loginInternal(Credentials credentials) throws LoginException {
Class<? extends Credentials> credentialsClass = credentials.getClass();
AuthenticationDetails details = null;
try {
publishBeforeLoginEvent(credentials);
List<LoginProvider> providers = getProviders();
for (LoginProvider provider : providers) {
if (!provider.supports(credentialsClass)) {
continue;
}
log.trace("Login attempt using {}", provider.getClass().getName());
try {
details = provider.login(credentials);
if (details != null) {
log.trace("Login successful for {}", credentials);
// publish login success
publishUserSessionStartedEvent(credentials, details);
return details;
}
} catch (LoginException e) {
// publish auth fail
publishLoginFailed(credentials, provider, e);
throw e;
} catch (RuntimeException re) {
InternalAuthenticationException ie = new InternalAuthenticationException("Exception is thrown by login provider", re);
// publish auth fail
publishLoginFailed(credentials, provider, ie);
throw ie;
}
}
} finally {
publishAfterLoginEvent(credentials, details);
}
throw new UnsupportedCredentialsException("Unable to find login provider that supports credentials class " + credentialsClass.getName());
}
use of com.haulmont.cuba.security.auth.AuthenticationDetails in project cuba by cuba-platform.
the class ConnectionImpl method login.
@Override
public void login(Credentials credentials) throws LoginException {
backgroundWorker.checkUIAccess();
preprocessCredentials(credentials);
AuthenticationDetails authenticationDetails = loginInternal(credentials);
ClientUserSession clientUserSession = createSession(authenticationDetails.getSession());
if (credentials instanceof AnonymousUserCredentials) {
clientUserSession.setAuthenticated(false);
} else {
clientUserSession.setAuthenticated(true);
}
UserSession previousSession = getSession();
setSessionInternal(clientUserSession);
publishUserConnectedEvent(credentials);
fireStateChangeListeners(previousSession, clientUserSession);
}
Aggregations