/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: ConfigManagerUMS.java,v 1.6 2009/01/28 05:34:50 ww203982 Exp $
*
* Portions Copyrighted 2011-2015 ForgeRock AS.
*/
/**
* Configuration Manager is responsible for getting configuration parameters for
* UMS. ConfigManager is implemented as a singleton and the configurations can
* be accessed as follows:
* <p>
*
* <pre>
* ConfigManager cm = ConfigManager.getConfigManager();
* AttrSet tempAtts=
* cm.getTemplate("o=foo,o=isp", "BasicUser");
* Set hs =
* cm.getEntity("o=foo,o=isp",
* "com.iplanet.ums.PeopleContainer" );
* String [] sTemplateNames =
* cm.getCreationTemplateNames("o=foo, o=isp"); *
* </pre>
*
* ConfigManager obsoletes the use of previous Config class which opens up
* resource file and reading whenever a configuation is needed. ConfigManager
* speeds up the retrieval in caching the configurations at start up time once
* as a singleton and share it among the ums package. ConfigManager uses the
* default PROXY as AuthPrincipal for this instance of the server.
*
* </p>
*/
/**
* i18n keys
*/
/**
* Get the singleton instance of Config Manager.
*
* @return Singleton instance of Configuration Manager.
*/
throws ConfigManagerException {
try {
_instance = new ConfigManagerUMS();
} catch (Exception e) {
}
}
return _instance;
}
/**
* Reads the directory server, via SMS APIs for a given org (/b/a) and for a
* given template (<code>StructureTemplates</code>,
* <code>CreationTemplates</code>, etc.).
*
* @param c List of template names.
* @param template Name of template.
*/
//
// To get all attributes for each component name from DS and store
// in cache. Calls getServiceAttrs()
//
try {
} catch (SMSException smse) {
// Don't throw an exception, just log it. Cache will return
// a null
} catch (SSOException ssoe) {
// Don't throw an exception, just log it. Cache will return
// a null
}
if (entityAttributes.isEmpty())
continue;
.hasNext();) {
.next()));
}
}
// This search is for EntityManager
} else {
}
if (_debug.messageEnabled())
}
// This search is for EntityManager
if (_debug.messageEnabled())
}
// } else {
// This search is for TemplateManager
if (_debug.messageEnabled())
}
// This search is for TemplateManager
}
}
// This adds the String[][] for ObjectResolver to cache
if (oc_jc_map_string != null) {
}
}
}
}
/**
* CACHE MANAGEMENT for entity and template components.
*
* @param org A string identifier for the cache.
* @throws ConfigManagerException
* The default components would be loaded through an XML
* schema/configuration file <code>ConfigManager</code> has to
* get the components and the related attributes from the directory
* Server initially to store them in the cache by calling the SMS
* API.
*/
// If org = "" (base level), then add OBJECTRESOLVER ATTRSET TO CACHE
}
try {
} catch (SMSException smse) {
// Don't do anything. This is an LDAP problem,
// cache will just return NULL
if (_debug.warningEnabled())
} catch (SSOException ssoe) {
// Don't do anything. This is an LDAP problem,
// cache will just return NULL
if (_debug.warningEnabled())
}
try {
} catch (SMSException smse) {
// Don't do anything. This is an LDAP problem,
// cache will just return NULL
if (_debug.warningEnabled())
} catch (SSOException ssoe) {
// Don't do anything. This is an LDAP problem,
// cache will just return NULL
if (_debug.warningEnabled())
}
try {
} catch (SMSException smse) {
// Don't do anything. This is an LDAP problem,
// cache will just return NULL
if (_debug.warningEnabled())
} catch (SSOException ssoe) {
// Don't do anything. This is an SSO problem,
// cache will just return NULL
if (_debug.warningEnabled())
}
return;
}
// This is a search for searchTemplateNames only.
String t;
}
if (_debug.messageEnabled())
}
// This is a search for creationTemplateNames only.
String t;
}
if (_debug.messageEnabled())
}
}
throws SMSException, SSOException {
null);
return new HashSet();
}
// Parser the "/" seperated path to get the right service config
while (st.hasMoreTokens()) {
continue;
}
}
}
return (answer);
}
throws SMSException, SSOException {
null);
// Parser the "/" seperated path to get the right service config
while (st.hasMoreTokens()) {
continue;
}
else
}
return (sc.getAttributes());
else
}
throws SMSException, SSOException {
// Parser the "/" seperated path to get the right service config
while (st.hasMoreTokens()) {
continue;
}
}
}
// Create this partial keys /b/a/StructureTemplates,
// /b/a/CreationTemplates,/b/a/SearchTemplate,
// so that with a root org, where the key would be ""
// everything doesn't get deleted in the cache.
// fdn = "";
} else {
/*
* DN dn = new DN(org); DN root = new DN(_rootDN); String [] dns =
* dn.explodeDN(true); String [] rootdns = root.explodeDN(true); int
* len = dns.length; int rootLen = rootdns.length; StringBuffer sb =
* new StringBuffer(); for (int k=0; k<len-rootLen; k++) {
* sb.append("/").append(dns[len-k-rootLen -1]); } fdn =
* sb.toString();
*/
}
if (_debug.messageEnabled())
+ " from cache");
while (e.hasMoreElements()) {
if (_debug.messageEnabled())
+ " Deleting..." + key);
}
}
// if org == "" (Base level) then remove ObjectResolver class too.
_oc_jc_map = null;
}
}
/**
* 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.
*/
int lookup) throws ConfigManagerException {
// if guid is null, replace it use the rootDN
// if guid is not "o=...", find the organization guid
/*
* if (!guid.getDn().startsWith("o=")) { guid =
* GuidUtils.getOrgGuid(guid); }
*/
// Till we find what we are looking for,
// traverse the tree in the cache
while (true) {
boolean inCache = false;
boolean checkedDS = false;
//
// 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
// Special case Cache Key for OBJECTRESOLVER
else
if (_debug.messageEnabled())
+ " cacheKey=" + cacheKey);
//
// Check the cache for the entry.
// If it's in the cache, return the information.
//
if (inCache) {
if (_debug.messageEnabled()) {
"cache for " + dn);
}
}
//
// 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.
//
if (!checkedDS) {
if (_debug.messageEnabled())
"cache for " + dn);
synchronized (lock_cch) {
}
}
//
// We've checked the DS already so get the parent and
// try again.
// Check if we need to traverse to the parent
switch (lookup) {
case TemplateManager.SCOPE_ORG:
return null;
case TemplateManager.SCOPE_TOP:
break;
// After getting parent, check if this is already root of tree,
// if so return null
// if (dn.toString().length() == 0) return null;
break;
} else {
return null;
}
}
if (_debug.messageEnabled())
"parent: " + dn);
}
}
throws ConfigManagerException {
// if guid is null, replace it use the rootDN
// if guid is not "o=...", find the organization guid
}
while (true) {
boolean inCache = false;
boolean checkedDS = false;
//
// 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
/*
* String[] dns = dn.explodeDN(true); String[] rootdns =
* root.explodeDN(true); int len = dns.length; int rootLen =
* rootdns.length; for (int k=0; k<len-rootLen; k++) { fdn = fdn +
* "/" + dns[len-k-rootLen-1]; }
*/
//
// Check the cache for the entry.
// If it's in the cache, return the information.
//
if (_debug.messageEnabled())
"Looking for: " + cacheKey);
if (inCache)
//
// 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.
//
if (!checkedDS) {
if (_debug.messageEnabled())
"updating " + dn);
synchronized (lock_cch) {
}
}
//
// We've checked the DS already so get the parent and
// try again.
switch (lookup) {
case TemplateManager.SCOPE_ORG:
case TemplateManager.SCOPE_TOP:
break;
// After getting parent, check if this is already root of tree,
// if so return null
// if (dn.toString().length() == 0)
break;
} else {
}
}
"Traversing parent: " + dn);
}
}
/**
* Returns the Attribute Key-Value set of a Structure Template
* entry. It searches for all entries and returns the entry for which the
* "class" Attribute matches the provided name.
*
* @param guid GUI specifies the starting location for
* <code>ConfigManager</code> to begin searching for DIT
* information (for structural entities).
* @param name Class name of the object for which the DIT information
* applies.
* @return Collection of attrSets pertaining to the structure
* templates in the DIT.
* @throws ConfigManagerException.
*/
}
/**
* TEMPLATE MANAGER APIs
*
*/
/**
* Returns the Attribute Key-Value set of a Search or Creation
* Template entry. It searches for all entries and returns the entry for
* which the "name" Attribute matches the provided name.
*
* @param guid Specifies the starting location for
* <code>ConfigManager</code> to begin searching for DIT
* information (for structural entities).
* @param templateName Template name.
* @param lookup
* @return <code>AttrSet</code> value pertaining to the structural template
* in the DIT. Usage:
* <pre>
* AttrSet a = CM.getSearchTemplateForClass(
* principal, "o=foo,o=org", "BasicUserSearch");
* </pre>
* representation). Looks for Search Template with attribute "name"
* matching <code>BasicUserSearch</code> and returns the first one
* matched. If found in cache, it returns that. Else it looks it up
* in the Directory through SMS (traverses the tree if need be).
* @throws ConfigManagerException.
*/
throws ConfigManagerException {
lookup);
}
/**
* Returns Attribute Key-Value set of a <code>CreationTemplate</code> entry.
* It searches for all entries and returns the entry for which the
* "name" Attribute matches the provided name.
*
* @param guid Specifies the starting location for
* <code>ConfigManager</code> to begin searching for DIT information
* (for structural entities).
* @param templateName Template name.
* @param lookup
* @return <code>AttrSet</code> value pertaining to the structural template
* in the DIT. Usage:
* <pre>
* AttrSet a = CM.getCreationTemplateForClass(
* principal, "o=foo,o=org", "BasicUser");
* </pre>
* representation). Looks for Search Template with attribute "name"
* matching <code>BasicUser</code> and returns the first one
* matched. If found in cache, it returns that. Else it looks it
* up in the Directory through SMS (traverses the tree if need be)
* @throws ConfigManagerException.
*/
int lookup
) throws ConfigManagerException {
lookup);
return ret;
}
/**
* Returns the Attribute key-value pair of Creation templates under the
* given organization by matching the the <code>javaclass</code> attribute
* to the name provided. If no templates are listed under the current
* organization then it traverses the org tree till it finds one, or returns
* null.
*
* @param guid Organization DN.
* @param className Name of <code>javaclass</code> Attribute to be matched.
* @param lookup
* @return Attribute key-value pair of Creation templates. Usage:
* <pre>
* AttrSet a = CM.getCreationTemplateForClass(
* principal, "o=foo,o=org", "com.iplanet.ums.BasicUser");
* </pre>
* <code>CreationTemplates/templates/org</code> for nodes where
* attribute "class" matches <code>com.iplanet.ums.BasicUser</code>.
* First looks up cache, if not found in cache, then looks up in
* Directory.
*/
int lookup
) throws ConfigManagerException {
}
return ret;
}
/**
* Returns an array of the Creation Template names under the
* given organization. If there are no Creation Templates under the given
* organization then it traveres the organization tree upwards till it finds
* one, or returns null.
*
* @param guid Organization to look under.
* @return Set of Creation Template names.
*/
throws ConfigManagerException {
return getConfigTemplateNames(
}
/**
* Returns a set of the Search Template names under the given
* organization. If there are no Search Templates under the given
* organization then it traveres the organization tree upwards till it finds
* one, or returns null.
*
* @param guid Organization to look under.
* @return Set of template name.
* @throws ConfigManagerException.
*/
}
/**
* Gets the mapping between ldap entry objectclasses and the UMS Java class.
* This is an array of objectclass, java class pairs. The
* Objectclass/Javaclass pair for a superclass should be defined before that
* of a subclass. This method returns a double-subscripted array for the
* component "ObjectResolver" under the root tree. This component will not
* exist under any other organization except the root.
*
* @return an array of Objectclass/Javaclass pairs.
* @exception ConfigManagerException.
*
* Usage: String[][] a = CM.getClassResolver() Looks up the attributes at
* the top level /ObjectResolver/templates/iDA Caches it first.
*/
// if it is not in the oc_jc_map cache, gets it
if (_oc_jc_map == null) {
}
return _oc_jc_map;
}
/**
* 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.
*/
}
}
}
try {
} catch (SMSException e) {
} catch (SSOException se) {
}
}
}
return map;
}
int i = 0;
while (st.hasMoreTokens()) {
if (index >= 0) {
i++;
}
}
return oc_jc_map;
}
/**
* Construct configuration.
*/
try {
if (_debug.messageEnabled())
.message("ConfigManager->Constructor: root DN "
+ _rootDN);
_principal = new AuthPrincipal(p);
try {
} catch (SSOException e) {
}
// _smapi = new ServiceConfigManager(_principal);
_listener = new CMListener();
} catch (Exception e) {
e.printStackTrace();
}
}
+ "/ObjectResolver";
}