Search in sources :

Example 1 with AMInvalidDNException

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

the class DirectoryServicesImpl method getObjectType.

/**
     * Gets the type of the object given its DN.
     * 
     * @param token
     *            token a valid SSOToken
     * @param dn
     *            DN of the object whose type is to be known.
     * @param cachedAttributes
     *            cached attributes of the user
     * 
     * @throws AMException
     *             if the data store is unavailable or if the object type is
     *             unknown
     * @throws SSOException
     *             if ssoToken is invalid or expired.
     */
public int getObjectType(SSOToken token, String dn, Map cachedAttributes) throws AMException, SSOException {
    if (debug.messageEnabled()) {
        debug.message("DirectoryServicesImpl.getObjectType() Getting " + "object type for: " + dn);
    }
    if (!LDAPUtils.isDN(dn)) {
        throw new AMInvalidDNException(AMSDKBundle.getString("157"), "157");
    }
    SSOTokenManager.getInstance().validateToken(token);
    Set objectClasses = null;
    // Check if object classes are cached, if not get from directory
    if (cachedAttributes == null || (objectClasses = (Set) cachedAttributes.get("objectclass")) == null) {
        if (debug.messageEnabled()) {
            debug.message("DirectoryServicesImpl.getObjectType() Making " + " LDAP call to get objectclass attributes for DN: " + dn);
        }
        Set attrNames = new HashSet(1);
        attrNames.add("objectclass");
        Map attributes = getAttributes(token, dn, attrNames, AMObject.UNDETERMINED_OBJECT_TYPE);
        if (attributes.size() == 1) {
            objectClasses = (Set) attributes.get("objectclass");
        }
    }
    // Determine the object type
    if (objectClasses != null) {
        if (debug.messageEnabled()) {
            debug.message("DirectoryServicesImpl.getObjectType()- DN: " + dn + " cachedAttributes: " + objectClasses);
        }
        Iterator itr = objectClasses.iterator();
        int possibleOT = -1;
        while (itr.hasNext()) {
            String tStr = (String) itr.next();
            int objectType = getObjectType(tStr);
            if (objectType == AMObject.ROLE) {
                possibleOT = objectType;
                continue;
            } else if (objectType != AMObject.UNKNOWN_OBJECT_TYPE) {
                if (debug.messageEnabled()) {
                    debug.message("DirectoryServicesImpl.getObjectType(" + "token, entryDN, cachedAttributes)- DN: " + dn + " objectType: " + objectType);
                }
                return objectType;
            }
        }
        if (possibleOT != -1) {
            if (debug.messageEnabled()) {
                debug.message("DirectoryServicesImpl.getObjectType(" + "token, entryDN, cachedAttributes)- DN: " + dn + " objectType: " + possibleOT);
            }
            return possibleOT;
        }
        throw new AMException(AMSDKBundle.getString("156"), "156");
    }
    throw new AMException(AMSDKBundle.getString("151"), "151");
}
Also used : Set(java.util.Set) OrderedSet(com.sun.identity.shared.datastruct.OrderedSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) AttrSet(com.iplanet.services.ldap.AttrSet) AMInvalidDNException(com.iplanet.am.sdk.AMInvalidDNException) Iterator(java.util.Iterator) AMException(com.iplanet.am.sdk.AMException) Map(java.util.Map) AMHashMap(com.iplanet.am.sdk.AMHashMap) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) HashSet(java.util.HashSet)

Example 2 with AMInvalidDNException

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

the class AMUserPasswordValidationPlugin method validateUserID.

/**
     * Checks for invalid characters in the source string
     * 
     * @param userID
     *            source string which should be validated
     * @param envParams
     *            parameters for which the userID validation is enforced.
     * @throws throws
     *             AMException when it detects specified pattern within source
     *             string which need to be validated OR if source string is null
     */
public void validateUserID(String userID, Map envParams) throws AMException {
    StringBuilder errorString = new StringBuilder(10);
    SSOToken token = (SSOToken) AccessController.doPrivileged(AdminTokenAction.getInstance());
    String orgDN = (String) envParams.get(com.sun.identity.shared.Constants.ORGANIZATION_NAME);
    String regEx = getOrgUserInvalidChars(orgDN, token);
    if (userID == null || userID.length() == 0) {
        debug.error("AMUserPasswordValidationPlugin." + "validateUserID() : Source string is null or empty" + userID);
        throw new AMInvalidDNException(AMSDKBundle.getString("157"), "157");
    }
    if (regEx == null || regEx.length() == 0) {
        debug.error("AMUserPasswordValidationPlugin." + "validateUserID() : List of invalid characters is null " + "or empty" + regEx);
        throw new AMInvalidDNException(AMSDKBundle.getString("157"), "157");
    }
    StringTokenizer st = new StringTokenizer(regEx, SEPERATOR);
    while (st.hasMoreTokens()) {
        String obj = st.nextToken();
        if (userID.indexOf(obj) > -1) {
            debug.error("AMUserPasswordValidationPlugin." + "validateUserID() : Detected invalid chars ...");
            debug.error("AMUserPasswordValidationPlugin." + "validateUserID() : User Name validation Failed:" + obj);
            errorString.append(obj).append(" ");
        }
    }
    Object[] args = { userID, errorString.toString() };
    if (errorString.length() != 0) {
        throw new AMException(AMSDKBundle.getString("1002", args), "1002", args);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) SSOToken(com.iplanet.sso.SSOToken) AMInvalidDNException(com.iplanet.am.sdk.AMInvalidDNException) AMException(com.iplanet.am.sdk.AMException)

Aggregations

AMException (com.iplanet.am.sdk.AMException)2 AMInvalidDNException (com.iplanet.am.sdk.AMInvalidDNException)2 AMHashMap (com.iplanet.am.sdk.AMHashMap)1 AttrSet (com.iplanet.services.ldap.AttrSet)1 SSOToken (com.iplanet.sso.SSOToken)1 OrderedSet (com.sun.identity.shared.datastruct.OrderedSet)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 StringTokenizer (java.util.StringTokenizer)1 TreeMap (java.util.TreeMap)1 TreeSet (java.util.TreeSet)1