Search in sources :

Example 1 with PolicyException

use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.

the class AuthContextLocal method login.

/**
     * Performs the Login for the given AuthContext
     * @param type authentication index type
     * @param indexName authentication index name
     * @param principal principal name of the user to be authenticated
     * @param password password for the user
     * @param subject authentication subject
     * @param envMap Environment map, this is applicable only when the type
     *        is <code>AuthContext.IndexType.RESOURCE</code>
     * @param locale locale setting
     * @throws AuthLoginException if error occurs during login
     */
protected void login(AuthContext.IndexType type, String indexName, Principal principal, char[] password, Subject subject, Map envMap, String locale) throws AuthLoginException {
    try {
        /*if (!getStatus().equals(AuthContext.Status.NOT_STARTED)) {
                if (authDebug.messageEnabled()) {
                    authDebug.message("AuthContextLocal::login called " +
                    "when the current login status is : " + getStatus());
                }
                throw new AuthLoginException(amAuthContextLocal, 
                    "invalidMethod", new Object[]{getStatus()});
            }*/
        // switch the login status
        loginStatus = AuthContext.Status.IN_PROGRESS;
        String redirectUrl = null;
        // specially processing for resouce/IP/Environement based auth
        if ((type != null) && type.equals(AuthContext.IndexType.RESOURCE)) {
            // this is resouce/IP/Env based authentication
            // call Policy Decision Util to find out the actual auth type 
            // required by policy
            List result = Collections.EMPTY_LIST;
            try {
                result = PolicyDecisionUtils.doResourceIPEnvAuth(indexName, organizationName, envMap);
            } catch (PolicyException pe) {
                // ignore, continue to default realm based authentication
                // may need to revisit this in the future
                authDebug.warning("AuthContextLocal.login() policy error " + "indexName=" + indexName, pe);
                type = null;
                indexName = null;
            }
            if (authDebug.messageEnabled()) {
                authDebug.message("AuthContextLocal.login: policy decision=" + result);
            }
            if (result.size() == 2) {
                type = (AuthContext.IndexType) result.get(0);
                indexName = (String) result.get(1);
            } else if (result.size() == 1) {
                // this is the redirection case (Policy Redirection Advice)
                redirectUrl = (String) result.get(0);
                // append goto parameter for federation case
                Set tmp = (Set) envMap.get(ISAuthConstants.GOTO_PARAM);
                if ((tmp != null) && !tmp.isEmpty()) {
                    String gotoParam = (String) tmp.iterator().next();
                    if ((gotoParam != null) && (gotoParam.length() != 0)) {
                        if ((redirectUrl != null) && (redirectUrl.indexOf("?") != -1)) {
                            redirectUrl = redirectUrl + "&" + ISAuthConstants.GOTO_PARAM + "=" + URLEncDec.encode(gotoParam);
                        } else {
                            redirectUrl = redirectUrl + "?" + ISAuthConstants.GOTO_PARAM + "=" + URLEncDec.encode(gotoParam);
                        }
                    }
                }
                type = null;
                indexName = null;
            } else {
                // no policy decision, use default realm login
                type = null;
                indexName = null;
            }
        }
        HashMap loginParamsMap = new HashMap();
        loginParamsMap.put(INDEX_TYPE, type);
        loginParamsMap.put(INDEX_NAME, indexName);
        loginParamsMap.put(PRINCIPAL, principal);
        loginParamsMap.put(PASSWORD, password);
        loginParamsMap.put(SUBJECT, subject);
        loginParamsMap.put(LOCALE, locale);
        if (redirectUrl != null) {
            loginParamsMap.put(REDIRECT_URL, redirectUrl);
        }
        if (authDebug.messageEnabled()) {
            authDebug.message("loginParamsMap : " + loginParamsMap.toString());
        }
        authDebug.message("calling AMLoginContext::exceuteLogin : ");
        amlc.executeLogin(loginParamsMap);
        authDebug.message("after AMLoginContext::exceuteLogin : ");
        if (amlc.getStatus() == LoginStatus.AUTH_SUCCESS) {
            loginStatus = AuthContext.Status.SUCCESS;
        } else if (amlc.getStatus() == LoginStatus.AUTH_FAILED) {
            loginStatus = AuthContext.Status.FAILED;
        }
        if (authDebug.messageEnabled()) {
            authDebug.message("Status at the end of login() : " + loginStatus);
        }
    } catch (AuthLoginException e) {
        if (authDebug.messageEnabled()) {
            authDebug.message("Exception in ac.login : " + e.toString());
        }
        throw e;
    }
}
Also used : Set(java.util.Set) PolicyException(com.sun.identity.policy.PolicyException) HashMap(java.util.HashMap) AuthContext(com.sun.identity.authentication.AuthContext) AuthLoginException(com.sun.identity.authentication.spi.AuthLoginException) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with PolicyException

use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.

the class PolicyModelImpl method getResponseProviderInstance.

private ResponseProvider getResponseProviderInstance(String realmName, String typeName) {
    ResponseProvider provider = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            ResponseProviderTypeManager mgr = policyMgr.getResponseProviderTypeManager();
            provider = mgr.getResponseProvider(typeName);
        }
    } catch (AMConsoleException e) {
        debug.warning("PolicyModelImpl.getResponseProviderInstance", e);
    } catch (NameNotFoundException e) {
        debug.warning("PolicyModelImpl.getResponseProviderInstance", e);
    } catch (PolicyException e) {
        debug.warning("PolicyModelImpl.getResponseProviderInstance", e);
    }
    return provider;
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) ResponseProviderTypeManager(com.sun.identity.policy.ResponseProviderTypeManager)

Example 3 with PolicyException

use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.

the class PolicyPropertyXMLBuilderBase method appendChoiceValues.

private void appendChoiceValues(String name, Syntax syntax, StringBuffer xml) {
    int syn = AMDisplayType.getDisplaySyntax(syntax);
    switch(syn) {
        case AMDisplayType.SYNTAX_SINGLE_CHOICE:
        case AMDisplayType.SYNTAX_MULTIPLE_CHOICE:
            try {
                Set validValues = getValidValues(name);
                if ((validValues != null) && !validValues.isEmpty()) {
                    Set sorted = new TreeSet(validValues);
                    for (Iterator iter = sorted.iterator(); iter.hasNext(); ) {
                        String val = (String) iter.next();
                        Object[] params = { val, val };
                        xml.append(MessageFormat.format(OPTION_TAG, params));
                    }
                }
            } catch (PolicyException e) {
                debug.warning("PolicyPropertyXMLBuilderBase.appendChoiceValues", e);
            }
            break;
    }
}
Also used : Set(java.util.Set) TreeSet(java.util.TreeSet) PolicyException(com.sun.identity.policy.PolicyException) TreeSet(java.util.TreeSet) Iterator(java.util.Iterator)

Example 4 with PolicyException

use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.

the class PolicyModelImpl method getDisplayNameForSubjectValues.

/**
     * Returns a map of values to localized label.
     *
     * @param realmName Name of realm.
     * @param subjectTypeName Name of Subject Type.
     * @param values Valid values.
     * @return a map of values to localized label.
     */
public Map getDisplayNameForSubjectValues(String realmName, String subjectTypeName, Set values) {
    Map map = null;
    if ((values != null) && !values.isEmpty()) {
        map = new HashMap(values.size() * 2);
        Locale locale = getUserLocale();
        try {
            PolicyManager policyMgr = getPolicyManager(realmName);
            if (policyMgr != null) {
                SubjectTypeManager subjectTypeMgr = policyMgr.getSubjectTypeManager();
                Subject subject = subjectTypeMgr.getSubject(subjectTypeName);
                for (Iterator i = values.iterator(); i.hasNext(); ) {
                    String v = (String) i.next();
                    map.put(v, subject.getDisplayNameForValue(v, locale));
                }
            }
        } catch (AMConsoleException e) {
            debug.warning("PolicyModelImpl.getDisplayNameForSubjectValues", e);
        } catch (NameNotFoundException e) {
            debug.warning("PolicyModelImpl.getDisplayNameForSubjectValues", e);
        } catch (PolicyException e) {
            debug.warning("PolicyModelImpl.getDisplayNameForSubjectValues", e);
        }
    }
    return (map == null) ? Collections.EMPTY_MAP : map;
}
Also used : Locale(java.util.Locale) PolicyManager(com.sun.identity.policy.PolicyManager) SubjectTypeManager(com.sun.identity.policy.SubjectTypeManager) HashMap(java.util.HashMap) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) Iterator(java.util.Iterator) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) Map(java.util.Map) HashMap(java.util.HashMap) Subject(com.sun.identity.policy.interfaces.Subject)

Example 5 with PolicyException

use of com.sun.identity.policy.PolicyException in project OpenAM by OpenRock.

the class PolicyModelImpl method getResponseProviderViewBeanURL.

/**
     * Returns properties view bean URL of a response provider.
     *
     * @param realmName Name of realm.
     * @param typeName Name of response provider Type.
     * @return properties view bean URL of a response provider.
     */
public String getResponseProviderViewBeanURL(String realmName, String typeName) {
    String url = null;
    try {
        PolicyManager policyMgr = getPolicyManager(realmName);
        if (policyMgr != null) {
            ResponseProviderTypeManager mgr = policyMgr.getResponseProviderTypeManager();
            ResponseProvider provider = mgr.getResponseProvider(typeName);
            url = mgr.getViewBeanURL(provider);
        }
    } catch (AMConsoleException e) {
        debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
    } catch (NameNotFoundException e) {
        debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
    } catch (PolicyException e) {
        debug.warning("PolicyModelImpl.getResponseProviderViewBeanURL", e);
    }
    return url;
}
Also used : PolicyManager(com.sun.identity.policy.PolicyManager) NameNotFoundException(com.sun.identity.policy.NameNotFoundException) PolicyException(com.sun.identity.policy.PolicyException) ResponseProvider(com.sun.identity.policy.interfaces.ResponseProvider) AMConsoleException(com.sun.identity.console.base.model.AMConsoleException) ResponseProviderTypeManager(com.sun.identity.policy.ResponseProviderTypeManager)

Aggregations

PolicyException (com.sun.identity.policy.PolicyException)151 SSOException (com.iplanet.sso.SSOException)64 HashSet (java.util.HashSet)63 Set (java.util.Set)57 Iterator (java.util.Iterator)50 PolicyManager (com.sun.identity.policy.PolicyManager)35 NameNotFoundException (com.sun.identity.policy.NameNotFoundException)32 HashMap (java.util.HashMap)28 Map (java.util.Map)27 AMConsoleException (com.sun.identity.console.base.model.AMConsoleException)26 ByteString (org.forgerock.opendj.ldap.ByteString)16 EntitlementException (com.sun.identity.entitlement.EntitlementException)14 LdapException (org.forgerock.opendj.ldap.LdapException)13 ResultCode (org.forgerock.opendj.ldap.ResultCode)13 Connection (org.forgerock.opendj.ldap.Connection)12 SearchResultEntry (org.forgerock.opendj.ldap.responses.SearchResultEntry)12 InvalidNameException (com.sun.identity.policy.InvalidNameException)11 ValidValues (com.sun.identity.policy.ValidValues)11 IOException (java.io.IOException)11 ConnectionEntryReader (org.forgerock.opendj.ldif.ConnectionEntryReader)11