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: AMClientCapData.java,v 1.7 2009/01/28 05:34:49 ww203982 Exp $
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Portions Copyrighted 2010-2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.event.IDSEventListener;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.security.AdminTokenAction;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceSchemaManager;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.openam.ldap.PersistentSearchChangeType;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.SearchScope;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The abstraction to get/set the clients stored in the DSAME. The Client is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * stored as a DIT in directory server with the properties as attributes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class AMClientCapData implements IDSEventListener {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // static stuff
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String SERVICE_VERSION = "1.0";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The service name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String SERVICE_NAME = "SunAMClientData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String BUNDLE_NAME = "amClientData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // To be overriden when read from config
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String OBJECTCLASS = "objectclass";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String CLIENT_OBJECTCLASS = "sunAMClient";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String UMS_ADD_TEMPLATE_NAME = "Client";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String UMS_SRCH_TEMPLATE_NAME = "BasicClientSearch";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String CLIENT_PREFIX = "sunamclient";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Error codes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CREATE_FAILED = "901";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String MISSING_PROP_CT = "903";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ADD_FAILED = "905";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CANNOT_MOD_INT_DB = "906";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String MODIFY_FAILED = "907";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String DELETE_FAILED = "908";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Begin attribute/schema names from amClientData.xml //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The attribute names in the service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Used by console plug-in. Should match the attribute names in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Service definition xml.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String[] dsameAttributeNames = {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "generalPropertyNames", "hardwarePlatformNames",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "softwarePlatformNames", "networkCharacteristicsNames",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "pushCharacteristicsNames", "additionalPropertiesNames" };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String DBSTORE_SUBSCHEMA_ID = "clientDBStore";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CLIENT_SUBSCHEMA_ID = "clientData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String INTERNAL_DB = "internalData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String EXTERNAL_DB = "externalData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String INTERNAL_DATA = "ou=" + INTERNAL_DB;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String EXTERNAL_DATA = "ou=" + EXTERNAL_DB;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Integer representation of the db.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The type of modification
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final int ADDED = DSEvent.OBJECT_ADDED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final int REMOVED = DSEvent.OBJECT_REMOVED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final int MODIFIED = DSEvent.OBJECT_CHANGED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CLIENT_TYPE = "clientType";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String USER_AGENT = "userAgent";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String PARENT_ID = "parentId";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ADD_PROPS = "additionalProperties";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The OU of the DN is the clientType for the device.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String ADD_PROP_SEPARATOR = EQUALS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String ADDITIONAL_PROPERTIES_ATTR = CLIENT_PREFIX
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String PROFILE_MANAGER_XML_ATTR = "profileManagerXML";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ENABLE_CLIENT_CREATION_ATTR =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "enableClientCreation";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // End - attribute/schema names from amClientData.xml //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = Debug.getInstance("amClientSchema");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static AMStoreConnection amConnection = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The dn to reach the ou=1.0,ou=SunAMClientData,..
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ou=1.0,ou=SunAMClientData,ou=ClientData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The actual internal & external instance objects.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static AMClientCapData internalInstance = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static AMClientCapData externalInstance = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Set wholeClient = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The schema for the service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static ServiceSchema clientServiceSchema = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Schema for the client data.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static ServiceSchema clientSchema = null;
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee // Needed since OpenAM retrieves all LDAP attrs in lowercase &
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // also since we prefix client attrs with "sunamclient"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Map schemaToLDAP = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Map LDAPToSchema = new HashMap();
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee // Persistent search related values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String SEARCH_FILTER = "(" + OBJECTCLASS + EQUALS
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington protected static final int OPERATIONS = PersistentSearchChangeType.ADDED
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington | PersistentSearchChangeType.MODIFIED | PersistentSearchChangeType.REMOVED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // BEGIN: per-instance variables //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // int representing the db instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String dbStr = null; // for debug messages
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // DSAME Object to access the AMOrganizationalUnit
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private AMOrganizationalUnit amClientOrg = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The dn to reach the ou=internaldata,..
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // END per-instance vars. //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private AMClientCapData(int dbType) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster init(dbName); // call init after setting per-instance vars
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * 1. get the admin token (or create one) 2. Create a ServiceManager 3. Get
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the ServiceSchemaManager for the service 4. Get the ServiceSchema for the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Global schema 5. Get the schema for the "internalData" schema. (temp
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * var). 6. Get the schema for the "clientData" schema id. (overwrite 8). 7.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get the ROOT_SUFFIX 8. Read config info & properties schema from
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ServiceSchema 9. Add Listeners to EventService.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private synchronized void init(String instanceRDN) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String srvcName = getServiceName(); // "SunAMClientData"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (adminToken == null) { // single static instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sManager = new ServiceManager(adminToken); // (2)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceSchemaManager schemaManager = sManager.getSchemaManager(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientServiceSchema = schemaManager.getGlobalSchema(); // (4)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // the internalDB & externalDB share the same schema (5)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientSchema = clientSchema.getSubSchema(CLIENT_SUBSCHEMA_ID); //(6)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amConnection = new AMStoreConnection(adminToken);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster topLevelDN = amConnection.getOrganizationDN(null, null); // (7)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientDataDN = CLIENT_DATA_DN_PREFIX + COMMA + topLevelDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // TBD : Commented so that persistant search is not setup to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // directory server when running in remote client SDK mode.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // This is temporary fix. Proper fix for this problem is TBD.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // initEventListeners (adminToken, clientDataDN); // (9)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster databaseDN = instanceRDN + COMMA + clientDataDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amClientOrg = amConnection.getOrganizationalUnit(databaseDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void initConfigurationInfo(ServiceSchema schema) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = getServiceAttribute(schema, "configInfo");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("umsAddTemplateName")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("umsSearchTemplateName")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("prefixForAttr")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("minimalClientAttrs")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Default configuration if not obtained from service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String DEF_MIN_CLIENTS = CLIENTTYPE_ATTR + COMMA + USER_AGENT
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer st = new StringTokenizer(val, ",");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if databaseType == INTERNAL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Map clientType to OU
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the serviceName. Used by the console plug-in to get to the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * resource bundle.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Singleton method to get an internal instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public synchronized static AMClientCapData getInternalInstance()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster internalInstance = new AMClientCapData(INTERNAL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("InternalDB:: Create instance object failed: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Singleton method to get an external instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public synchronized static AMClientCapData getExternalInstance()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster externalInstance = new AMClientCapData(EXTERNAL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("ExternalDB:: Create instance object failed: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the dn for the client
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String generateClientDN(String clientType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get a Map of all the properties for the Client. The Map contains key of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * property names and a Set for the values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param clientType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Client Type Name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Map of the properties or null if client not found
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = amConnection.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + "Could not get Client, session invalid: " + clientType, ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // admin token has timed out, retry
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster init(dbName); // call init after setting per-instance vars
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = amConnection.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + "Could not get Client, even after retry: " + clientType, ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning(dbStr + "Could not get Client: " + clientType, ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Gets the minimal client info for the specified client.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map loadMinimalClient(String clientType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = amConnection.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map attrsMap = amEntity.getAttributes(minClient);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning(dbStr + "Could not get Client: " + clientType, e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The ldap attribute names for the client properties and prefixed with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "sunamclient" to make them unique. This method gets the ldap attrs and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * converts them to client property names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (attrName.equalsIgnoreCase(ADDITIONAL_PROPERTIES_ATTR)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String propName = compositeVal.substring(0, index);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String propVal = compositeVal.substring(index + 1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String propertyName = (String) LDAPToSchema.get(attrName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void addToMap(Map m, String key, String val) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // works on the Set in the Map, so we dont need another put.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void addToMap(Map m, String key, Set vals) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Gets the profile manager xlob as a string. Used by the MAPClientDetector.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = getServiceAttribute(PROFILE_MANAGER_XML_ATTR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get a dsame attribute from the internal/external service. used by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * getProfileManagerXML()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attributeName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The name of the attribute.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return String The attribute as a string
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Set getServiceAttribute(String attributeName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set set = getServiceAttribute(clientServiceSchema, attributeName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Set getServiceAttribute(ServiceSchema schema, String attributeName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get a Set of all the Property names for the classification. Valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * classifications are:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>generalPropertyNames</li>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>hardwarePlatformNames</li>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>softwarePlatformNames</li>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>networkCharacteristicsNames</li>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>browserUANames</li>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>wapCharacteristicsNames</li>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>pushCharacteristicsNames</li>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <li>additionalPropertiesNames</li>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Set of PropertyNames belonging to classification or null if
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * nothing exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set getPropertyNames(String classification) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Checks if the clientType exists in the db.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if present, false otherwise
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean isClientPresent(String clientType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean exists = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = amConnection.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Cannot happen since we are using the AdminToken
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get the value of the clientType property from the Map.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The value of the "clientType" property
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Parse the allProps Map and return the known properties, and the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * additional ones in a Set of name=value Strings with the Map index being
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the ldap attr "sunamclientadditionalProperties"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ldapAttrName = (String) schemaToLDAP.get(propName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // separate multi-values with comma
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster val = (val == null) ? prop : val + COMMA + prop;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addProps.add(propName + ADD_PROP_SEPARATOR + val);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Add to the ADDITIONAL_PROPERTIES_ATTR in clientschema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addProps.addAll(e); // add if the allProps came with one.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster newPropsMap.put(ADDITIONAL_PROPERTIES_ATTR, addProps);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Add a client. For every property in the Map, it looks up the schema to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * check if the property is known, if not known adds it to the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * additionalProperties schema element. <br>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <b>Note: To add a property in the external db to mask the corresponding
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * property value in internal db, add the property with a " "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ("<space>") not an empty "" string. This is required because, when
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * dsame fetches the value from directory and sees it has no value, it
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * returns an empty set. (And we discard empty sets internally - bcos dsame
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * stores values for every property defined in the schema).</b>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * SSOToken to validate the user
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param props
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Map of profiles known to ClientCap. The Map "must" have a
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * property "clientType"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return 0 on success
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception AMClientCapException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if Client could not be added - permission problems or if
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the clientType property is mising in the Map.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int addClient(SSOToken token, Map props) throws AMClientCapException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMStoreConnection conn = new AMStoreConnection(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMOrganizationalUnit amOU = conn.getOrganizationalUnit(databaseDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amOU.createEntities(UMS_ADD_TEMPLATE_NAME, entityMap);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMClientCapException ace = new AMClientCapException(BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Modify the properties of the Client instance in externalDB. Valid only
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with instance of externalDB. <br>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <b>Note: To add a property in the external db to mask the corresponding
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * property value in internal db, add the property with a " "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ("<space>") not an empty "" string. This is required because, when
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * dsame fetches the value from directory and sees it has no value, it
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * returns an empty set. (And we discard empty sets internally - bcos dsame
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * stores values for every property defined in the schema).</b>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Also, if the additionalProperties are being modified, it should contain
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * both the modified and the unmodified ones. This is required since all the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * additionalProperties are stored in a single Attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "additionalProperties".
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * SSOToken to validate the user.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param props
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Map of profiles known to ClientCapabilities. The Map contains
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * key of property name(s) and Set for the values. It wont
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * overwrite the property names not in the Map. A key with an
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * empty Set for the values will delete the property (DSAME
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * cannot handle null values - throws NullPointerExcptn). The Map
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "must" have a property "clientType"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return 0 on success
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception AMClientCapException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if Client could not be modified - permission problems OR
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if the clientType property is mising in the Map.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int modifyClient(SSOToken token, Map props)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMStoreConnection localConn = new AMStoreConnection(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster m.remove(CLIENTTYPE_ATTR); // modify shouldn't have the RDN
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Need to add if the entry doesn't exist
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMClientCapException ace = new AMClientCapException(BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Remove a Client - removes the client from the externalDB. Valid only with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * instance of externalDB.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * SSOToken to validate the user
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param clientType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Client Type Name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return 0 on success
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception AMClientCapException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if Client could not be removed - permission problems
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int removeClient(SSOToken token, String clientType)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMStoreConnection localConn = new AMStoreConnection(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMClientCapException ace = new AMClientCapException(BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method returns the name of the "defined" client properties in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Schema. To get the AttributeSchema of these elements, iterate through
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * each of these names and call the getAttributeSchema() on it. Can be used
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with internal/external instance (since they share the same schema).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a Set of "defined" property names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public synchronized static Set getSchemaElements() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the schema for an property given the name. Can be used with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * internal/external instance (since they share the same schema).
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param propName Name of the property
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return com.sun.identity.sm.AttributeSchema Look at OpenSSO
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.sun.identity.sm.AttributeSchema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public AttributeSchema getAttributeSchema(String propName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema attrSchema = (AttributeSchema) map.get(propName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Cache for the attribute schemas.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private synchronized static Map getSchemaMap() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema prop = (AttributeSchema) itr.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Checks the enableClientCliention attr in Service. Used by the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ClientTypesManager when creating new Clients in the internal DB.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean allow = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = getServiceAttribute(ENABLE_CLIENT_CREATION_ATTR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Boolean perms = Boolean.valueOf((String)iter.next());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * register for listening to Client data changes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void addListener(AMClientDataListener cdl) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (listeners) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The ServiceListener interface methods
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Handled eventError() Notification: " + err);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("entryChanged() Notification for: " + dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return; // cannot notify correctly !
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String ct = LDAPUtils.rdnValue(ldapName.rdn());
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String db = LDAPUtils.rdnValue(ldapName.parent().rdn());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Unknown db: " + db + " : client = " + ct);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return; // unknown dbType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("Notifying Listeners:: ClientType = " + ct
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (listeners) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMClientDataListener cdl = (AMClientDataListener) listeners
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Event Notification failed: ", t);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // TODO Add code here to handle the situation of all entries changed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the valid classifications.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Demand Load stuff
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Gets a minimal set of client properties for all clients.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Set of Maps. Each Map has the propertyNames for the Key and Value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is Set of Property values. By default, the keys returned are
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * clientType, userAgent & parentID.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMSearchControl amsrchCntrl = new AMSearchControl();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMSearchResults results = amClientOrg.searchEntities("*",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "getMinimalClientInfo() Srch Time (ms) = "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "getMinimalClientInfo() Parse Time (ms) = "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + " getMinimalClientInfo(): Search Error: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#getBase()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#getFilter()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#getOperations()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#getScope()
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington return SearchScope.WHOLE_SUBTREE.intValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#setListener()