Search in sources :

Example 1 with ExternalUserCredentials

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);
            }
        }
    }
}
Also used : Locale(java.util.Locale) ExternalUserCredentials(com.haulmont.cuba.web.security.ExternalUserCredentials) Connection(com.haulmont.cuba.web.Connection) IdpSession(com.haulmont.cuba.security.global.IdpSession) VaadinRequest(com.vaadin.server.VaadinRequest) Principal(java.security.Principal) Order(org.springframework.core.annotation.Order) EventListener(org.springframework.context.event.EventListener)

Example 2 with ExternalUserCredentials

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);
}
Also used : ExternalUserCredentials(com.haulmont.cuba.web.security.ExternalUserCredentials) Serializable(java.io.Serializable) TrustedClientCredentials(com.haulmont.cuba.security.auth.TrustedClientCredentials) Nullable(javax.annotation.Nullable)

Aggregations

ExternalUserCredentials (com.haulmont.cuba.web.security.ExternalUserCredentials)2 TrustedClientCredentials (com.haulmont.cuba.security.auth.TrustedClientCredentials)1 IdpSession (com.haulmont.cuba.security.global.IdpSession)1 Connection (com.haulmont.cuba.web.Connection)1 VaadinRequest (com.vaadin.server.VaadinRequest)1 Serializable (java.io.Serializable)1 Principal (java.security.Principal)1 Locale (java.util.Locale)1 Nullable (javax.annotation.Nullable)1 EventListener (org.springframework.context.event.EventListener)1 Order (org.springframework.core.annotation.Order)1