Search in sources :

Example 1 with AMSearchControl

use of com.iplanet.am.sdk.AMSearchControl in project OpenAM by OpenRock.

the class DSAMERole method getValidValues.

/**
     * Returns a list of possible values for the <code>Subject
     * </code> that matches the pattern. 
     *
     * @param token the <code>SSOToken</code> that will be used
     * to determine the possible values
     *
     * @return <code>ValidValues</code> object
     *
     * @exception SSOException if SSO token is not valid
     * @exception PolicyException if unable to get the list of valid
     * names.
     */
public ValidValues getValidValues(SSOToken token, String pattern) throws SSOException, PolicyException {
    if (!initialized) {
        throw (new PolicyException(ResBundleUtils.rbName, "role_subject_not_yet_initialized", null, null));
    }
    try {
        AMStoreConnection amConnection = new AMStoreConnection(token);
        AMOrganization orgObject = amConnection.getOrganization(organizationDN);
        AMSearchControl sc = new AMSearchControl();
        sc.setMaxResults(maxResults);
        sc.setTimeOut(timeLimit);
        sc.setSearchScope(roleSearchScope);
        AMSearchResults results = orgObject.searchAllRoles(pattern, sc);
        int status;
        switch(results.getErrorCode()) {
            case AMSearchResults.SUCCESS:
                status = ValidValues.SUCCESS;
                break;
            case AMSearchResults.SIZE_LIMIT_EXCEEDED:
                status = ValidValues.SIZE_LIMIT_EXCEEDED;
                break;
            case AMSearchResults.TIME_LIMIT_EXCEEDED:
                status = ValidValues.TIME_LIMIT_EXCEEDED;
                break;
            default:
                status = ValidValues.SUCCESS;
        }
        return new ValidValues(status, results.getSearchResults());
    } catch (AMException e) {
        LdapException lde = e.getLDAPException();
        if (lde != null) {
            ResultCode ldapErrorCode = lde.getResult().getResultCode();
            if (ResultCode.INVALID_CREDENTIALS.equals(ldapErrorCode)) {
                throw new PolicyException(ResBundleUtils.rbName, "ldap_invalid_password", null, null);
            } else if (ResultCode.NO_SUCH_OBJECT.equals(ldapErrorCode)) {
                String[] objs = { organizationDN };
                throw new PolicyException(ResBundleUtils.rbName, "no_such_am_roles_base_dn", objs, null);
            }
            String errorMsg = lde.getResult().getDiagnosticMessage();
            String additionalMsg = lde.getResult().getResultCode().getName().toString(Locale.ROOT);
            if (additionalMsg != null) {
                throw new PolicyException(errorMsg + ": " + additionalMsg);
            } else {
                throw new PolicyException(errorMsg);
            }
        }
        throw new PolicyException(e);
    }
}
Also used : AMStoreConnection(com.iplanet.am.sdk.AMStoreConnection) AMSearchControl(com.iplanet.am.sdk.AMSearchControl) PolicyException(com.sun.identity.policy.PolicyException) ValidValues(com.sun.identity.policy.ValidValues) AMOrganization(com.iplanet.am.sdk.AMOrganization) AMException(com.iplanet.am.sdk.AMException) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) LdapException(org.forgerock.opendj.ldap.LdapException) ResultCode(org.forgerock.opendj.ldap.ResultCode)

Example 2 with AMSearchControl

use of com.iplanet.am.sdk.AMSearchControl in project OpenAM by OpenRock.

the class AMClientCapData method getMinimalClientInfo.

/**
     * Demand Load stuff
     */
/**
     * Gets a minimal set of client properties for all clients.
     * 
     * @return Set of Maps. Each Map has the propertyNames for the Key and Value
     *         is Set of Property values. By default, the keys returned are
     *         clientType, userAgent & parentID.
     */
public Set getMinimalClientInfo() {
    Set clients = new HashSet();
    AMSearchControl amsrchCntrl = new AMSearchControl();
    amsrchCntrl.setReturnAttributes(minClient);
    try {
        long st = System.currentTimeMillis();
        AMSearchResults results = amClientOrg.searchEntities("*", amsrchCntrl, null, UMS_SRCH_TEMPLATE_NAME);
        long end = System.currentTimeMillis();
        if (debug.messageEnabled()) {
            debug.message(dbStr + "getMinimalClientInfo() Srch Time (ms) = " + (end - st));
        }
        st = System.currentTimeMillis();
        Map m = results.getResultAttributes();
        Iterator keys = m.keySet().iterator();
        while (keys.hasNext()) {
            String dn = (String) keys.next();
            Map attrsMap = (Map) m.get(dn);
            Map data = parsePropertyNames(attrsMap);
            clients.add(data);
        }
        end = System.currentTimeMillis();
        if (debug.messageEnabled()) {
            debug.message(dbStr + "getMinimalClientInfo() Parse Time (ms) = " + (end - st));
        }
    } catch (Exception e) {
        debug.error(dbStr + " getMinimalClientInfo(): Search Error: ", e);
    }
    return clients;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) AMSearchControl(com.iplanet.am.sdk.AMSearchControl) Iterator(java.util.Iterator) AMSearchResults(com.iplanet.am.sdk.AMSearchResults) HashMap(java.util.HashMap) Map(java.util.Map) SSOException(com.iplanet.sso.SSOException) HashSet(java.util.HashSet)

Aggregations

AMSearchControl (com.iplanet.am.sdk.AMSearchControl)2 AMSearchResults (com.iplanet.am.sdk.AMSearchResults)2 AMException (com.iplanet.am.sdk.AMException)1 AMOrganization (com.iplanet.am.sdk.AMOrganization)1 AMStoreConnection (com.iplanet.am.sdk.AMStoreConnection)1 SSOException (com.iplanet.sso.SSOException)1 PolicyException (com.sun.identity.policy.PolicyException)1 ValidValues (com.sun.identity.policy.ValidValues)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 Map (java.util.Map)1 Set (java.util.Set)1 LdapException (org.forgerock.opendj.ldap.LdapException)1 ResultCode (org.forgerock.opendj.ldap.ResultCode)1