use of org.forgerock.opendj.ldap.DN in project OpenAM by OpenRock.
the class AMServiceUtils method getOrgConfig.
/**
* Get organization config for the service
*
* @param token
* SSOToken
* @param orgDN
* DN of the org or org unit
* @param serviceName
* Service Name
* @return ServiceConfig of the organization for the service
*/
public static ServiceConfig getOrgConfig(SSOToken token, String orgDN, String serviceName) throws SSOException, AMException {
try {
ServiceConfigManager scm = new ServiceConfigManager(serviceName, token);
ServiceConfig sc = scm.getOrganizationConfig(orgDN, null);
DN theOrgDN = DN.valueOf(orgDN);
if (theOrgDN.equals(DN.valueOf(SMSEntry.getAMSdkBaseDN())) && sc != null) {
Map avPair = sc.getAttributes();
Set subConfigs = sc.getSubConfigNames();
if (avPair.isEmpty() && (subConfigs == null || subConfigs.isEmpty())) {
return null;
}
}
return sc;
} catch (ServiceNotFoundException ex) {
Object[] args = { serviceName };
String locale = AMCommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString("481", args, locale), "481", args);
} catch (ServiceAlreadyExistsException ex) {
Object[] args = { serviceName };
String locale = AMCommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString("479", args, locale), "479", args);
} catch (SMSException ex) {
Object[] args = { serviceName };
String locale = AMCommonUtils.getUserLocale(token);
throw new AMException(AMSDKBundle.getString("482", args, locale), "482", args);
}
}
use of org.forgerock.opendj.ldap.DN in project OpenAM by OpenRock.
the class AMUserImpl method getAllRoleDNs.
/**
* Gets all the static and filtered roles the user is in.
*
* @return The Set of static and filtered role DN's the user is in.
*/
public Set getAllRoleDNs() throws AMException, SSOException {
Set nsroleANSet = new HashSet(1);
nsroleANSet.add(nsroleAN);
Map nsrolesMap = getAttributesFromDataStore(nsroleANSet);
Set nsroles = (Set) nsrolesMap.get(nsroleAN);
Set result = new HashSet();
Iterator iter = nsroles.iterator();
getAMStoreConnection();
while (iter.hasNext()) {
String nsrole = (String) iter.next();
DN nsroleDN = DN.valueOf(nsrole);
RDN rdn = nsroleDN.rdn();
if (!rdn.equals(ContainerDefaultTemplateRoleRDN) && isAMManagedRole(nsrole)) {
result.add(nsroleDN.toString());
}
}
return result;
}
use of org.forgerock.opendj.ldap.DN in project OpenAM by OpenRock.
the class AssignableDynamicGroup method addMember.
/**
* Adds a member to the group. The change is saved to persistent storage.
*
* @param member Object to be added as member.
* @exception UMSException if fail to save to persistent storage or if the
* user is not within the scope of the group.
*
* @supported.api
*/
public void addMember(PersistentObject member) throws UMSException {
// check whether the userGuid is within the scope of memberUrl
DN userDN = DN.valueOf(member.getGuid().getDn());
LDAPUrl memberUrl = getUrl();
DN memberDN = memberUrl.getName();
if (!userDN.isInScopeOf(memberDN, SearchScope.WHOLE_SUBTREE)) {
String[] args = new String[2];
args[0] = userDN.toString();
args[1] = memberUrl.toString();
throw new UMSException(i18n.getString(IUMSConstants.USER_NOT_IN_GROUP_SCOPE, args));
} else if ((userDN.size() - memberDN.size()) > 1 && SearchScope.SINGLE_LEVEL.equals(memberUrl.getScope())) {
String[] args = new String[2];
args[0] = userDN.toString();
args[1] = memberUrl.toString();
throw new UMSException(i18n.getString(IUMSConstants.USER_NOT_IN_GROUP_SCOPE, args));
}
member.modify(new Attr(MEMBER_ATTR_NAME, this.getDN()), ModificationType.ADD);
member.save();
}
use of org.forgerock.opendj.ldap.DN in project OpenAM by OpenRock.
the class ConfigManagerUMS method getConfigData.
/**
* Config management.
*
* @param guid GUID it is looking under.
* @param name Name for which AttrSets are needed.
* @param template Template name (<code>StructureTemplates</code>, etc.)
* @return either an <code>AttrSet</code> or a collection depending on
* caller.
*/
private Object getConfigData(Guid guid, String name, String template, int lookup) throws ConfigManagerException {
// if guid is null, replace it use the rootDN
if (guid == null)
guid = new Guid(_rootDN);
// if guid is not "o=...", find the organization guid
/*
* if (!guid.getDn().startsWith("o=")) { guid =
* GuidUtils.getOrgGuid(guid); }
*/
DN dn = DN.valueOf(guid.getDn());
// traverse the tree in the cache
while (true) {
String fdn = _rootDN;
boolean inCache = false;
boolean checkedDS = false;
String cacheKey = null;
//
// Explode the guid and build a string delimited by "/".
// ex: guid->o=b,o=a fdn->/b/a
// Build the cache key as fdn + name
// ex: /b/a/com.iplanet.ums.organization
// or /b/a/BasicUser
fdn = dn.toString().toLowerCase();
// Special case Cache Key for OBJECTRESOLVER
if (template.equals(OBJECTRESOLVER))
cacheKey = OBJECTRESOLVERPATH;
else
cacheKey = fdn + "/" + template + "/" + name;
if (_debug.messageEnabled())
_debug.message("ConfigManager->getConfigData: fdn=" + fdn + " cacheKey=" + cacheKey);
//
// Check the cache for the entry.
// If it's in the cache, return the information.
//
inCache = _cch.containsKey(cacheKey);
if (inCache) {
if (_debug.messageEnabled()) {
_debug.message("ConfigManager->getConfigData: get from " + "cache for " + dn);
}
return _cch.get(cacheKey);
}
//
// If it's not in the cache, check if we've looked in the
// DS already. If we haven't checked the DS, go to the DS.
// "updateCache" will get the info from the DS and update
// both the cache (_cch) and _checkListCache.
//
checkedDS = _checkListCache.containsKey(fdn.toLowerCase());
if (!checkedDS) {
if (_debug.messageEnabled())
_debug.message("ConfigManager->getConfigData: updating " + "cache for " + dn);
synchronized (lock_cch) {
updateCache(fdn);
}
if (_cch.containsKey(cacheKey))
return _cch.get(cacheKey);
}
// Check if we need to traverse to the parent
switch(lookup) {
case TemplateManager.SCOPE_ORG:
return null;
case TemplateManager.SCOPE_TOP:
dn = DN.valueOf(_rootDN);
break;
case TemplateManager.SCOPE_ANCESTORS:
dn = dn.parent();
// if (dn.toString().length() == 0) return null;
if (dn.isInScopeOf(_root, SearchScope.WHOLE_SUBTREE)) {
break;
} else {
return null;
}
}
if (_debug.messageEnabled())
_debug.message("ConfigManager->getConfigData: Traversing " + "parent: " + dn);
}
}
use of org.forgerock.opendj.ldap.DN in project OpenAM by OpenRock.
the class ConfigManagerUMS method replaceCreationTemplate.
/**
* Replaces an existing template.
*
* @param guid the GUID it is looking under.
* @param templateName Name of the template.
* @param attrSet attribute-values pair to be replaced.
* @exception ConfigManagerException.
*/
public void replaceCreationTemplate(Guid guid, String templateName, AttrSet attrSet) throws ConfigManagerException {
if (guid == null) {
guid = new Guid(_rootDN);
}
DN dn = DN.valueOf(guid.getDn());
String org = "";
List<RDN> rdns = new ArrayList<>();
for (RDN rdn : dn) {
rdns.add(0, rdn);
}
for (RDN rdn : rdns) {
org = org + "/" + LDAPUtils.rdnValue(rdn);
}
String service = CREATIONPATH + "/" + templateName;
Map map = convertToMap(attrSet);
try {
replaceServiceAttributes(org, service, map);
} catch (SMSException e) {
String[] args = new String[1];
args[0] = e.toString();
throw new ConfigManagerException(i18n.getString(IUMSConstants.ERROR_CM, args));
} catch (SSOException se) {
String[] args = new String[1];
args[0] = se.toString();
throw new ConfigManagerException(i18n.getString(IUMSConstants.ERROR_CM, args));
}
}
Aggregations