8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: CachedSubEntries.java,v 1.10 2008/07/11 01:46:21 arviranga Exp $
1de34e3b680bd4ab2b1bbb6cd58a61ab6f21164eJames Phillpotts * Portions Copyrighted 2013-2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Cache of CachedSubEntries based on lowercased DN to obtain sub entries
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static Map smsEntries = Collections.synchronizedMap(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Instance variables
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Cache of SubEntries for the given SSOToken
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Limited cache so that it does not grow in size
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected Map ssoTokenToSubEntries = new Cache(100);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Debug & I18n variables
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Private constructor, can be instantiated only via getInstance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private CachedSubEntries(SSOToken t, String dn) throws SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cachedEntry = CachedSMSEntry.getInstance(t, dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Register for notifications to clear instance cache
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // invalid ssoToken
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("CachedSubEntries::init Invalid SSOToken", ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "sms-INVALID_SSO_TOKEN"));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries::init: " + dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns one-level sub-entries for the given DN.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Results are cached.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param t SSOToken to used for searching
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return sub entries for the given DN
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.sun.identity.sm.SMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.iplanet.sso.SSOException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected Set getSubEntries(SSOToken t) throws SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set subEntries = (Set) ssoTokenToSubEntries.get(tokenID);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((subEntries != null) && SMSEntry.cacheSMSEntries) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries:getSubEntries Entries from " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Check if cached entries can be used
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (CachedSMSEntry.ttlEnabled && ((System.currentTimeMillis() -
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Clear the cache
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Obtain sub-entries and add to cache
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Add to cache
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries:getSubEntries Entries from " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Return sub-entries that match the pattern.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Performs data store operation, the results are not cached
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pattern
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return subentries that match the pattern
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.sun.identity.sm.SMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.iplanet.sso.SSOException
1de34e3b680bd4ab2b1bbb6cd58a61ab6f21164eJames Phillpotts public Set<String> getSubEntries(SSOToken token, String pattern)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries: reading sub-entries DN: " +
1de34e3b680bd4ab2b1bbb6cd58a61ab6f21164eJames Phillpotts return cachedEntry.getSMSEntry().subEntries(token, pattern, 0, false, true);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns sub-entries that belong to given SubSchema name and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * statisfies the pattern. The results are not cached.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pattern
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param serviceidPattern sub-schema name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return subentries that belong to given SubSchema name and satisfies
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the pattern
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.sun.identity.sm.SMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.iplanet.sso.SSOException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set getSchemaSubEntries(SSOToken token, String pattern,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String serviceidPattern) throws SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries: reading sub-entries DN: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cachedEntry.getDN() + " pattern: " + serviceidPattern);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (cachedEntry.getSMSEntry().schemaSubEntries(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster token, pattern, serviceidPattern, 0, true, true));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Clear the cache, will be updated in the next lookup
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Clear the cache, will be updated in the next lookup
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected boolean isEmpty(SSOToken t) throws SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected boolean contains(SSOToken t, String entry) throws SMSException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries::update called for dn: "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Clear the cache, will be updated in the next lookup
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SMSEventListenerManager.removeNotification(notificationID);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns realm names that matches the given pattern. If <code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * recursive<code> is set to <code>true</code>, a sub-tree search
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is performed. The results are not cached.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param pattern
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param recursive
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return realm names that matches the given pattern
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.sun.identity.sm.SMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.iplanet.sso.SSOException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set searchSubOrgNames(SSOToken token, String pattern,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean recursive) throws SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries: reading subOrgNames DN: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (cachedEntry.getSMSEntry().searchSubOrgNames(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster token, pattern, 0, !recursive, !recursive, recursive));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns realm names that match the attribute-values pair for the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * given service name. The attribute-values pairs is based on organization
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attribute schema. A sub-tree search is performed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The results are not cached.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param serviceName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return realm names that match the attributevalues pair for the given
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * service name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.sun.identity.sm.SMSException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws com.iplanet.sso.SSOException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set searchOrgNames(SSOToken token, String serviceName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String attrName, Set values) throws SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries: reading orgNames DN: " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cachedEntry.getDN() + " attrName: " + attrName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (cachedEntry.getSMSEntry().searchOrganizationNames(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster token, 0, true, true, serviceName, attrName, values));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Static methods to get object instance and to clear cache
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static CachedSubEntries getInstanceIfCached(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOToken token, String dn, boolean cached) throws SMSException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("CachedSubEntries::getInstance DN: " + dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CachedSubEntries answer = (CachedSubEntries) smsEntries.get(entry);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Not in cache, synchronize and add to cache
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (smsEntries) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster answer = (CachedSubEntries) smsEntries.get(entry);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Create and add to cache
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static CachedSubEntries getInstance(SSOToken token, String dn)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (getInstanceIfCached(token, dn, false));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (smsEntries) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Clear the individual cached entries
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator items = smsEntries.values().iterator();