use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.
the class DJLDAPv3Repo method initialize.
/**
* Initializes the IdRepo instance, basically within this method we process
* the configuration settings and set up the connection factories that will
* be used later in the lifetime of the IdRepo plugin.
*
* @param configParams The IdRepo configuration as defined in the service
* configurations.
* @throws IdRepoException Shouldn't be thrown.
*/
@Override
public void initialize(Map<String, Set<String>> configParams) throws IdRepoException {
if (DEBUG.messageEnabled()) {
DEBUG.message("initialize invoked");
}
super.initialize(configParams);
String hostServerId = null;
String hostSiteId = "";
try {
hostServerId = WebtopNaming.getAMServerID();
hostSiteId = WebtopNaming.getSiteID(hostServerId);
} catch (ServerEntryNotFoundException senfe) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("ServerEntryNotFoundException, hostServerId=" + hostServerId + ", hostSiteId=" + hostSiteId);
}
}
dnCacheEnabled = CollectionHelper.getBooleanMapAttr(configMap, LDAP_DNCACHE_ENABLED, true);
if (dnCacheEnabled) {
dnCache = new Cache(CollectionHelper.getIntMapAttr(configParams, LDAP_DNCACHE_SIZE, 1500, DEBUG));
}
ldapServers = LDAPUtils.prioritizeServers(configParams.get(LDAP_SERVER_LIST), hostServerId, hostSiteId);
defaultSizeLimit = CollectionHelper.getIntMapAttr(configParams, LDAP_MAX_RESULTS, 100, DEBUG);
defaultTimeLimit = CollectionHelper.getIntMapAttr(configParams, LDAP_TIME_LIMIT, 5, DEBUG);
int maxPoolSize = CollectionHelper.getIntMapAttr(configParams, LDAP_CONNECTION_POOL_MAX_SIZE, 10, DEBUG);
String username = CollectionHelper.getMapAttr(configParams, LDAP_SERVER_USER_NAME);
char[] password = CollectionHelper.getMapAttr(configParams, LDAP_SERVER_PASSWORD, "").toCharArray();
heartBeatInterval = CollectionHelper.getIntMapAttr(configParams, LDAP_SERVER_HEARTBEAT_INTERVAL, "10", DEBUG);
heartBeatTimeUnit = CollectionHelper.getMapAttr(configParams, LDAP_SERVER_HEARTBEAT_TIME_UNIT, "SECONDS");
String connectionMode = CollectionHelper.getMapAttr(configParams, LDAP_CONNECTION_MODE);
useStartTLS = LDAP_CONNECTION_MODE_STARTTLS.equalsIgnoreCase(connectionMode);
isSecure = LDAP_CONNECTION_MODE_LDAPS.equalsIgnoreCase(connectionMode) || useStartTLS;
bindConnectionFactory = createConnectionFactory(null, null, maxPoolSize);
connectionFactory = createConnectionFactory(username, password, maxPoolSize);
supportedTypesAndOperations = IdRepoUtils.parseSupportedTypesAndOperations(configParams.get(LDAP_SUPPORTED_TYPES_AND_OPERATIONS));
userStatusAttr = CollectionHelper.getMapAttr(configParams, LDAP_USER_STATUS_ATTR_NAME);
if (userStatusAttr == null || userStatusAttr.isEmpty()) {
alwaysActive = true;
userStatusAttr = DEFAULT_USER_STATUS_ATTR;
}
activeValue = CollectionHelper.getMapAttr(configParams, LDAP_STATUS_ACTIVE, STATUS_ACTIVE);
inactiveValue = CollectionHelper.getMapAttr(configParams, LDAP_STATUS_INACTIVE, STATUS_INACTIVE);
creationAttributeMapping = IdRepoUtils.parseAttributeMapping(configParams.get(LDAP_CREATION_ATTR_MAPPING));
userNamingAttr = CollectionHelper.getMapAttr(configParams, LDAP_USER_NAMING_ATTR);
groupNamingAttr = CollectionHelper.getMapAttr(configParams, LDAP_GROUP_NAMING_ATTR);
roleNamingAttr = CollectionHelper.getMapAttr(configParams, LDAP_ROLE_NAMING_ATTR);
filteredRoleNamingAttr = CollectionHelper.getMapAttr(configParams, LDAP_FILTERED_ROLE_NAMING_ATTR);
userSearchAttr = CollectionHelper.getMapAttr(configParams, LDAP_USER_SEARCH_ATTR);
userAttributesAllowed = new CaseInsensitiveHashSet();
Set<String> allowAttrs = configParams.get(LDAP_USER_ATTRS);
if (allowAttrs != null) {
userAttributesAllowed.addAll(allowAttrs);
}
groupAttributesAllowed = new CaseInsensitiveHashSet();
allowAttrs = configParams.get(LDAP_GROUP_ATTRS);
if (allowAttrs != null) {
groupAttributesAllowed.addAll(allowAttrs);
}
roleAttributesAllowed = new CaseInsensitiveHashSet();
allowAttrs = configParams.get(LDAP_ROLE_ATTRS);
if (allowAttrs != null) {
roleAttributesAllowed.addAll(allowAttrs);
}
filteredRoleAttributesAllowed = new CaseInsensitiveHashSet();
allowAttrs = configParams.get(LDAP_FILTERED_ROLE_ATTRS);
if (allowAttrs != null) {
filteredRoleAttributesAllowed.addAll(allowAttrs);
}
userObjectClasses = getNonNullSettingValues(LDAP_USER_OBJECT_CLASS);
groupObjectClasses = getNonNullSettingValues(LDAP_GROUP_OBJECT_CLASS);
roleObjectClasses = getNonNullSettingValues(LDAP_ROLE_OBJECT_CLASS);
filteredRoleObjectClasses = getNonNullSettingValues(LDAP_FILTERED_ROLE_OBJECT_CLASS);
defaultGroupMember = CollectionHelper.getMapAttr(configParams, LDAP_DEFAULT_GROUP_MEMBER);
uniqueMemberAttr = CollectionHelper.getMapAttr(configParams, LDAP_UNIQUE_MEMBER, UNIQUE_MEMBER_ATTR);
memberURLAttr = CollectionHelper.getMapAttr(configParams, LDAP_MEMBER_URL);
memberOfAttr = CollectionHelper.getMapAttr(configParams, LDAP_MEMBER_OF);
peopleContainerName = CollectionHelper.getMapAttr(configParams, LDAP_PEOPLE_CONTAINER_NAME);
peopleContainerValue = CollectionHelper.getMapAttr(configParams, LDAP_PEOPLE_CONTAINER_VALUE);
groupContainerName = CollectionHelper.getMapAttr(configParams, LDAP_GROUP_CONTAINER_NAME);
groupContainerValue = CollectionHelper.getMapAttr(configParams, LDAP_GROUP_CONTAINER_VALUE);
roleAttr = CollectionHelper.getMapAttr(configParams, LDAP_ROLE_ATTR, ROLE_ATTR);
roleDNAttr = CollectionHelper.getMapAttr(configParams, LDAP_ROLE_DN_ATTR, ROLE_DN_ATTR);
roleFilterAttr = CollectionHelper.getMapAttr(configParams, LDAP_ROLE_FILTER_ATTR, ROLE_FILTER_ATTR);
rootSuffix = CollectionHelper.getMapAttr(configParams, LDAP_SERVER_ROOT_SUFFIX);
userSearchFilter = LDAPUtils.parseFilter(CollectionHelper.getMapAttr(configParams, LDAP_USER_SEARCH_FILTER), Filter.objectClassPresent());
groupSearchFilter = LDAPUtils.parseFilter(CollectionHelper.getMapAttr(configParams, LDAP_GROUP_SEARCH_FILTER), Filter.objectClassPresent());
roleSearchFilter = LDAPUtils.parseFilter(CollectionHelper.getMapAttr(configParams, LDAP_ROLE_SEARCH_FILTER), DEFAULT_ROLE_SEARCH_FILTER);
filteredRoleSearchFilter = LDAPUtils.parseFilter(CollectionHelper.getMapAttr(configParams, LDAP_FILTERED_ROLE_SEARCH_FILTER), DEFAULT_FILTERED_ROLE_SEARCH_FILTER);
String serviceInfo = CollectionHelper.getMapAttr(configParams, LDAP_SERVICE_ATTRS);
serviceMap = new HashMap<String, Map<String, Set<String>>>(new SOAPClient("dummy").decodeMap(serviceInfo));
defaultScope = LDAPUtils.getSearchScope(CollectionHelper.getMapAttr(configParams, LDAP_SEARCH_SCOPE), SearchScope.WHOLE_SUBTREE);
roleScope = LDAPUtils.getSearchScope(CollectionHelper.getMapAttr(configParams, LDAP_ROLE_SEARCH_SCOPE), SearchScope.WHOLE_SUBTREE);
if (configParams.containsKey(LDAP_ADAM_TYPE)) {
helper = new ADAMHelper();
} else if (configParams.containsKey(LDAP_AD_TYPE)) {
helper = new ADHelper();
} else {
helper = new DirectoryHelper();
}
if (DEBUG.messageEnabled()) {
DEBUG.message("IdRepo configuration:\n" + IdRepoUtils.getAttrMapWithoutPasswordAttrs(configMap, asSet(LDAP_SERVER_PASSWORD)));
}
}
use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.
the class DJLDAPv3Repo method removeUndefinedAttributes.
private Set<String> removeUndefinedAttributes(IdType type, Set<String> attributes) {
Set<String> predefinedAttrs = getDefinedAttributes(type);
Set<String> filteredSet = Collections.EMPTY_SET;
if (attributes != null) {
filteredSet = new CaseInsensitiveHashSet(attributes);
}
filteredSet.retainAll(predefinedAttrs);
return filteredSet;
}
use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.
the class DJLDAPv3Repo method getAssignedServices.
/**
* Returns the currently assigned to the given identity.
* In case of a USER this will retrieve the objectclasses defined for this user, and based on the provided
* mapOfServicesAndOCs if all of the objectclasses mapped to a service is present, only then will the service be
* added to the resulting list.
* In case of a REALM the locally stored serviceMap's keySet will be returned, since that contains all the different
* service names defined within this realm.
*
* @param token Not used.
* @param type The type of the identity, this should be always USER or REALM.
* @param name The name of the identity. Only used when identity type is USER.
* @param mapOfServicesAndOCs A mapping between the names of services and the corresponding objectclasses.
* @return The list of services that are currently assigned to the identity.
* @throws IdRepoException If the identity type was invalid, or if there was an error while retrieving the
* objectclasses.
*/
@Override
public Set<String> getAssignedServices(SSOToken token, IdType type, String name, Map<String, Set<String>> mapOfServicesAndOCs) throws IdRepoException {
if (DEBUG.messageEnabled()) {
DEBUG.message("getAssignedServices invoked");
}
Set<String> results = new HashSet<String>();
if (type.equals(IdType.USER)) {
Set<String> attrs = asSet("objectclass");
Set<String> objectClasses = getAttributes(token, type, name, attrs).get(OBJECT_CLASS_ATTR);
if (objectClasses != null) {
objectClasses = new CaseInsensitiveHashSet(objectClasses);
}
for (Map.Entry<String, Set<String>> entry : mapOfServicesAndOCs.entrySet()) {
String serviceName = entry.getKey();
Set<String> serviceOCs = entry.getValue();
if (objectClasses != null && objectClasses.containsAll(serviceOCs)) {
results.add(serviceName);
}
}
} else if (type.equals(IdType.REALM)) {
results.addAll(serviceMap.keySet());
} else {
throw new IdRepoUnsupportedOpException(IdRepoBundle.BUNDLE_NAME, IdRepoErrorCode.SERVICES_NOT_SUPPORTED_FOR_AGENTS_AND_GROUPS, new Object[] { CLASS_NAME });
}
if (DEBUG.messageEnabled()) {
DEBUG.message("Assigned services returned: " + results);
}
return results;
}
use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.
the class DJLDAPv3Repo method setAttributes.
/**
* Sets the provided attributes (string or binary) for the given identity. The following steps will be performed
* prior to modification:
* <ul>
* <li>The password will be encoded in case we are dealing with AD.</li>
* <li>Anything related to undefined attributes will be ignored.</li>
* <li>If the attribute map contains the default status attribute, then it will be converted to the status value
* specified in the configuration.</li>
* <li>In case changeOCs is set to <code>true</code>, the method will traverse through all the defined
* objectclasses to see if there is any attribute in the attributes map that is defined by that objectclass.
* These objectclasses will be collected and will be part of the modificationset with the other changes.</li>
* </ul>
* The attributes will be translated to modifications based on the followings:
* <ul>
* <li>If the attribute has no values in the map, it will be considered as an attribute DELETE.</li>
* <li>In any other case based on the value of isAdd parameter, it will be either ADD, or REPLACE.</li>
* </ul>
*
* @param token Not used.
* @param type The type of the identity.
* @param name The name of the identity.
* @param attributes The attributes that needs to be set for the entry.
* @param isAdd <code>true</code> if the attributes should be ADDed, <code>false</code> if the attributes should be
* REPLACEd instead.
* @param isString Whether the provided attributes are in string or binary format.
* @param changeOCs Whether the module should adjust the objectclasses for the entry or not.
* @throws IdRepoException Can be thrown in the following cases:
* <ul>
* <li>the identity cannot be found,</li>
* <li>there was a problem while retrieving the current user status from the directory (AD),</li>
* <li>there are no modifications to actually perform,</li>
* <li>there was an error while retrieving the objectClass attribute,</li>
* <li>there was an error while trying to read the directory schema,</li>
* <li>there was an error while trying to perform the modifications.</li>
* </ul>
*/
private void setAttributes(SSOToken token, IdType type, String name, Map attributes, boolean isAdd, boolean isString, boolean changeOCs) throws IdRepoException {
ModifyRequest modifyRequest = LDAPRequests.newModifyRequest(getDN(type, name));
attributes = removeUndefinedAttributes(type, attributes);
if (type.equals(IdType.USER)) {
Object status = attributes.get(DEFAULT_USER_STATUS_ATTR);
if (status != null && !attributes.containsKey(userStatusAttr)) {
String value = null;
if (status instanceof Set) {
value = ((Set<String>) status).iterator().next();
} else if (status instanceof byte[][]) {
value = new String(((byte[][]) status)[0], Charset.forName("UTF-8"));
}
value = helper.getStatus(this, name, !STATUS_INACTIVE.equals(value), userStatusAttr, activeValue, inactiveValue);
attributes.remove(DEFAULT_USER_STATUS_ATTR);
if (isString) {
attributes.put(userStatusAttr, asSet(value));
} else {
byte[][] binValue = new byte[1][];
binValue[0] = value.getBytes(Charset.forName("UTF-8"));
attributes.put(userStatusAttr, binValue);
}
}
}
for (Map.Entry<String, Object> entry : (Set<Map.Entry<String, Object>>) attributes.entrySet()) {
Object values = entry.getValue();
String attrName = entry.getKey();
Attribute attr = new LinkedAttribute(attrName);
if (AD_UNICODE_PWD_ATTR.equalsIgnoreCase(attrName)) {
if (values instanceof byte[][]) {
attr.add(ByteString.valueOfBytes(helper.encodePassword(IdType.USER, (byte[][]) values)));
} else {
attr.add(ByteString.valueOfBytes(helper.encodePassword(IdType.USER, (Set) values)));
}
} else if (values instanceof byte[][]) {
for (byte[] bytes : (byte[][]) values) {
attr.add(ByteString.valueOfBytes(bytes));
}
} else if (values instanceof Set) {
for (String value : (Set<String>) values) {
attr.add(value);
}
}
if (attr.isEmpty()) {
modifyRequest.addModification(new Modification(ModificationType.REPLACE, attr));
} else {
modifyRequest.addModification(new Modification(isAdd ? ModificationType.ADD : ModificationType.REPLACE, attr));
}
}
if (modifyRequest.getModifications().isEmpty()) {
if (DEBUG.messageEnabled()) {
DEBUG.message("setAttributes: there are no modifications to perform");
}
throw newIdRepoException(IdRepoErrorCode.ILLEGAL_ARGUMENTS);
}
if (type.equals(IdType.USER) && changeOCs) {
Set<String> missingOCs = new CaseInsensitiveHashSet();
Map<String, Set<String>> attrs = getAttributes(token, type, name, asSet(OBJECT_CLASS_ATTR));
Set<String> ocs = attrs.get(OBJECT_CLASS_ATTR);
//to missingOCs
if (ocs != null) {
missingOCs.addAll(getObjectClasses(type));
missingOCs.removeAll(ocs);
}
//if the missingOCs is not empty (i.e. there are objectclasses that are not present in the entry yet)
if (!missingOCs.isEmpty()) {
Object obj = attributes.get(OBJECT_CLASS_ATTR);
//if the API user has also added some of his objectclasses, then let's remove those from missingOCs
if (obj != null && obj instanceof Set) {
missingOCs.removeAll((Set<String>) obj);
}
//for every single objectclass that needs to be added, let's check if they contain an attribute that we
//wanted to add to the entry.
Set<String> newOCs = new HashSet<String>(2);
Schema dirSchema = getSchema();
for (String objectClass : missingOCs) {
try {
ObjectClass oc = dirSchema.getObjectClass(objectClass);
//we should never add new structural objectclasses, see RFC 4512
if (!oc.getObjectClassType().equals(ObjectClassType.STRUCTURAL)) {
for (String attrName : (Set<String>) attributes.keySet()) {
//before we start to add too many objectclasses here...
if (!attrName.equalsIgnoreCase(OBJECT_CLASS_ATTR) && oc.isRequiredOrOptional(dirSchema.getAttributeType(attrName))) {
newOCs.add(objectClass);
break;
}
}
}
} catch (UnknownSchemaElementException usee) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("Unable to find a schema element: " + usee.getMessage());
}
}
}
missingOCs = newOCs;
//it is possible that none of the missing objectclasses are actually covering any new attributes
if (!missingOCs.isEmpty()) {
//based on these let's add the extra objectclasses to the modificationset
modifyRequest.addModification(new Modification(ModificationType.ADD, new LinkedAttribute(OBJECT_CLASS_ATTR, missingOCs)));
}
}
}
Connection conn = null;
try {
conn = connectionFactory.getConnection();
conn.modify(modifyRequest);
} catch (LdapException ere) {
DEBUG.error("An error occured while setting attributes for identity: " + name, ere);
handleErrorResult(ere);
} finally {
IOUtils.closeIfNotNull(conn);
}
}
use of com.sun.identity.common.CaseInsensitiveHashSet in project OpenAM by OpenRock.
the class IdRemoteServicesImpl method getFullyQualifiedNames.
public Set getFullyQualifiedNames(SSOToken token, IdType type, String name, String org) throws IdRepoException, SSOException {
Set answer = null;
try {
Object[] objs = { getTokenString(token), type.getName(), name, org };
Set set = (Set) client.send(client.encodeMessage("getFullyQualifiedNames_idrepo", objs), sessionCookies.getLBCookie(token.getTokenID().toString()), null);
if (set != null) {
// Convert to CaseInsensitiveHashSet
answer = new CaseInsensitiveHashSet(set);
}
} catch (Exception ex) {
if (DEBUG.warningEnabled()) {
DEBUG.warning("IdRemoteServicesImpl.getFullyQualifiedNames_idrepo: " + "caught exception=", ex);
}
if (ex instanceof IdRepoException) {
throw ((IdRepoException) ex);
}
throw new IdRepoException(AMSDKBundle.getString("1000"), "1000");
}
return (answer);
}
Aggregations