Search in sources :

Example 1 with SecurityAssociationCallback

use of org.jboss.security.auth.callback.SecurityAssociationCallback in project wildfly by wildfly.

the class TrustedIdentityTokenLoginModule method login.

@Override
@SuppressWarnings("unchecked")
public boolean login() throws LoginException {
    // See if shared credentials exist
    if (super.login() == true) {
        // Setup our view of the user
        Object username = sharedState.get("javax.security.auth.login.name");
        if (username instanceof Principal)
            identity = (Principal) username;
        else {
            String name = username.toString();
            try {
                identity = createIdentity(name);
            } catch (Exception e) {
                LoginException le = new LoginException();
                le.initCause(e);
                throw le;
            }
        }
        return true;
    }
    super.loginOk = false;
    if (callbackHandler == null) {
        throw new LoginException();
    }
    SecurityAssociationCallback callback = new SecurityAssociationCallback();
    Callback[] callbacks = { callback };
    final String username;
    try {
        callbackHandler.handle(callbacks);
        username = callback.getPrincipal().getName();
        final Object c = callback.getCredential();
        if (c instanceof SASCurrent) {
            credential = (SASCurrent) c;
        } else {
            return false;
        }
    } catch (IOException e) {
        LoginException le = new LoginException();
        le.initCause(e);
        throw le;
    } catch (UnsupportedCallbackException e) {
        LoginException le = new LoginException();
        le.initCause(e);
        throw le;
    }
    validateCredential(username, credential);
    if (username == null) {
        return false;
    }
    if (identity == null) {
        try {
            identity = createIdentity(username);
        } catch (Exception e) {
            LoginException le = new LoginException();
            le.initCause(e);
            throw le;
        }
    }
    if (getUseFirstPass() == true) {
        // Add the principal to the shared state map
        sharedState.put("javax.security.auth.login.name", identity);
        sharedState.put("javax.security.auth.login.password", credential);
    }
    super.loginOk = true;
    return true;
}
Also used : SASCurrent(org.jboss.iiop.csiv2.SASCurrent) SecurityAssociationCallback(org.jboss.security.auth.callback.SecurityAssociationCallback) Callback(javax.security.auth.callback.Callback) LoginException(javax.security.auth.login.LoginException) IOException(java.io.IOException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) SecurityAssociationCallback(org.jboss.security.auth.callback.SecurityAssociationCallback) Principal(java.security.Principal) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException)

Example 2 with SecurityAssociationCallback

use of org.jboss.security.auth.callback.SecurityAssociationCallback in project wildfly-swarm by wildfly-swarm.

the class JWTLoginModule method login.

@Override
public boolean login() throws LoginException {
    SecurityAssociationCallback sac = new SecurityAssociationCallback();
    try {
        callbackHandler.handle(new Callback[] { sac });
        JWTCredential jwtCredential = (JWTCredential) sac.getCredential();
        // Validate the credential by
        jwtPrincipal = validate(jwtCredential);
    } catch (Exception e) {
        if (logExceptions) {
            log.infof(e, "Failed to validate token");
        }
        LoginException ex = new LoginException("Failed to validate token");
        ex.initCause(e);
        throw ex;
    }
    loginOk = true;
    return true;
}
Also used : LoginException(javax.security.auth.login.LoginException) SecurityAssociationCallback(org.jboss.security.auth.callback.SecurityAssociationCallback) LoginException(javax.security.auth.login.LoginException) ParseException(org.wildfly.swarm.microprofile.jwtauth.deployment.principal.ParseException)

Aggregations

LoginException (javax.security.auth.login.LoginException)2 SecurityAssociationCallback (org.jboss.security.auth.callback.SecurityAssociationCallback)2 IOException (java.io.IOException)1 Principal (java.security.Principal)1 Callback (javax.security.auth.callback.Callback)1 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)1 SASCurrent (org.jboss.iiop.csiv2.SASCurrent)1 ParseException (org.wildfly.swarm.microprofile.jwtauth.deployment.principal.ParseException)1