Search in sources :

Example 6 with Auth

use of org.platformlayer.auth.v1.Auth in project sonarqube by SonarSource.

the class SamlIdentityProvider method callback.

@Override
public void callback(CallbackContext context) {
    // 
    // Workaround for onelogin/java-saml validation not taking into account running a reverse proxy configuration. This change
    // makes the validation take into account 'X-Forwarded-Proto' and 'Host' headers set by the reverse proxy
    // More details here:
    // - https://github.com/onelogin/java-saml/issues/198
    // - https://github.com/onelogin/java-saml/issues/95
    // 
    HttpServletRequest processedRequest = useProxyHeadersInRequest(context.getRequest());
    Auth auth = newAuth(initSettings(null), processedRequest, context.getResponse());
    processResponse(auth);
    context.verifyCsrfState(STATE_REQUEST_PARAMETER);
    LOGGER.trace("Name ID : {}", auth.getNameId());
    checkAuthentication(auth);
    samlMessageIdChecker.check(auth);
    LOGGER.trace("Attributes received : {}", auth.getAttributes());
    String login = getNonNullFirstAttribute(auth, samlSettings.getUserLogin());
    UserIdentity.Builder userIdentityBuilder = UserIdentity.builder().setProviderLogin(login).setName(getNonNullFirstAttribute(auth, samlSettings.getUserName()));
    samlSettings.getUserEmail().ifPresent(email -> userIdentityBuilder.setEmail(getFirstAttribute(auth, email)));
    samlSettings.getGroupName().ifPresent(group -> userIdentityBuilder.setGroups(getGroups(auth, group)));
    context.authenticate(userIdentityBuilder.build());
    context.redirectToRequestedPage();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) Auth(com.onelogin.saml2.Auth) UserIdentity(org.sonar.api.server.authentication.UserIdentity)

Aggregations

AuthenticateResponse (org.platformlayer.auth.v1.AuthenticateResponse)3 RestClientException (org.platformlayer.rest.RestClientException)3 Auth (com.onelogin.saml2.Auth)2 PlatformlayerAuthenticationClientException (org.platformlayer.auth.PlatformlayerAuthenticationClientException)2 PlatformlayerAuthenticationToken (org.platformlayer.auth.PlatformlayerAuthenticationToken)2 Auth (org.platformlayer.auth.v1.Auth)2 AuthenticateRequest (org.platformlayer.auth.v1.AuthenticateRequest)2 SimpleClientCertificateKeyManager (com.fathomdb.crypto.SimpleClientCertificateKeyManager)1 SettingsException (com.onelogin.saml2.exception.SettingsException)1 IOException (java.io.IOException)1 X509Certificate (java.security.cert.X509Certificate)1 KeyManager (javax.net.ssl.KeyManager)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 PlatformlayerInvalidCredentialsException (org.platformlayer.auth.PlatformlayerInvalidCredentialsException)1 CertificateCredentials (org.platformlayer.auth.v1.CertificateCredentials)1 PasswordCredentials (org.platformlayer.auth.v1.PasswordCredentials)1 SignCertificateRequest (org.platformlayer.auth.v1.SignCertificateRequest)1 SignCertificateResponse (org.platformlayer.auth.v1.SignCertificateResponse)1 UserIdentity (org.sonar.api.server.authentication.UserIdentity)1