Search in sources :

Example 71 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class AuthXMLUtils method getCallbacks.

/**
     * TODO-JAVADOC
     */
public static Callback[] getCallbacks(Node callbackNode, boolean noFilter, Callback[] callbacks) {
    if (callbackNode == null) {
        return (null);
    }
    // Get the length attribute and construct the callbacks
    String lenString = XMLUtils.getNodeAttributeValue(callbackNode, AuthXMLTags.LENGTH);
    int length = Integer.parseInt(lenString);
    if (debug.messageEnabled()) {
        debug.message("Callbacks length is : " + length);
        if (callbacks != null) {
            for (int k = 0; k < callbacks.length; k++) {
                debug.message("callback is : " + callbacks[k]);
            }
        }
    }
    Callback[] answer = new Callback[0];
    ArrayList callbackList = new ArrayList();
    Callback callback = null;
    // Get the child nodes and construct the callbacks
    NodeList childNodes = callbackNode.getChildNodes();
    if (childNodes == null) {
        return null;
    }
    // following indexes are to keep track of order of
    // callback in the callback array.
    int nameIndex = 0;
    int passIndex = 0;
    int ccIndex = 0;
    int concIndex = 0;
    int tiIndex = 0;
    int toIndex = 0;
    int lcIndex = 0;
    int ppIndex = 0;
    int diIndex = 0;
    int authCallbackIndex = 0;
    for (int i = 0; i < childNodes.getLength(); i++) {
        Node childNode = childNodes.item(i);
        String childNodeName = childNode.getNodeName();
        if (AuthXMLTags.HIDDEN_VALUE_CALLBACK.equals(childNodeName)) {
            if (callbacks != null) {
                nameIndex = getNameCallbackIndex(callbacks, nameIndex);
                if (nameIndex >= 0) {
                    callbackList.add(createHiddenValueCallback(childNode, callbacks[nameIndex]));
                }
                nameIndex = nameIndex + 1;
            } else {
                callbackList.add(createHiddenValueCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.NAME_CALLBACK)) {
            if (callbacks != null) {
                nameIndex = getNameCallbackIndex(callbacks, nameIndex);
                if (nameIndex >= 0) {
                    callbackList.add(createNameCallback(childNode, callbacks[nameIndex]));
                }
                nameIndex = nameIndex + 1;
            } else {
                callbackList.add(createNameCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.PASSWORD_CALLBACK)) {
            if (callbacks != null) {
                passIndex = getPasswordCallbackIndex(callbacks, passIndex);
                if (passIndex >= 0) {
                    callbackList.add(createPasswordCallback(childNode, callbacks[passIndex]));
                }
                passIndex = passIndex + 1;
            } else {
                callbackList.add(createPasswordCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.CHOICE_CALLBACK)) {
            if (callbacks != null) {
                ccIndex = getChoiceCallbackIndex(callbacks, ccIndex);
                if (ccIndex >= 0) {
                    callbackList.add(createChoiceCallback(childNode, callbacks[ccIndex]));
                }
                ccIndex = ccIndex + 1;
            } else {
                callbackList.add(createChoiceCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.CONFIRMATION_CALLBACK)) {
            if (callbacks != null) {
                concIndex = getConfCallbackIndex(callbacks, concIndex);
                if (concIndex >= 0) {
                    callbackList.add(createConfirmationCallback(childNode, callbacks[concIndex]));
                }
                concIndex = concIndex + 1;
            } else {
                callbackList.add(createConfirmationCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.TEXT_INPUT_CALLBACK)) {
            if (callbacks != null) {
                tiIndex = getTextInputIndex(callbacks, tiIndex);
                if (tiIndex >= 0) {
                    callbackList.add(createTextInputCallback(childNode, callbacks[tiIndex]));
                }
                tiIndex = tiIndex + 1;
            } else {
                callbackList.add(createTextInputCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.TEXT_OUTPUT_CALLBACK)) {
            if (callbacks != null) {
                toIndex = getTextOutputIndex(callbacks, toIndex);
                if (toIndex >= 0) {
                    callbackList.add(createTextOutputCallback(childNode, callbacks[toIndex]));
                }
                toIndex = toIndex + 1;
            } else {
                callbackList.add(createTextOutputCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.PAGE_PROPERTIES_CALLBACK) && noFilter) {
            if (callbacks != null) {
                ppIndex = getPagePropertiesIndex(callbacks, ppIndex);
                if (ppIndex >= 0) {
                    callbackList.add(createPagePropertiesCallback(childNode, callbacks[ppIndex]));
                }
                ppIndex = ppIndex + 1;
            } else {
                callbackList.add(createPagePropertiesCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.LANGUAGE_CALLBACK)) {
            if (callbacks != null) {
                lcIndex = getLanguageCallbackIndex(callbacks, lcIndex);
                if (lcIndex >= 0) {
                    callbackList.add(createLanguageCallback(childNode, callbacks[lcIndex]));
                }
                lcIndex = lcIndex + 1;
            } else {
                callbackList.add(createLanguageCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.SAML_CALLBACK)) {
            AuthenticationCallbackXMLHelper callbackXMLHelper = AuthenticationCallbackXMLHelperFactory.getCallbackXMLHelper();
            if (callbackXMLHelper != null) {
                if (callbacks != null) {
                    authCallbackIndex = callbackXMLHelper.getAuthenticationCallbackIndex(callbacks, authCallbackIndex);
                    if (authCallbackIndex >= 0) {
                        callbackList.add(callbackXMLHelper.createAuthenticationCallback(childNode, callbacks[authCallbackIndex]));
                    }
                    authCallbackIndex = authCallbackIndex + 1;
                } else {
                    callbackList.add(callbackXMLHelper.createAuthenticationCallback(childNode, null));
                }
            }
        } else if (childNodeName.equals(AuthXMLTags.X509CERTIFICATE_CALLBACK)) {
            if (callbacks != null) {
                lcIndex = getX509CertificateCallbackIndex(callbacks, lcIndex);
                if (lcIndex >= 0) {
                    callbackList.add(createX509CertificateCallback(childNode, callbacks[lcIndex]));
                }
                lcIndex = lcIndex + 1;
            } else {
                callbackList.add(createX509CertificateCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.HTTP_CALLBACK)) {
            if (callbacks != null) {
                diIndex = getHttpCallbackIndex(callbacks, ppIndex);
                if (diIndex >= 0) {
                    callbackList.add(createHttpCallback(childNode, callbacks[diIndex]));
                }
            } else {
                callbackList.add(createHttpCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.CUSTOM_CALLBACK)) {
            if (callbacks != null) {
                diIndex = getCustomCallbackIndex(callbacks, ppIndex);
                if (diIndex >= 0) {
                    callbackList.add(createCustomCallback(childNode, callbacks[diIndex]));
                }
                diIndex = diIndex + 1;
            } else {
                callbackList.add(createCustomCallback(childNode, null));
            }
        } else if (childNodeName.equals(AuthXMLTags.REDIRECT_CALLBACK)) {
            if (callbacks != null) {
                diIndex = getRedirectCallbackIndex(callbacks, ppIndex);
                if (diIndex >= 0) {
                    callbackList.add(createRedirectCallback(childNode, callbacks[diIndex]));
                }
                diIndex = diIndex + 1;
            } else {
                callbackList.add(createRedirectCallback(childNode, null));
            }
        }
    }
    return (Callback[]) callbackList.toArray(answer);
}
Also used : TextInputCallback(javax.security.auth.callback.TextInputCallback) PagePropertiesCallback(com.sun.identity.authentication.spi.PagePropertiesCallback) TextOutputCallback(javax.security.auth.callback.TextOutputCallback) HiddenValueCallback(com.sun.identity.authentication.callbacks.HiddenValueCallback) ScriptTextOutputCallback(com.sun.identity.authentication.callbacks.ScriptTextOutputCallback) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback) HttpCallback(com.sun.identity.authentication.spi.HttpCallback) RedirectCallback(com.sun.identity.authentication.spi.RedirectCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) LanguageCallback(javax.security.auth.callback.LanguageCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) ConfirmationCallback(javax.security.auth.callback.ConfirmationCallback) Callback(javax.security.auth.callback.Callback) NodeList(org.w3c.dom.NodeList) Node(org.w3c.dom.Node) ArrayList(java.util.ArrayList)

Example 72 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class Authenticator method processCallback.

private void processCallback(CommandManager mgr, AuthContext lc, String bindUser, String bindPwd) throws CLIException {
    ResourceBundle rb = mgr.getResourceBundle();
    while (lc.hasMoreRequirements()) {
        Callback[] callbacks = lc.getRequirements();
        if (callbacks != null) {
            setCallbackValues(callbacks, bindUser, bindPwd);
            lc.submitRequirements(callbacks);
        }
    }
    if (lc.getStatus() != AuthContext.Status.SUCCESS) {
        throw new CLIException(rb.getString("exception-LDAP-login-failed"), ExitCodes.SESSION_BASED_LOGIN_FAILED);
    }
}
Also used : PasswordCallback(javax.security.auth.callback.PasswordCallback) NameCallback(javax.security.auth.callback.NameCallback) Callback(javax.security.auth.callback.Callback) ResourceBundle(java.util.ResourceBundle)

Example 73 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class AuthXMLHandler method processAuthXMLRequest.

/*
     * Process the XMLRequest
     */
private AuthXMLResponse processAuthXMLRequest(String xml, PLLAuditor auditor, AuthXMLRequest authXMLRequest, HttpServletRequest servletRequest, HttpServletResponse servletResponse) {
    if (messageEnabled) {
        debug.message("authXMLRequest is : " + authXMLRequest);
    }
    int requestType = authXMLRequest.getRequestType();
    String sessionID = authXMLRequest.getAuthIdentifier();
    String orgName = authXMLRequest.getOrgName();
    AuthContextLocal authContext = authXMLRequest.getAuthContext();
    LoginState loginState = AuthUtils.getLoginState(authContext);
    auditor.setMethod(getMethodName(requestType));
    auditor.setUserId(getAuthenticationId(loginState));
    auditor.setTrackingId(getContextId(loginState));
    auditor.setRealm(orgName);
    auditor.auditAccessAttempt();
    String params = authXMLRequest.getParams();
    List envList = authXMLRequest.getEnvironment();
    Map envMap = toEnvMap(envList);
    AuthXMLResponse authResponse = new AuthXMLResponse(requestType);
    authResponse.setAuthContext(authContext);
    authResponse.setAuthIdentifier(sessionID);
    if (messageEnabled) {
        debug.message("authContext is : " + authContext);
        debug.message("requestType : " + requestType);
    }
    if (authXMLRequest.getValidSessionNoUpgrade()) {
        authResponse.setAuthXMLRequest(authXMLRequest);
        authResponse.setValidSessionNoUpgrade(true);
        return authResponse;
    }
    String securityEnabled = null;
    try {
        securityEnabled = AuthUtils.getRemoteSecurityEnabled();
    } catch (AuthException auExp) {
        debug.error("Got Exception", auExp);
        setErrorCode(authResponse, auExp);
        return authResponse;
    }
    if (debug.messageEnabled()) {
        debug.message("Security Enabled = " + securityEnabled);
    }
    if (requestType != 0) {
        if ((securityEnabled != null) && (securityEnabled.equals("true"))) {
            security = true;
            String indexNameLoc = authXMLRequest.getIndexName();
            AuthContext.IndexType indexTypeLoc = authXMLRequest.getIndexType();
            if (indexTypeLoc == null) {
                indexTypeLoc = AuthUtils.getIndexType(authContext);
                indexNameLoc = AuthUtils.getIndexName(authContext);
            }
            if (debug.messageEnabled()) {
                debug.message("Index Name Local : " + indexNameLoc);
                debug.message("Index Type Local : " + indexTypeLoc);
            }
            if (((indexTypeLoc == null) || (indexNameLoc == null)) || !((indexTypeLoc == AuthContext.IndexType.MODULE_INSTANCE) && indexNameLoc.equals("Application"))) {
                try {
                    String ssoTokenID = authXMLRequest.getAppSSOTokenID();
                    if (debug.messageEnabled()) {
                        debug.message("Session ID = : " + ssoTokenID);
                    }
                    SSOTokenManager manager = SSOTokenManager.getInstance();
                    SSOToken appSSOToken = manager.createSSOToken(ssoTokenID);
                    // retry
                    if (!manager.isValidToken(appSSOToken)) {
                        if (debug.messageEnabled()) {
                            debug.message("App SSOToken is not valid");
                        }
                        setErrorCode(authResponse, new AuthException(AMAuthErrorCode.REMOTE_AUTH_INVALID_SSO_TOKEN, null));
                        return authResponse;
                    } else {
                        debug.message("App SSOToken is VALID");
                    }
                } catch (SSOException ssoe) {
                    // can retry
                    if (debug.messageEnabled()) {
                        debug.message("App SSOToken is not valid: " + ssoe.getMessage());
                    }
                    setErrorCode(authResponse, new AuthException(AMAuthErrorCode.REMOTE_AUTH_INVALID_SSO_TOKEN, null));
                    return authResponse;
                } catch (Exception exp) {
                    debug.error("Got Exception", exp);
                    setErrorCode(authResponse, exp);
                    return authResponse;
                }
            }
        }
    } else {
        security = false;
    }
    // selected choice then start module based authentication.
    if ((AuthUtils.getIndexType(authContext) == AuthContext.IndexType.LEVEL) || (AuthUtils.getIndexType(authContext) == AuthContext.IndexType.COMPOSITE_ADVICE)) {
        Callback[] callbacks = authXMLRequest.getSubmittedCallbacks();
        if (messageEnabled) {
            debug.message("Callbacks are  : " + callbacks);
        }
        if (callbacks != null) {
            if (messageEnabled) {
                debug.message("Callback length is : " + callbacks.length);
            }
            if (callbacks[0] instanceof ChoiceCallback) {
                ChoiceCallback cc = (ChoiceCallback) callbacks[0];
                int[] selectedIndexes = cc.getSelectedIndexes();
                int selected = selectedIndexes[0];
                String[] choices = cc.getChoices();
                String indexName = choices[selected];
                if (messageEnabled) {
                    debug.message("Selected Index is : " + indexName);
                }
                authXMLRequest.setIndexType("moduleInstance");
                authXMLRequest.setIndexName(indexName);
                authXMLRequest.setRequestType(AuthXMLRequest.LoginIndex);
                requestType = AuthXMLRequest.LoginIndex;
                auditor.setMethod(getMethodName(requestType));
            }
        }
    }
    AuthContext.Status loginStatus = AuthContext.Status.IN_PROGRESS;
    HttpServletRequest clientRequest = authXMLRequest.getClientRequest();
    if (loginState != null) {
        loginState.setHttpServletRequest(clientRequest);
        loginState.setHttpServletResponse(authXMLRequest.getClientResponse());
        if (clientRequest != null) {
            loginState.setParamHash(AuthUtils.parseRequestParameters(clientRequest));
        }
    }
    switch(requestType) {
        case AuthXMLRequest.NewAuthContext:
            try {
                processNewRequest(servletRequest, servletResponse, authResponse, loginState, authContext);
                postProcess(loginState, authResponse);
            } catch (Exception ex) {
                debug.error("Error in NewAuthContext ", ex);
                setErrorCode(authResponse, ex);
            }
            break;
        case AuthXMLRequest.Login:
            try {
                if (sessionID != null && sessionID.equals("0")) {
                    processNewRequest(servletRequest, servletResponse, authResponse, loginState, authContext);
                }
                String clientHost = null;
                if (security) {
                    clientHost = authXMLRequest.getHostName();
                    if (messageEnabled) {
                        debug.message("Client Host from Request = " + clientHost);
                    }
                }
                if ((clientHost == null) && (servletRequest != null)) {
                    clientHost = ClientUtils.getClientIPAddress(servletRequest);
                }
                loginState.setClient(clientHost);
                authContext.login();
                //setServletRequest(servletRequest,authContext);
                processRequirements(xml, authContext, authResponse, params, servletRequest);
                loginStatus = authContext.getStatus();
                authResponse.setRemoteRequest(loginState.getHttpServletRequest());
                authResponse.setRemoteResponse(loginState.getHttpServletResponse());
                postProcess(loginState, authResponse);
                checkACException(authResponse, authContext);
            } catch (Exception ex) {
                debug.error("Error during login ", ex);
                setErrorCode(authResponse, ex);
                authResponse.setLoginStatus(authContext.getStatus());
            }
            break;
        case AuthXMLRequest.LoginIndex:
            try {
                AuthContext.IndexType indexType = authXMLRequest.getIndexType();
                String indexName = authXMLRequest.getIndexName();
                if (messageEnabled) {
                    debug.message("indexName is : " + indexName);
                    debug.message("indexType is : " + indexType);
                }
                if (sessionID != null && sessionID.equals("0")) {
                    processNewRequest(servletRequest, servletResponse, authResponse, loginState, authContext);
                }
                String clientHost = null;
                if (security) {
                    clientHost = authXMLRequest.getHostName();
                    if (messageEnabled) {
                        debug.message("Client Host from Request = " + clientHost);
                    }
                }
                if ((clientHost == null) && (servletRequest != null)) {
                    clientHost = ClientUtils.getClientIPAddress(servletRequest);
                }
                loginState.setClient(clientHost);
                String locale = authXMLRequest.getLocale();
                if (locale != null && locale.length() > 0) {
                    if (debug.messageEnabled()) {
                        debug.message("locale is : " + locale);
                    }
                    authContext.login(indexType, indexName, envMap, locale);
                } else {
                    authContext.login(indexType, indexName, envMap, null);
                }
                //setServletRequest(servletRequest,authContext);
                processRequirements(xml, authContext, authResponse, params, servletRequest);
                loginStatus = authContext.getStatus();
                authResponse.setRemoteRequest(loginState.getHttpServletRequest());
                authResponse.setRemoteResponse(loginState.getHttpServletResponse());
                postProcess(loginState, authResponse);
                checkACException(authResponse, authContext);
            } catch (Exception ex) {
                debug.error("Exception during LoginIndex", ex);
                setErrorCode(authResponse, ex);
            }
            break;
        case AuthXMLRequest.LoginSubject:
            try {
                Subject subject = authXMLRequest.getSubject();
                authContext.login(subject);
                //setServletRequest(servletRequest,authContext);
                processRequirements(xml, authContext, authResponse, params, servletRequest);
                postProcess(loginState, authResponse);
                loginStatus = authContext.getStatus();
                checkACException(authResponse, authContext);
            } catch (AuthLoginException ale) {
                debug.error("Exception during LoginSubject", ale);
                setErrorCode(authResponse, ale);
            }
            break;
        case AuthXMLRequest.SubmitRequirements:
            try {
                //setServletRequest(servletRequest,authContext);
                Callback[] submittedCallbacks = authXMLRequest.getSubmittedCallbacks();
                authContext.submitRequirements(submittedCallbacks);
                Callback[] reqdCallbacks = null;
                if (authContext.hasMoreRequirements()) {
                    reqdCallbacks = authContext.getRequirements();
                    authResponse.setReqdCallbacks(reqdCallbacks);
                }
                authResponse.setRemoteRequest(loginState.getHttpServletRequest());
                authResponse.setRemoteResponse(loginState.getHttpServletResponse());
                postProcess(loginState, authResponse);
                loginStatus = authContext.getStatus();
                authResponse.setLoginStatus(loginStatus);
                InternalSession oldSession = loginState.getOldSession();
                authResponse.setOldSession(oldSession);
                checkACException(authResponse, authContext);
            } catch (Exception ex) {
                debug.error("Error during submit requirements ", ex);
                setErrorCode(authResponse, ex);
            }
            break;
        case AuthXMLRequest.QueryInformation:
            try {
                if (sessionID != null && sessionID.equals("0")) {
                    processNewRequest(servletRequest, servletResponse, authResponse, loginState, authContext);
                }
                Set moduleNames = authContext.getModuleInstanceNames();
                authResponse.setModuleNames(moduleNames);
                authResponse.setAuthContext(authContext);
                postProcess(loginState, authResponse);
                checkACException(authResponse, authContext);
            } catch (Exception ex) {
                debug.error("Error during Query Information", ex);
                setErrorCode(authResponse, ex);
            }
            break;
        case AuthXMLRequest.Logout:
            //boolean logoutCalled = false;
            if (sessionID != null && !sessionID.equals("0")) {
                /*intSess = AuthD.getSession(sessionID);
                    try {
                        token = SSOTokenManager.getInstance().
                            createSSOToken(sessionID);
                        if (debug.messageEnabled()) {
                            debug.message("AuthXMLHandler."
                                + "processAuthXMLRequest: Created token " 
                                + "during logout = "+token);
                        }
	            } catch (com.iplanet.sso.SSOException ssoExp) {
                       if (debug.messageEnabled()) {
		           debug.message("AuthXMLHandler.processAuthXMLRequest:"
                           + "SSOException checking validity of SSO Token");
                       }
	            }*/
                try {
                    AuthUtils.logout(sessionID, servletRequest, servletResponse);
                } catch (com.iplanet.sso.SSOException ssoExp) {
                    if (debug.messageEnabled()) {
                        debug.message("AuthXMLHandler.processAuthXMLRequest:" + "SSOException checking validity of SSO Token");
                    }
                }
            }
            /*if (intSess != null) {
                    loginContext = intSess.getObject(ISAuthConstants.
                        LOGIN_CONTEXT);
                }
                try {
                    if (loginContext != null) {
                        if (loginContext instanceof 
                            javax.security.auth.login.LoginContext) {
                            javax.security.auth.login.LoginContext lc = 
                                (javax.security.auth.login.LoginContext) 
                                 loginContext;
                            lc.logout();
                        } else {
                            com.sun.identity.authentication.jaas.LoginContext 
                                jlc = (com.sun.identity.authentication.jaas.
                                LoginContext) loginContext;
                            jlc.logout();
                        }
                        logoutCalled = true;
                    }
                } catch (javax.security.auth.login.LoginException loginExp) {
                    debug.error("AuthXMLHandler.processAuthXMLRequest: "
                        + "Cannot Execute module Logout", loginExp);
                }
                Set postAuthSet = null;
                if (intSess != null) {
                    postAuthSet = (Set) intSess.getObject(ISAuthConstants.
                        POSTPROCESS_INSTANCE_SET);
                }
                if ((postAuthSet != null) && !(postAuthSet.isEmpty())) {
                    AMPostAuthProcessInterface postLoginInstance=null;
                    for(Iterator iter = postAuthSet.iterator();
                    iter.hasNext();) {
                        try {
	                    postLoginInstance =
	 	                (AMPostAuthProcessInterface) iter.next();
                             postLoginInstance.onLogout(servletRequest, 
                                 servletResponse, token);
                        } catch (Exception exp) {
                           debug.error("AuthXMLHandler.processAuthXMLRequest: "
                               + "Failed in post logout.", exp);
                        }
	            }
                } else {
                    String plis = null;
                    if (intSess != null) {
                        plis = intSess.getProperty(
                            ISAuthConstants.POST_AUTH_PROCESS_INSTANCE);
                    }
                    if (plis != null && plis.length() > 0) {
                        StringTokenizer st = new StringTokenizer(plis, "|");
                        if (token != null) {
                            while (st.hasMoreTokens()) {
                                String pli = (String)st.nextToken();
                                try {
                                    AMPostAuthProcessInterface postProcess = 
                                            (AMPostAuthProcessInterface)
                                            Thread.currentThread().
                                            getContextClassLoader().
                                            loadClass(pli).newInstance();
                                    postProcess.onLogout(servletRequest, 
                                        servletResponse, token);
                                } catch (Exception e) {
                                    debug.error("AuthXMLHandler."
                                        + "processAuthXMLRequest:" + pli, e);
                                }
                            }
                        }
                    }
                }
                try {
                    boolean isTokenValid = SSOTokenManager.getInstance().
                        isValidToken(token);
                    if ((token != null) && isTokenValid) {
                        AuthD.getAuth().logLogout(token);
                        Session session = Session.getSession(
                            new SessionID(sessionID));
                        session.logout();
                        debug.message("logout successful.");
                    }
	        } catch (com.iplanet.dpro.session.SessionException 
                    sessExp) {
                    if (debug.messageEnabled()) {
                        debug.message("AuthXMLHandler."
                            + "processAuthXMLRequest: SessionException"
                            + " checking validity of SSO Token");
                    }
	        } catch (com.iplanet.sso.SSOException ssoExp) {
                    if (debug.messageEnabled()) {
                        debug.message("AuthXMLHandler."
                            + "processAuthXMLRequest: SSOException "
                            + "checking validity of SSO Token");
                    }
                }*/
            authResponse.setLoginStatus(AuthContext.Status.COMPLETED);
            break;
        case AuthXMLRequest.Abort:
            try {
                authContext.abort();
                loginStatus = authContext.getStatus();
                authResponse.setLoginStatus(loginStatus);
                checkACException(authResponse, authContext);
            } catch (AuthLoginException ale) {
                debug.error("Error aborting ", ale);
                setErrorCode(authResponse, ale);
            }
            break;
    }
    if (messageEnabled) {
        debug.message("loginStatus: " + loginStatus);
        if (authContext != null) {
            debug.message("error Code: " + authContext.getErrorCode());
            debug.message("error Template: " + authContext.getErrorTemplate());
        }
    }
    if (loginStatus == AuthContext.Status.FAILED) {
        if ((authContext.getErrorMessage() != null) && (authContext.getErrorMessage().equals(AMResourceBundleCache.getInstance().getResBundle("amAuthLDAP", com.sun.identity.shared.locale.Locale.getLocale(loginState.getLocale())).getString(ISAuthConstants.EXCEED_RETRY_LIMIT)))) {
            loginState.setErrorCode(AMAuthErrorCode.AUTH_LOGIN_FAILED);
        }
        if ((authContext.getErrorCode() != null) && ((authContext.getErrorCode()).length() > 0)) {
            authResponse.setErrorCode(authContext.getErrorCode());
        }
        checkACException(authResponse, authContext);
        if ((authContext.getErrorTemplate() != null) && ((authContext.getErrorTemplate()).length() > 0)) {
            authResponse.setErrorTemplate(authContext.getErrorTemplate());
        }
        //Account Lockout Warning Check
        if ((authContext.getErrorCode() != null) && (authContext.getErrorCode().equals(AMAuthErrorCode.AUTH_INVALID_PASSWORD))) {
            String lockWarning = authContext.getLockoutMsg();
            if ((lockWarning != null) && (lockWarning.length() > 0)) {
                authResponse.setErrorMessage(lockWarning);
            }
        }
    }
    auditor.setUserId(getAuthenticationId(loginState));
    auditor.setTrackingId(getContextId(loginState));
    return authResponse;
}
Also used : SSOToken(com.iplanet.sso.SSOToken) Set(java.util.Set) ResponseSet(com.iplanet.services.comm.share.ResponseSet) HashSet(java.util.HashSet) RequestSet(com.iplanet.services.comm.share.RequestSet) AuthException(com.sun.identity.authentication.service.AuthException) AuthContext(com.sun.identity.authentication.AuthContext) SSOException(com.iplanet.sso.SSOException) HttpServletRequest(javax.servlet.http.HttpServletRequest) InternalSession(com.iplanet.dpro.session.service.InternalSession) List(java.util.List) ArrayList(java.util.ArrayList) SSOTokenManager(com.iplanet.sso.SSOTokenManager) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) SSOException(com.iplanet.sso.SSOException) AuthException(com.sun.identity.authentication.service.AuthException) Subject(javax.security.auth.Subject) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) PasswordCallback(javax.security.auth.callback.PasswordCallback) Callback(javax.security.auth.callback.Callback) X509CertificateCallback(com.sun.identity.authentication.spi.X509CertificateCallback) ChoiceCallback(javax.security.auth.callback.ChoiceCallback) NameCallback(javax.security.auth.callback.NameCallback) LoginState(com.sun.identity.authentication.service.LoginState) SSOException(com.iplanet.sso.SSOException) Map(java.util.Map) HashMap(java.util.HashMap)

Example 74 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class JaspiAuthModuleWrapperTest method setUp.

@BeforeMethod
public void setUp() {
    amLoginModuleBinder = mock(AMLoginModuleBinder.class);
    serverAuthModule = mock(ServerAuthModule.class);
    jaspiAuthModuleWrapper = new JaspiAuthModuleWrapper<ServerAuthModule>(serverAuthModule, "amAuthPersistentCookie") {

        @Override
        protected Map<String, Object> initialize(Subject subject, Map sharedState, Map options) {
            return config;
        }

        @Override
        protected boolean process(MessageInfo messageInfo, Subject clientSubject, Callback[] callbacks) throws LoginException {
            processMethodCalled = true;
            return true;
        }

        @Override
        protected Map<String, Object> initialize(Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
            return config;
        }

        @Override
        protected void onLoginSuccess(MessageInfo messageInfo, Map requestParamsMap, HttpServletRequest request, HttpServletResponse response, SSOToken ssoToken) throws AuthenticationException {
            onLoginSuccessMethodCalled = true;
        }

        @Override
        public Principal getPrincipal() {
            return null;
        }
    };
    jaspiAuthModuleWrapper.setAMLoginModule(amLoginModuleBinder);
    HttpServletRequest request = mock(HttpServletRequest.class);
    HttpServletResponse response = mock(HttpServletResponse.class);
    given(amLoginModuleBinder.getHttpServletRequest()).willReturn(request);
    given(amLoginModuleBinder.getHttpServletResponse()).willReturn(response);
}
Also used : SSOToken(com.iplanet.sso.SSOToken) AuthenticationException(com.sun.identity.authentication.spi.AuthenticationException) ServerAuthModule(javax.security.auth.message.module.ServerAuthModule) HttpServletResponse(javax.servlet.http.HttpServletResponse) Subject(javax.security.auth.Subject) MessageInfo(javax.security.auth.message.MessageInfo) HttpServletRequest(javax.servlet.http.HttpServletRequest) Callback(javax.security.auth.callback.Callback) LoginException(javax.security.auth.login.LoginException) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) HashMap(java.util.HashMap) Map(java.util.Map) Principal(java.security.Principal) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 75 with Callback

use of javax.security.auth.callback.Callback in project OpenAM by OpenRock.

the class Application method authenticateToDatastore.

/**
     * Authenticates to the datastore using idRepo API
     *
     * @param userName User Name
     * @param userPassword User Password
     * @return <code>true</code> if success. <code>false</code> if failure
     * @throws <code> AuthLoginException </code> 
     */
private boolean authenticateToDatastore(String userName, String userPassword) throws AuthLoginException {
    boolean retval = false;
    Callback[] callbacks = new Callback[2];
    NameCallback nameCallback = new NameCallback("NamePrompt");
    nameCallback.setName(userName);
    callbacks[0] = nameCallback;
    PasswordCallback passwordCallback = new PasswordCallback("PasswordPrompt", false);
    passwordCallback.setPassword(userPassword.toCharArray());
    callbacks[1] = passwordCallback;
    try {
        AMIdentityRepository idrepo = getAMIdentityRepository(getRequestOrg());
        retval = idrepo.authenticate(callbacks);
    } catch (IdRepoException idrepoExp) {
        if (debug.messageEnabled()) {
            debug.message("Application.authenticateToDatastore:  " + "IdRepo Exception", idrepoExp);
        }
    }
    return retval;
}
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) AMIdentityRepository(com.sun.identity.idm.AMIdentityRepository) IdRepoException(com.sun.identity.idm.IdRepoException) PasswordCallback(javax.security.auth.callback.PasswordCallback)

Aggregations

Callback (javax.security.auth.callback.Callback)274 NameCallback (javax.security.auth.callback.NameCallback)181 PasswordCallback (javax.security.auth.callback.PasswordCallback)173 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)127 IOException (java.io.IOException)84 LoginException (javax.security.auth.login.LoginException)54 ChoiceCallback (javax.security.auth.callback.ChoiceCallback)49 CallbackHandler (javax.security.auth.callback.CallbackHandler)43 Test (org.testng.annotations.Test)42 ConfirmationCallback (javax.security.auth.callback.ConfirmationCallback)38 AuthLoginException (com.sun.identity.authentication.spi.AuthLoginException)31 Subject (javax.security.auth.Subject)31 HashMap (java.util.HashMap)28 HttpServletRequest (javax.servlet.http.HttpServletRequest)24 Principal (java.security.Principal)23 AuthContext (com.sun.identity.authentication.AuthContext)22 FailedLoginException (javax.security.auth.login.FailedLoginException)22 PagePropertiesCallback (com.sun.identity.authentication.spi.PagePropertiesCallback)19 TextOutputCallback (javax.security.auth.callback.TextOutputCallback)19 LoginContext (javax.security.auth.login.LoginContext)18