SMSEmbeddedLdapObject.java revision 8af80418ba1ec431c8027fa9668e5678658d3611
/**
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2009 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: SMSEmbeddedLdapObject.java,v 1.3 2009/10/28 04:24:27 hengming Exp $
*/
/*
* Portions Copyrighted [2011] [ForgeRock AS]
*/
/**
* This object represents an LDAP entry in the directory server. The UMS have an
* equivalent class called PersistentObject. The SMS could not integrate with
* PersistentObject, because of the its dependecy on the Session object. This
* would mean that, to instantiate an PersistentObject inside SMS, we need to
* create an UMS instance, which would be having directory parameters of SMS.
* <p>
* This class is used both to read and write information into the directory
* server. The appropriate constructors discusses it is done.
* <p>
* There can be only three types of SMS entries in the directory (i) entry with
* organizationUnit object class (attribute: ou) (ii) entry with sunService
* object class (attributes: ou, labeledURI, sunServiceSchema, sunPluginSchema,
* and sunKeyValue (sunXMLKeyValue, in the future) (iii) entry with
* sunServiceComponent object class (attributes: ou, sunServiceID,
* sunSMSPriority, sunKeyValue. All the schema, configuration and plugin entries
* will be stored using the above entries.
*/
public class SMSEmbeddedLdapObject extends SMSObjectDB
implements SMSObjectListener {
static int entriesPresentCacheSize = 1000;
static boolean initializedNotification;
new LinkedHashSet());
new LinkedHashSet());
// Other parameters
static ResourceBundle bundle;
static boolean initialized = false;
static LinkedHashSet OU_ATTR;
static LinkedHashSet O_ATTR;
static InternalClientConnection icConn;
static LinkedHashSet smsAttributes;
static final String SMS_EMBEDDED_LDAP_OBJECT_SEARCH_LIMIT =
"com.sun.identity.sm.sms_embedded_ldap_object_search_limit";
/**
* Public constructor for SMSEmbeddedLdapObject
*/
public SMSEmbeddedLdapObject() throws SMSException {
// Initialized (should be called only once by SMSEntry)
initialize();
}
/**
* Synchronized initialized method
*/
private synchronized void initialize() throws SMSException {
if (initialized) {
return;
}
// Obtain the I18N resource bundle & Debug
try {
if (!entryExists(serviceDN)) {
}
} catch (Exception e) {
// Unable to initialize (trouble!!)
"Unable to initalize(exception):", e);
}
}
initialized = true;
}
private void initializeNotification() {
if (!initializedNotification) {
// If cache is enabled, register for notification to maintian
// internal cache of entriesPresent
if (SMSNotificationManager.isCacheEnabled()) {
.registerCallbackHandler(this);
}
initializedNotification = true;
}
}
/**
* Reads in the object from persistent store, assuming that the guid and the
* SSOToken are valid
*/
// This must not be possible return an exception.
}
"sms-INVALID_DN", args);
}
// Check if entry does not exist
if (SMSNotificationManager.isCacheEnabled() &&
if (debug.messageEnabled()) {
dn + " (checked in cached)");
}
return (null);
}
try {
0, 0, false, "(|(objectclass=*)(objectclass=ldapsubentry))",
if (!searchResult.isEmpty()) {
return EmbeddedSearchResultIterator.
} else {
return null;
}
// Add to not present Set
if (debug.messageEnabled()) {
"entry not present:"+ dn);
}
return null;
} else {
if (debug.warningEnabled()) {
"Error in accessing entry DN: " + dn +
", error code = " + resultCode);
}
}
} catch (DirectoryException dex) {
if (debug.warningEnabled()) {
}
}
}
/**
* Create an entry in the directory
*/
throws SMSException, SSOException {
// Update entryPresent cache
}
/**
* Create an entry in the directory using the principal name
*/
throws SMSException, SSOException {
if (debug.messageEnabled()) {
"SMSEmbeddedLdapObject.create: Successfully created" +
" entry: " + dn);
}
// During install time and other times,
// this error gets throws due to unknown issue. Issue:
// Hence mask it.
"Already Exists Error for DN" + dn);
} else {
}
}
/**
* Save the entry using the token provided. The principal provided will be
* used to get the proxy connection.
*/
throws SMSException, SSOException {
if (debug.messageEnabled()) {
"modified entry: " + dn);
}
} else {
", error code = " + resultCode );
}
}
/**
* Delete the entry in the directory. This will delete sub-entries also!
*/
// Check if there are sub-entries, delete if present
if (debug.messageEnabled()) {
entry);
}
}
// Check if there are suborganizations, delete if present
// The recursive 'false' here has the scope SCOPE_ONE
// while searching for the suborgs.
// Loop through the suborg at the first level and if there
// is no next suborg, delete that.
false);
if (debug.messageEnabled()) {
"suborganization: " + subOrg);
}
}
if (debug.warningEnabled()) {
"Unable to delete entry:" + dn);
}
}
}
/**
* Returns the sub-entry names. Returns a set of RDNs that are sub-entries.
* The paramter <code>numOfEntries</code> identifies the number of entries
* to return, if <code>0</code> returns all the entries.
*/
throws SMSException, SSOException {
filter = "*";
}
if (debug.messageEnabled()) {
}
// Construct the filter
// This is a workaround for Issue 3823, where DS returns an
// empty set if restarted during OpenSSO operation
}
return (answer);
}
throws SMSException, SSOException {
// sorting is not implemented
// Get the sub entries
try {
if (debug.messageEnabled()) {
"entry not present:" + dn);
}
if (debug.messageEnabled()) {
"sub-entries: " + dn);
}
if (debug.warningEnabled()) {
}
}
// Construct the results and return
continue;
}
.toString();
}
if (debug.messageEnabled()) {
"Successfully obtained sub-entries for : " + dn);
}
return (answer);
} catch (DirectoryException dex) {
if (debug.warningEnabled()) {
}
}
}
/**
* Returns the sub-entry names. Returns a set of RDNs that are sub-entries.
* The paramter <code>numOfEntries</code> identifies the number of entries
* to return, if <code>0</code> returns all the entries.
*/
if (debug.messageEnabled()) {
dn);
}
// Construct the filter
return (answer);
}
return ("SMSEmbeddedLdapObject");
}
throws SSOException, SMSException {
if (debug.messageEnabled()) {
" size limit exceeded. numOfEntries = " + numOfEntries);
}
if (debug.warningEnabled()) {
}
}
}
/**
* Returns LDAP entries that match the filter, using the start DN provided
* in method
*/
if (debug.messageEnabled()) {
}
if (debug.messageEnabled()) {
" size limit exceeded. numOfEntries = " + numOfEntries);
}
if (debug.warningEnabled()) {
}
}
}
if (debug.messageEnabled()) {
}
return answer;
}
boolean sortResults, boolean ascendingOrder)
throws SSOException, SMSException {
// sorting is not implemented
try {
// Get the sub entries
return iso;
} catch (DirectoryException dex) {
if (debug.warningEnabled()) {
}
}
}
/**
* Checks if the provided DN exists. Used by PolicyManager.
*/
/**
* Checks if the provided DN exists. Used by PolicyManager.
*/
if (debug.messageEnabled()) {
"entry exists: " + dn);
}
// Check the caches
if (SMSNotificationManager.isCacheEnabled() &&
if (debug.messageEnabled()) {
"entry present in cache: " + dn);
}
return (true);
} else if (SMSNotificationManager.isCacheEnabled() &&
if (debug.messageEnabled()) {
"entry present in not-present-cache: " + dn);
}
return (false);
}
// Check if entry exisits
// Update the cache
synchronized (entriesPresent) {
}
}
}
} else if (SMSNotificationManager.isCacheEnabled()) {
synchronized (entriesNotPresent) {
}
}
}
}
return (entryExists);
}
/**
* Checks if the provided DN exists.
*/
try {
0, 0, false, "(|(objectclass=*)(objectclass=ldapsubentry))",
null);
return true;
} else {
if (debug.warningEnabled()) {
"does not exist. resultCode = " + resultCode);
}
return false;
}
} catch (DirectoryException dex) {
if (debug.warningEnabled()) {
"does not exist.", dex);
}
return false;
}
}
/**
* Registration of Notification Callbacks
*/
throws SMSException {
}
}
// Method to convert Map to LDAPAttributeSet
return null;
}
}
}
return attrList;
}
// Method to covert JNDI ModificationItems to LDAPModificationSet
private static List copyModItemsToLDAPModList(
return null;
}
try {
mods[i].getAttribute();
}
switch (mods[i].getModificationOp()) {
case DirContext.ADD_ATTRIBUTE:
break;
case DirContext.REPLACE_ATTRIBUTE:
break;
case DirContext.REMOVE_ATTRIBUTE:
break;
}
}
}
} catch (NamingException nne) {
throw (new SMSException(nne,
"sms-cannot-copy-fromModItemToModSet"));
}
return (modList);
}
// Remove from entriesPresent Set
// Remove from entriesNotPresent set
}
}
public void allObjectsChanged() {
// Not clear why this class is implemeting the SMSObjectListener
// interface.
" got notifications, all objects changed");
}
}
/**
* Returns the suborganization names. Returns a set of RDNs that are
* suborganization name. The paramter <code>numOfEntries</code> identifies
* the number of entries to return, if <code>0</code> returns all the
* entries.
*/
if (debug.messageEnabled()) {
dn);
}
/*
* Instead of constructing the filter in the framework(SMSEntry.java),
* Construct the filter here in SMSEmbeddedLdapObject or the plugin
* implementation to support JDBC or other data store.
*/
"={0}))";
return (answer);
}
if (debug.messageEnabled()) {
"searchSubOrganizationNames: suborg not present:" + dn);
}
if (debug.messageEnabled()) {
"searchSubOrganizationNames: size limit exceeded. " +
}
if (debug.warningEnabled()) {
"searchSubOrganizationNames: Unable to search. dn = "+
}
}
}
if (debug.messageEnabled()) {
"Successfully obtained suborganization names for : " + dn);
"Successfully obtained suborganization names : " +
}
return (answer);
}
/**
* Returns the organization names. Returns a set of RDNs that are
* organization name. The paramter <code>numOfEntries</code> identifies
* the number of entries to return, if <code>0</code> returns all the
* entries.
*/
throws SMSException, SSOException {
if (debug.messageEnabled()) {
" search dn: " + dn);
}
/*
* Instead of constructing the filter in the framework(SMSEntry.java),
* Construct the filter here in SMSEmbeddedLdapObject or the plugin
* implementation to support JDBC or other data store. To return
* organization names that match the given attribute name and values,
* only exact matching is supported, and if more than one value is
* provided the organization must have all these values for the
* attribute. Basically an AND is performed for attribute values for
* searching. The attributes can be under the service config as well
* under the Realm/Organization directly. For eg.,
* (|(&(objectclass=sunRealmService)(&
* (|(sunxmlkeyvalue=SERVICE_NAME-ATTR_NAME=VALUE1)
* (sunxmlkeyvalue=ATTR_NAME=VALUE1))
* (|(sunxmlkeyvalue=SERVICE_NAME-ATTR_NAME=VALUE2)
* (sunxmlkeyvalue=ATTR_NAME=VALUE2))(...))
* (&(objectclass=sunServiceComponent)(&
* (|(sunxmlkeyvalue=SERVICE_NAME-ATTR_NAME=VALUE1)
* (sunxmlkeyvalue=ATTR_NAME=VALUE1))
* (|(sunxmlkeyvalue=SERVICE_NAME-ATTR_NAME=VALUE2)
* (sunxmlkeyvalue=ATTR_NAME=VALUE2))(...))
*
*/
}
) {
// Include the OCs only for sunDS, not Active Directory.
//String FILTER_PATTERN_SEARCH_ORG = "(|(&(objectclass="
FILTER_PATTERN_SEARCH_ORG = "(|(&(objectclass="
}
if (debug.messageEnabled()) {
"orgNames search filter: " + sfilter);
}
sortResults, ascendingOrder, true);
return (answer);
}
public void shutdown() {
}
}