Search in sources :

Example 16 with LoginException

use of com.sun.enterprise.security.auth.login.common.LoginException in project Payara by payara.

the class LoginContextDriver method login.

public static void login(AssertedCredentials asrtCred) throws javax.security.auth.login.LoginException {
    Subject subject = new Subject();
    subject.getPrivateCredentials().add(asrtCred);
    String jaasCtx = null;
    try {
        jaasCtx = Realm.getInstance(asrtCred.getRealmName()).getJAASContext();
    } catch (Exception ex) {
        if (ex instanceof LoginException) {
            throw (LoginException) ex;
        } else {
            throw (LoginException) new LoginException(ex.toString()).initCause(ex);
        }
    }
    try {
        // A dummyCallback is used to satisfy JAAS but it is never used.
        // name/pwd info is already contained in Subject's Credential
        LoginContext lg = new LoginContext(jaasCtx, subject, dummyCallback);
        lg.login();
    } catch (Exception e) {
        if (_logger.isLoggable(Level.INFO)) {
            _logger.log(Level.INFO, SecurityLoggerInfo.auditAtnRefusedError, asrtCred.getUserName());
        }
        if (_logger.isLoggable(Level.FINEST)) {
            _logger.log(Level.FINEST, "doPasswordLogin fails", e);
        }
        if (AUDIT_MANAGER.isAuditOn()) {
            AUDIT_MANAGER.authentication(asrtCred.getUserName(), asrtCred.getRealmName(), false);
        }
        if (e instanceof LoginException) {
            throw (LoginException) e;
        } else {
            throw (LoginException) new LoginException("Login failed: " + e.getMessage()).initCause(e);
        }
    }
    setSecurityContext(asrtCred.getUserName(), subject, asrtCred.getRealmName());
}
Also used : LoginContext(javax.security.auth.login.LoginContext) LoginException(com.sun.enterprise.security.auth.login.common.LoginException) Subject(javax.security.auth.Subject) LoginException(com.sun.enterprise.security.auth.login.common.LoginException) NoSuchRealmException(com.sun.enterprise.security.auth.realm.NoSuchRealmException) InvalidOperationException(com.sun.enterprise.security.auth.realm.InvalidOperationException) NoSuchUserException(com.sun.enterprise.security.auth.realm.NoSuchUserException)

Aggregations

LoginException (com.sun.enterprise.security.auth.login.common.LoginException)16 Subject (javax.security.auth.Subject)12 InvalidOperationException (com.sun.enterprise.security.auth.realm.InvalidOperationException)10 NoSuchRealmException (com.sun.enterprise.security.auth.realm.NoSuchRealmException)10 NoSuchUserException (com.sun.enterprise.security.auth.realm.NoSuchUserException)10 PrivilegedAction (java.security.PrivilegedAction)8 LoginContext (javax.security.auth.login.LoginContext)8 PasswordCredential (com.sun.enterprise.security.auth.login.common.PasswordCredential)5 Realm (com.sun.enterprise.security.auth.realm.Realm)4 CertificateRealm (com.sun.enterprise.security.auth.realm.certificate.CertificateRealm)4 X509CertificateCredential (com.sun.enterprise.security.auth.login.common.X509CertificateCredential)3 Iterator (java.util.Iterator)3 Set (java.util.Set)3 Enumeration (java.util.Enumeration)2 Group (org.glassfish.security.common.Group)2 X500Name (sun.security.x509.X500Name)2 GSSUPName (com.sun.enterprise.common.iiop.security.GSSUPName)1 SecurityContext (com.sun.enterprise.common.iiop.security.SecurityContext)1 ServerLoginCallbackHandler (com.sun.enterprise.security.auth.login.common.ServerLoginCallbackHandler)1 JDBCRealm (com.sun.enterprise.security.auth.realm.jdbc.JDBCRealm)1