use of com.haulmont.cuba.web.security.ExternalUserCredentials in project cuba by cuba-platform.
the class IdpLoginLifecycleManager method onAppStarted.
@Order(Events.HIGHEST_PLATFORM_PRECEDENCE + 10)
@EventListener
protected void onAppStarted(AppStartedEvent event) throws LoginException {
Connection connection = event.getApp().getConnection();
// can be already authenticated by another event listener
if (webIdpConfig.getIdpEnabled() && !connection.isAuthenticated()) {
VaadinRequest currentRequest = VaadinService.getCurrentRequest();
if (currentRequest != null) {
Principal principal = currentRequest.getUserPrincipal();
if (principal instanceof IdpSessionPrincipal) {
IdpSession idpSession = ((IdpSessionPrincipal) principal).getIdpSession();
Locale locale = event.getApp().getLocale();
ExternalUserCredentials credentials = new ExternalUserCredentials(principal.getName(), locale);
credentials.setSessionAttributes(ImmutableMap.of(IdpService.IDP_USER_SESSION_ATTRIBUTE, idpSession.getId()));
connection.login(credentials);
}
}
}
}
use of com.haulmont.cuba.web.security.ExternalUserCredentials in project cuba by cuba-platform.
the class ExternalUserLoginProvider method login.
@Nullable
@Override
public AuthenticationDetails login(Credentials credentials) throws LoginException {
ExternalUserCredentials externalUserCredentials = (ExternalUserCredentials) credentials;
if (webAuthConfig.getStandardAuthenticationUsers().contains(externalUserCredentials.getLogin())) {
log.debug("User {} is not allowed to use external login");
return null;
}
TrustedClientCredentials tcCredentials = new TrustedClientCredentials(externalUserCredentials.getLogin(), webAuthConfig.getTrustedClientPassword(), externalUserCredentials.getLocale(), externalUserCredentials.getParams());
tcCredentials.setClientInfo(externalUserCredentials.getClientInfo());
tcCredentials.setClientType(ClientType.WEB);
tcCredentials.setIpAddress(externalUserCredentials.getIpAddress());
tcCredentials.setOverrideLocale(externalUserCredentials.isOverrideLocale());
tcCredentials.setSyncNewUserSessionReplication(externalUserCredentials.isSyncNewUserSessionReplication());
Map<String, Serializable> sessionAttributes = externalUserCredentials.getSessionAttributes();
Map<String, Serializable> targetSessionAttributes;
if (sessionAttributes != null && !sessionAttributes.isEmpty()) {
targetSessionAttributes = new HashMap<>(sessionAttributes);
targetSessionAttributes.put(EXTERNAL_AUTH_USER_SESSION_ATTRIBUTE, true);
} else {
targetSessionAttributes = ImmutableMap.of(EXTERNAL_AUTH_USER_SESSION_ATTRIBUTE, true);
}
tcCredentials.setSessionAttributes(targetSessionAttributes);
return loginMiddleware(tcCredentials);
}
Aggregations