bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
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 *
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 * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
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 *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: AMClientCapData.java,v 1.7 2009/01/28 05:34:49 ww203982 Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington * Portions Copyrighted 2010-2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.iplanet.services.cdm.clientschema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.security.AccessController;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.ArrayList;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.Collections;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.HashMap;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.HashSet;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.Iterator;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.List;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.Map;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.Set;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport java.util.StringTokenizer;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMEntity;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMOrganizationalUnit;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMSearchControl;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMSearchResults;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMStoreConnection;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.event.DSEvent;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.services.ldap.event.IDSEventListener;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOToken;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.security.AdminTokenAction;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.AttributeSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceSchemaManager;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.openam.ldap.LDAPUtils;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.openam.ldap.PersistentSearchChangeType;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.DN;
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunningtonimport org.forgerock.opendj.ldap.SearchScope;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
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 Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class AMClientCapData implements IDSEventListener {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // static stuff
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String SERVICE_VERSION = "1.0";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The service name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String SERVICE_NAME = "SunAMClientData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String BUNDLE_NAME = "amClientData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // To be overriden when read from config
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String OBJECTCLASS = "objectclass";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String CLIENT_OBJECTCLASS = "sunAMClient";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String UMS_ADD_TEMPLATE_NAME = "Client";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String UMS_SRCH_TEMPLATE_NAME = "BasicClientSearch";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String CLIENT_PREFIX = "sunamclient";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Error codes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CREATE_FAILED = "901";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String MISSING_PROP_CT = "903";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CT_EXISTS = "904";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ADD_FAILED = "905";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CANNOT_MOD_INT_DB = "906";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String MODIFY_FAILED = "907";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String DELETE_FAILED = "908";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Begin attribute/schema names from amClientData.xml //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
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 //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String[] dsameAttributeNames = {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "generalPropertyNames", "hardwarePlatformNames",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "softwarePlatformNames", "networkCharacteristicsNames",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "browserUANames", "wapCharacteristicsNames",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "pushCharacteristicsNames", "additionalPropertiesNames" };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String DBSTORE_SUBSCHEMA_ID = "clientDBStore";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CLIENT_SUBSCHEMA_ID = "clientData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String INTERNAL_DB = "internalData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String EXTERNAL_DB = "externalData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String INTERNAL_DATA = "ou=" + INTERNAL_DB;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String EXTERNAL_DATA = "ou=" + EXTERNAL_DB;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Integer representation of the db.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final int INTERNAL = 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final int EXTERNAL = 2;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The type of modification
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final int ADDED = DSEvent.OBJECT_ADDED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final int REMOVED = DSEvent.OBJECT_REMOVED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final int MODIFIED = DSEvent.OBJECT_CHANGED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String CLIENT_TYPE = "clientType";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String USER_AGENT = "userAgent";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String PARENT_ID = "parentId";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ADD_PROPS = "additionalProperties";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String EQUALS = "=";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String COMMA = ",";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The OU of the DN is the clientType for the device.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String CLIENTTYPE_ATTR = "ou";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String ADD_PROP_SEPARATOR = EQUALS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String ADDITIONAL_PROPERTIES_ATTR = CLIENT_PREFIX
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + ADD_PROPS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String PROFILE_MANAGER_XML_ATTR = "profileManagerXML";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String ENABLE_CLIENT_CREATION_ATTR =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "enableClientCreation";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // End - attribute/schema names from amClientData.xml //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static SSOToken adminToken = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = Debug.getInstance("amClientSchema");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static AMStoreConnection amConnection = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static ServiceManager sManager = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String topLevelDN = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The dn to reach the ou=1.0,ou=SunAMClientData,..
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String clientDataDN = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String CLIENT_DATA_DN_PREFIX =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ou=1.0,ou=SunAMClientData,ou=ClientData";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The actual internal & external instance objects.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static AMClientCapData internalInstance = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static AMClientCapData externalInstance = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Set wholeClient = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Set minClient = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The schema for the service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static ServiceSchema clientServiceSchema = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Schema for the client data.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static ServiceSchema clientSchema = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Map schemaMap = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee // Needed since OpenAM retrieves all LDAP attrs in lowercase &
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // also since we prefix client attrs with "sunamclient"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Map schemaToLDAP = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Map LDAPToSchema = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8d3140b524c0e28c0a49dc7c7d481123ef3cfe11Chris Lee // Persistent search related values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String SEARCH_FILTER = "(" + OBJECTCLASS + EQUALS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + CLIENT_OBJECTCLASS + ")";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington protected static final int OPERATIONS = PersistentSearchChangeType.ADDED
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington | PersistentSearchChangeType.MODIFIED | PersistentSearchChangeType.REMOVED;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // BEGIN: per-instance variables //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // int representing the db instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private int databaseType = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String dbStr = null; // for debug messages
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // DSAME Object to access the AMOrganizationalUnit
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private AMOrganizationalUnit amClientOrg = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private List listeners = new ArrayList(2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The dn to reach the ou=internaldata,..
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String databaseDN = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // END per-instance vars. //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private AMClientCapData(int dbType) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dbName = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster databaseType = dbType; // order is important !
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (isInternalInstance()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbName = INTERNAL_DATA;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbStr = "InternalDB:: "; // for debug messages
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbName = EXTERNAL_DATA;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbStr = "ExternalDB:: "; // for debug messages
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster init(dbName); // call init after setting per-instance vars
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private synchronized void init(String instanceRDN) throws Exception {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String srvcName = getServiceName(); // "SunAMClientData"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (adminToken == null) { // single static instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adminToken = (SSOToken) AccessController
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .doPrivileged(AdminTokenAction.getInstance());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sManager = new ServiceManager(adminToken); // (2)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceSchemaManager schemaManager = sManager.getSchemaManager(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster srvcName, SERVICE_VERSION); // (3)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientServiceSchema = schemaManager.getGlobalSchema(); // (4)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // the internalDB & externalDB share the same schema (5)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientSchema = clientServiceSchema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .getSubSchema(DBSTORE_SUBSCHEMA_ID);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientSchema = clientSchema.getSubSchema(CLIENT_SUBSCHEMA_ID); //(6)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amConnection = new AMStoreConnection(adminToken);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster topLevelDN = amConnection.getOrganizationDN(null, null); // (7)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster initClientSchema(); // (8)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster initConfigurationInfo(clientServiceSchema);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientDataDN = CLIENT_DATA_DN_PREFIX + COMMA + topLevelDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
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 }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster databaseDN = instanceRDN + COMMA + clientDataDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amClientOrg = amConnection.getOrganizationalUnit(databaseDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void initConfigurationInfo(ServiceSchema schema) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = getServiceAttribute(schema, "configInfo");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (vals == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster vals = Collections.EMPTY_SET;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator iter = vals.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (iter.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String val = (String) iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int index = val.indexOf(EQUALS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String key = val.substring(0, index);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String value = val.substring(index + 1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (key.equalsIgnoreCase(OBJECTCLASS)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CLIENT_OBJECTCLASS = value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("umsAddTemplateName")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UMS_ADD_TEMPLATE_NAME = value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("umsSearchTemplateName")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster UMS_SRCH_TEMPLATE_NAME = value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("prefixForAttr")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CLIENT_PREFIX = value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("rdn")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CLIENTTYPE_ATTR = value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("clientDN")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CLIENT_DATA_DN_PREFIX = value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (key.equalsIgnoreCase("minimalClientAttrs")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addToSet(value, minClient);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Default configuration if not obtained from service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (minClient.isEmpty()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String DEF_MIN_CLIENTS = CLIENTTYPE_ATTR + COMMA + USER_AGENT
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + COMMA + PARENT_ID;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addToSet(DEF_MIN_CLIENTS, minClient);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void addToSet(String val, Set s) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer st = new StringTokenizer(val, ",");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (st.hasMoreElements()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String str = st.nextToken();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (str.equalsIgnoreCase("rdn")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster str = CLIENTTYPE_ATTR;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster str = CLIENT_PREFIX + str;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster s.add(str);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if databaseType == INTERNAL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private boolean isInternalInstance() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (databaseType == INTERNAL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static void initClientSchema() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set props = getSchemaElements();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator itr = props.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (itr.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String propName = (String) itr.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String attrName = CLIENT_PREFIX + propName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (propName.equals(CLIENT_TYPE)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Map clientType to OU
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrName = CLIENTTYPE_ATTR;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster wholeClient.add(attrName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String attrNameLC = attrName.toLowerCase();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster LDAPToSchema.put(attrNameLC, propName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster schemaToLDAP.put(propName, attrName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the serviceName. Used by the console plug-in to get to the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * resource bundle.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getServiceName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (SERVICE_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Singleton method to get an internal instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public synchronized static AMClientCapData getInternalInstance()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws AMClientCapException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (internalInstance == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster internalInstance = new AMClientCapData(INTERNAL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster internalInstance = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("InternalDB:: Create instance object failed: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMClientCapException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BUNDLE_NAME, CREATE_FAILED, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return internalInstance;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Singleton method to get an external instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public synchronized static AMClientCapData getExternalInstance()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws AMClientCapException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (externalInstance == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster externalInstance = new AMClientCapData(EXTERNAL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster externalInstance = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("ExternalDB:: Create instance object failed: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMClientCapException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BUNDLE_NAME, CREATE_FAILED, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return externalInstance;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the dn for the client
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String generateClientDN(String clientType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder dn = new StringBuilder();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dn.append(CLIENTTYPE_ATTR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dn.append(EQUALS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dn.append(clientType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dn.append(COMMA);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dn.append(databaseDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (dn.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
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 *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param clientType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Client Type Name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Map of the properties or null if client not found
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map getProperties(String clientType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map props = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dn = generateClientDN(clientType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = amConnection.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (amEntity.isExists()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map attrsMap = amEntity.getAttributes();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster props = parsePropertyNames(attrsMap);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException ssoe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + "Could not get Client, session invalid: " + clientType, ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // admin token has timed out, retry
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adminToken = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dbName = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (isInternalInstance()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbName = INTERNAL_DATA;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbName = EXTERNAL_DATA;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster init(dbName); // call init after setting per-instance vars
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = amConnection.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (amEntity.isExists()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map attrsMap = amEntity.getAttributes();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster props = parsePropertyNames (attrsMap);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + "Could not get Client, even after retry: " + clientType, ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception ex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning(dbStr + "Could not get Client: " + clientType, ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return props;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Gets the minimal client info for the specified client.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map loadMinimalClient(String clientType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map props = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dn = generateClientDN(clientType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = amConnection.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (amEntity.isExists()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map attrsMap = amEntity.getAttributes(minClient);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster props = parsePropertyNames(attrsMap);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning(dbStr + "Could not get Client: " + clientType, e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return props;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Map parsePropertyNames(Map m) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map props = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator allKeys = m.keySet().iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (allKeys.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String attrName = (String) allKeys.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = (Set) m.get(attrName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (vals.isEmpty()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster continue;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (attrName.equalsIgnoreCase(ADDITIONAL_PROPERTIES_ATTR)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator attrs = vals.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (attrs.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String compositeVal = (String) attrs.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int index = compositeVal.indexOf(EQUALS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String propName = compositeVal.substring(0, index);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String propVal = compositeVal.substring(index + 1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addToMap(props, propName, propVal);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String propertyName = (String) LDAPToSchema.get(attrName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (propertyName != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addToMap(props, propertyName, vals);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return props;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void addToMap(Map m, String key, String val) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set s = (Set) m.get(key);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (s == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster s = new HashSet(2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster m.put(key, s);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // works on the Set in the Map, so we dont need another put.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster s.add(val);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void addToMap(Map m, String key, Set vals) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set s = (Set) m.get(key);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (s == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster m.put(key, vals);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster s.addAll(vals);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Gets the profile manager xlob as a string. Used by the MAPClientDetector.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return ProfileManager.xml
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getProfileManagerXML() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String profileManagerXML = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = getServiceAttribute(PROFILE_MANAGER_XML_ATTR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (vals != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator iter = vals.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster profileManagerXML = (String) iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return profileManagerXML;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get a dsame attribute from the internal/external service. used by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * getProfileManagerXML()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attributeName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The name of the attribute.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return String The attribute as a string
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Set getServiceAttribute(String attributeName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set set = getServiceAttribute(clientServiceSchema, attributeName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Set getServiceAttribute(ServiceSchema schema, String attributeName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set set = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = schema.getAttributeDefaults();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (map != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster set = (Set) map.get(attributeName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get a Set of all the Property names for the classification. Valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * classifications are:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <ol>
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 * </ol>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Set of PropertyNames belonging to classification or null if
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * nothing exists.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set getPropertyNames(String classification) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set names = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (classification != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster names = getServiceAttribute(classification);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return names;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Checks if the clientType exists in the db.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if present, false otherwise
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean isClientPresent(String clientType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dn = generateClientDN(clientType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean exists = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = amConnection.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster exists = amEntity.isExists();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException ssoe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Cannot happen since we are using the AdminToken
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return exists;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Get the value of the clientType property from the Map.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return The value of the "clientType" property
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String getClientType(Map props) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String clientType = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set tmpVals = (Set) props.get(CLIENT_TYPE);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tmpVals != null && tmpVals.size() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator itr = tmpVals.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientType = (String) itr.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return clientType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Map getKnownProperties(Map allProps) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map newPropsMap = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set addProps = new HashSet(5);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator itr = allProps.keySet().iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (itr.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String propName = (String) itr.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ldapAttrName = (String) schemaToLDAP.get(propName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = (Set) allProps.get(propName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ldapAttrName == null) // not in schema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((vals == null) || (vals.isEmpty())) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster continue;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String val = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator innerItr = vals.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (innerItr.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String prop = (String) innerItr.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // separate multi-values with comma
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster val = (val == null) ? prop : val + COMMA + prop;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addProps.add(propName + ADD_PROP_SEPARATOR + val);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster newPropsMap.put(ldapAttrName, vals);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Add to the ADDITIONAL_PROPERTIES_ATTR in clientschema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (addProps.size() > 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set e = (Set) allProps.get(ADD_PROPS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (e != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addProps.addAll(e); // add if the allProps came with one.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster newPropsMap.put(ADDITIONAL_PROPERTIES_ATTR, addProps);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return newPropsMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
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 *
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 * ("&lt;space&gt;") 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 *
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 *
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int addClient(SSOToken token, Map props) throws AMClientCapException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int status = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ct = getClientType(props);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map m = getKnownProperties(props);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map entityMap = new HashMap(1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster entityMap.put(ct, m);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
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 } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] errArgs = { ct };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMClientCapException ace = new AMClientCapException(BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ADD_FAILED, errArgs);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = ace.getMessage();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + msg, e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw ace;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return status;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
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 * ("&lt;space&gt;") 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 *
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 *
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 *
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int modifyClient(SSOToken token, Map props)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws AMClientCapException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int status = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (isInternalInstance()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMClientCapException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BUNDLE_NAME, CANNOT_MOD_INT_DB, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ct = getClientType(props);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMStoreConnection localConn = new AMStoreConnection(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dn = generateClientDN(ct);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = localConn.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (amEntity.isExists()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map m = getKnownProperties(props);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster m.remove(CLIENTTYPE_ATTR); // modify shouldn't have the RDN
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amEntity.setAttributes(m);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amEntity.store();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Need to add if the entry doesn't exist
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster status = addClient(token, props);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] errArgs = { ct };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMClientCapException ace = new AMClientCapException(BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster MODIFY_FAILED, errArgs);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = ace.getMessage();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + msg, e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw ace;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return status;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Remove a Client - removes the client from the externalDB. Valid only with
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * instance of externalDB.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param token
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * SSOToken to validate the user
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param clientType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Client Type Name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return 0 on success
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @exception AMClientCapException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if Client could not be removed - permission problems
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int removeClient(SSOToken token, String clientType)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws AMClientCapException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (isInternalInstance()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMClientCapException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster BUNDLE_NAME, CANNOT_MOD_INT_DB, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMStoreConnection localConn = new AMStoreConnection(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dn = generateClientDN(clientType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = localConn.getEntity(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amEntity.delete();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String[] errArgs = { clientType };
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMClientCapException ace = new AMClientCapException(BUNDLE_NAME,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster DELETE_FAILED, errArgs);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String msg = ace.getMessage();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + msg, e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw ace;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
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 *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a Set of "defined" property names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public synchronized static Set getSchemaElements() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = getSchemaMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set set = map.keySet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
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 *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param propName Name of the property
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return com.sun.identity.sm.AttributeSchema Look at OpenSSO
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * API
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.sun.identity.sm.AttributeSchema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public AttributeSchema getAttributeSchema(String propName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map map = getSchemaMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema attrSchema = (AttributeSchema) map.get(propName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return attrSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Cache for the attribute schemas.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private synchronized static Map getSchemaMap() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (schemaMap == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set set = clientSchema.getAttributeSchemas();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster schemaMap = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator itr = set.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (itr.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema prop = (AttributeSchema) itr.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = prop.getName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster schemaMap.put(name, prop);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return schemaMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Checks the enableClientCliention attr in Service. Used by the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * ClientTypesManager when creating new Clients in the internal DB.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true/false
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public boolean canCreateInternalClients() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean allow = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set vals = getServiceAttribute(ENABLE_CLIENT_CREATION_ATTR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (vals != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator iter = vals.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Boolean perms = Boolean.valueOf((String)iter.next());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster allow = perms.booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return allow;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * register for listening to Client data changes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void addListener(AMClientDataListener cdl) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (listeners) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!listeners.contains(cdl)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster listeners.add(cdl);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // The ServiceListener interface methods
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void eventError(String err) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Handled eventError() Notification: " + err);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void entryChanged(DSEvent event) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dn = event.getID();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington DN ldapName = DN.valueOf(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("entryChanged() Notification for: " + dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington if (ldapName.size() < 2) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return; // cannot notify correctly !
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String ct = LDAPUtils.rdnValue(ldapName.rdn());
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington String db = LDAPUtils.rdnValue(ldapName.parent().rdn());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int type = event.getEventType();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (db == null || ct == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int dbType = -1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (db.equalsIgnoreCase(INTERNAL_DB)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbType = INTERNAL;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (db.equalsIgnoreCase(EXTERNAL_DB)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dbType = EXTERNAL;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Unknown db: " + db + " : client = " + ct);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return; // unknown dbType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("Notifying Listeners:: ClientType = " + ct
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + " : DB = " + dbType + " : OP = " + type);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (listeners) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int size = listeners.size();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (int i = 0; i < size; i++) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMClientDataListener cdl = (AMClientDataListener) listeners
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .get(i);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cdl.clientChanged(ct, dbType, type);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Throwable t) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("Event Notification failed: ", t);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // TODO Add code here to handle the situation of all entries changed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void allEntriesChanged() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the valid classifications.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String[] getClassifications() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return dsameAttributeNames;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Demand Load stuff
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Gets a minimal set of client properties for all clients.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
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 */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set getMinimalClientInfo() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set clients = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMSearchControl amsrchCntrl = new AMSearchControl();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amsrchCntrl.setReturnAttributes(minClient);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster long st = System.currentTimeMillis();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMSearchResults results = amClientOrg.searchEntities("*",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amsrchCntrl, null, UMS_SRCH_TEMPLATE_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster long end = System.currentTimeMillis();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message(dbStr
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "getMinimalClientInfo() Srch Time (ms) = "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + (end - st));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster st = System.currentTimeMillis();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map m = results.getResultAttributes();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator keys = m.keySet().iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (keys.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dn = (String) keys.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map attrsMap = (Map) m.get(dn);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map data = parsePropertyNames(attrsMap);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clients.add(data);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster end = System.currentTimeMillis();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message(dbStr
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "getMinimalClientInfo() Parse Time (ms) = "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + (end - st));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error(dbStr + " getMinimalClientInfo(): Search Error: ", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return clients;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#getBase()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getBase() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return clientDataDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#getFilter()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getFilter() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return SEARCH_FILTER;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#getOperations()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int getOperations() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return OPERATIONS;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#getScope()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public int getScope() {
bee2440354b4bc8796e1de0b6cbd60e1f68deba0Phill Cunnington return SearchScope.WHOLE_SUBTREE.intValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (non-Javadoc)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @see com.iplanet.services.ldap.event.IDSEventListener#setListener()
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setListeners(Map listener) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // noop.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}