Search in sources :

Example 21 with AuthContext

use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.

the class Authenticator method sessionBasedLoginInternal.

private AuthContext sessionBasedLoginInternal(CommandManager mgr, String bindUser, String bindPwd, String indexType, String indexName) throws CLIException {
    AuthContext lc = getAuthContext(mgr, indexType, indexName);
    processCallback(mgr, lc, bindUser, bindPwd);
    try {
        lc.getSSOToken();
    } catch (Exception e) {
        ResourceBundle rb = mgr.getResourceBundle();
        throw new CLIException(rb.getString("exception-session-based-login-failed"), ExitCodes.SESSION_BASED_LOGIN_FAILED);
    }
    return lc;
}
Also used : AuthContext(com.sun.identity.authentication.AuthContext) ResourceBundle(java.util.ResourceBundle) LoginException(javax.security.auth.login.LoginException) InvalidAuthContextException(com.sun.identity.authentication.internal.InvalidAuthContextException) SSOException(com.iplanet.sso.SSOException)

Example 22 with AuthContext

use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.

the class SystemAppTokenProvider method getAppSSOToken.

/**
     * Returns Application single sign on token.
     *
     * @return application single sign on token.
     */
public SSOToken getAppSSOToken() {
    SSOToken ssoToken = null;
    try {
        AuthContext authContext = new AuthContext("/");
        authContext.login(AuthContext.IndexType.MODULE_INSTANCE, MODULE_APPLICATION);
        if (authContext.hasMoreRequirements()) {
            Callback[] callbacks = authContext.getRequirements();
            if (callbacks != null) {
                addLoginCallbackMessage(callbacks, appUserName, appPassword);
                authContext.submitRequirements(callbacks);
            }
        }
        if (authContext.getStatus() == AuthContext.Status.SUCCESS) {
            ssoToken = authContext.getSSOToken();
        }
    } catch (AuthLoginException ale) {
        AdminTokenAction.debug.error("SystemAppTokenProvider.getAppSSOToken()", ale);
    } catch (UnsupportedCallbackException usce) {
        AdminTokenAction.debug.error("SystemAppTokenProvider.getAppSSOToken()", usce);
    } catch (Exception e) {
        AdminTokenAction.debug.error("SystemAppTokenProvider.getAppSSOToken()", e);
    }
    return ssoToken;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) AuthContext(com.sun.identity.authentication.AuthContext) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 23 with AuthContext

use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.

the class TokenUtils method getSessionToken.

public static SSOToken getSessionToken(String orgName, String userId, String password, String module, int level) throws Exception {
    AuthContext ac = null;
    try {
        //System.out.println("TokenUtils:orgName=" + orgName);
        ac = new AuthContext(orgName);
        if (module != null) {
            ac.login(AuthContext.IndexType.MODULE_INSTANCE, module);
        } else if (level != -1) {
            ac.login(AuthContext.IndexType.LEVEL, String.valueOf(level));
        } else {
            //System.out.println("TokenUtils:calling login()");
            ac.login();
        }
    //System.out.println("TokenUtils:after ac.login()");
    } catch (LoginException le) {
        le.printStackTrace();
        return null;
    }
    try {
        Callback[] callbacks = null;
        // Get the information requested by the plug-ins
        if (ac.hasMoreRequirements()) {
            callbacks = ac.getRequirements();
            if (callbacks != null) {
                addLoginCallbackMessage(callbacks, userId, password);
                ac.submitRequirements(callbacks);
                if (ac.getStatus() == AuthContext.Status.SUCCESS) {
                    //System.out.println("Auth success");
                    Subject authSubject = ac.getSubject();
                    if (authSubject != null) {
                        Iterator principals = (authSubject.getPrincipals()).iterator();
                        Principal principal;
                        while (principals.hasNext()) {
                            principal = (Principal) principals.next();
                        }
                    }
                } else if (ac.getStatus() == AuthContext.Status.FAILED) {
                //System.out.println("Authentication has FAILED");
                } else {
                }
            } else {
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
    //System.out.println(ac.getSSOToken().getPrincipal().getName());
    return ac.getSSOToken();
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) Iterator(java.util.Iterator) AuthContext(com.sun.identity.authentication.AuthContext) LoginException(javax.security.auth.login.LoginException) Subject(javax.security.auth.Subject) Principal(java.security.Principal) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException)

Example 24 with AuthContext

use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.

the class LogSample method logWriteProcessing.

private void logWriteProcessing() {
    /*
         *  get:
         *    1. subject userid (subject of the LogRecord)
	 *    2. subject userid's password
         *    3. Log filename to log to
         *    4. LogRecord's "data"
         *    5. LoggedBy userid (who's doing the logging)
         *    6. LoggedBy userid's password
         *    7. Realm (for both subject userid and LoggedBy userid
         *       in this sample)
         */
    String userSID = sampleUtils.getLine("Subject Userid", DEF_USERNAME);
    String userPWD = sampleUtils.getLine("Subject Userid " + userSID + "'s password", DEF_USERPSWD);
    String logName = sampleUtils.getLine("Log file", DEF_LOGNAME);
    String message = sampleUtils.getLine("Log message", DEF_LOGMSG);
    ;
    String loggedBySID = sampleUtils.getLine("LoggedBy Userid", DEF_LOGGEDBY);
    String loggedByPWD = sampleUtils.getLine("LoggedBy Userid's password", DEF_LOGGEDBYPSWD);
    String realmName = sampleUtils.getLine("Realm", DEF_REALM);
    // get AuthContexts for subject userid and loggedby userid
    try {
        userAC = new AuthContext(realmName);
        loggerAC = new AuthContext(realmName);
    } catch (AuthLoginException le) {
        System.err.println("LogSampleUtils: could not get AuthContext for realm " + realmName);
        System.exit(2);
    }
    // do user and loggedby login and get the SSOToken
    try {
        userSSOToken = sampleUtils.realmLogin(userSID, userPWD, userAC);
        loggerSSOToken = sampleUtils.realmLogin(loggedBySID, loggedByPWD, loggerAC);
    } catch (SSOException ssoe) {
        System.err.println("logWriteProcessing: could not get SSOToken: " + ssoe.getMessage());
        System.exit(3);
    } catch (AuthLoginException ale) {
        System.err.println("logWriteProcessing: could not authenticate: " + ale.getMessage());
        System.exit(4);
    } catch (Exception e) {
        System.err.println("logWriteProcessing: exception getting SSOToken: " + e.getMessage());
        System.exit(5);
    }
    try {
        LogRecord logRecord = new LogRecord(java.util.logging.Level.INFO, message, userSSOToken);
        logRecord.addLogInfo("ModuleName", DEF_MODULENAME);
        java.net.InetAddress ipAddr = java.net.InetAddress.getLocalHost();
        logRecord.addLogInfo("IPAddr", ipAddr.getHostAddress());
        Logger logger = (Logger) Logger.getLogger(logName);
        logger.log(logRecord, loggerSSOToken);
        System.out.println("LogSample: Logging Successful !!!");
        userAC.logout();
        loggerAC.logout();
    } catch (AMLogException amex) {
        System.err.println("LogSample: AMLogException: " + amex.getMessage());
        System.err.println("LogSample: Logging Failed; " + "Is user '" + loggedBySID + "' a member of a Role or Group with log writing privileges?");
    } catch (Exception ssoe) {
        System.err.println("LogSample: Exception: " + ssoe.getMessage());
        System.err.println("LogSample: Logging Failed !!!");
    }
}
Also used : LogRecord(com.sun.identity.log.LogRecord) AuthContext(com.sun.identity.authentication.AuthContext) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) AMLogException(com.sun.identity.log.AMLogException) SSOException(com.iplanet.sso.SSOException) Logger(com.sun.identity.log.Logger) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AMLogException(com.sun.identity.log.AMLogException)

Example 25 with AuthContext

use of com.sun.identity.authentication.AuthContext in project OpenAM by OpenRock.

the class SampleBase method authenticate.

protected AuthContext authenticate(String orgname, String username, String password, PrintWriter out) throws Exception {
    // Authenticate the user and obtain SSO Token
    AuthContext lc = new AuthContext(orgname);
    lc.login();
    while (lc.hasMoreRequirements()) {
        Callback[] callbacks = lc.getRequirements();
        for (int i = 0; i < callbacks.length; i++) {
            if (callbacks[i] instanceof NameCallback) {
                NameCallback nc = (NameCallback) callbacks[i];
                nc.setName(username);
            } else if (callbacks[i] instanceof PasswordCallback) {
                PasswordCallback pc = (PasswordCallback) callbacks[i];
                pc.setPassword(password.toCharArray());
            } else {
                out.println("Unknow Callback: " + callbacks[i]);
                out.println("</body></html>");
                return null;
            }
        }
        lc.submitRequirements(callbacks);
    }
    if (lc.getStatus() != AuthContext.Status.SUCCESS) {
        out.println("Invalid credentials");
        out.println("</body></html>");
        return null;
    }
    return lc;
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) NameCallback(javax.security.auth.callback.NameCallback) AuthContext(com.sun.identity.authentication.AuthContext) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Aggregations

AuthContext (com.sun.identity.authentication.AuthContext)40 Callback (javax.security.auth.callback.Callback)22 NameCallback (javax.security.auth.callback.NameCallback)21 PasswordCallback (javax.security.auth.callback.PasswordCallback)20 SSOToken (com.iplanet.sso.SSOToken)14 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)14 SSOException (com.iplanet.sso.SSOException)12 LoginException (javax.security.auth.login.LoginException)8 Iterator (java.util.Iterator)7 Set (java.util.Set)7 IdRepoException (com.sun.identity.idm.IdRepoException)6 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)6 IOException (java.io.IOException)5 ArrayList (java.util.ArrayList)5 Subject (javax.security.auth.Subject)5 Principal (java.security.Principal)4 HashSet (java.util.HashSet)4 Map (java.util.Map)4 SSOTokenManager (com.iplanet.sso.SSOTokenManager)3 LoginState (com.sun.identity.authentication.service.LoginState)3