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");
}
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);
}
}
Aggregations