AMClientCapData.java revision cc87cf22700a4a41bf0eba0d9579db53e7cedd94
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
*
* The contents of this file are subject to the terms
* of the Common Development and Distribution License
* (the License). You may not use this file except in
* compliance with the License.
*
* You can obtain a copy of the License at
* See the License for the specific language governing
* permission and limitations under the License.
*
* When distributing Covered Code, include this CDDL
* Header Notice in each file and include the License file
* at opensso/legal/CDDLv1.0.txt.
* If applicable, add the following below the CDDL Header,
* with the fields enclosed by brackets [] replaced by
* your own identifying information:
* "Portions Copyrighted [year] [name of copyright owner]"
*
* $Id: AMClientCapData.java,v 1.7 2009/01/28 05:34:49 ww203982 Exp $
*
* Portions Copyrighted 2010-2016 ForgeRock AS.
*/
/**
* stored as a DIT in directory server with the properties as attributes.
*/
public class AMClientCapData implements IDSEventListener {
//
// static stuff
//
//
// The service name
//
//
// To be overriden when read from config
//
//
// Error codes
//
//
// Begin attribute/schema names from amClientData.xml //
//
//
// The attribute names in the service.
// Used by console plug-in. Should match the attribute names in the
// Service definition xml.
//
private static final String[] dsameAttributeNames = {
"generalPropertyNames", "hardwarePlatformNames",
"softwarePlatformNames", "networkCharacteristicsNames",
"browserUANames", "wapCharacteristicsNames",
"pushCharacteristicsNames", "additionalPropertiesNames" };
//
// Integer representation of the db.
//
public static final int INTERNAL = 1;
public static final int EXTERNAL = 2;
/**
* The type of modification
*/
//
// The OU of the DN is the clientType for the device.
//
+ ADD_PROPS;
private static final String ENABLE_CLIENT_CREATION_ATTR =
"enableClientCreation";
// End - attribute/schema names from amClientData.xml //
//
// The dn to reach the ou=1.0,ou=SunAMClientData,..
//
private static String CLIENT_DATA_DN_PREFIX =
"ou=1.0,ou=SunAMClientData,ou=ClientData";
//
// The actual internal & external instance objects.
//
//
// The schema for the service.
//
//
// Schema for the client data.
//
//
// Needed since OpenAM retrieves all LDAP attrs in lowercase &
// also since we prefix client attrs with "sunamclient"
//
// Persistent search related values
+ CLIENT_OBJECTCLASS + ")";
// BEGIN: per-instance variables //
//
// int representing the db instance
//
private int databaseType = 0;
//
// DSAME Object to access the AMOrganizationalUnit
//
//
// The dn to reach the ou=internaldata,..
//
// END per-instance vars. //
if (isInternalInstance()) {
} else {
}
}
/**
* 1. get the admin token (or create one) 2. Create a ServiceManager 3. Get
* the ServiceSchemaManager for the service 4. Get the ServiceSchema for the
* Global schema 5. Get the schema for the "internalData" schema. (temp
* var). 6. Get the schema for the "clientData" schema id. (overwrite 8). 7.
* Get the ROOT_SUFFIX 8. Read config info & properties schema from
* ServiceSchema 9. Add Listeners to EventService.
*/
//
// the internalDB & externalDB share the same schema (5)
//
initClientSchema(); // (8)
// TBD : Commented so that persistant search is not setup to
// directory server when running in remote client SDK mode.
// This is temporary fix. Proper fix for this problem is TBD.
// initEventListeners (adminToken, clientDataDN); // (9)
}
}
}
}
}
//
// Default configuration if not obtained from service.
//
}
}
while (st.hasMoreElements()) {
} else {
}
}
return;
}
/**
* @return true if databaseType == INTERNAL
*/
private boolean isInternalInstance() {
return (databaseType == INTERNAL);
}
private static void initClientSchema() {
//
// Map clientType to OU
//
}
}
return;
}
/**
* @return the serviceName. Used by the console plug-in to get to the
* resource bundle.
*/
public String getServiceName() {
return (SERVICE_NAME);
}
/**
* Singleton method to get an internal instance
*/
public synchronized static AMClientCapData getInternalInstance()
throws AMClientCapException {
if (internalInstance == null) {
try {
} catch (Exception e) {
throw new AMClientCapException(
}
}
return internalInstance;
}
/**
* Singleton method to get an external instance
*/
public synchronized static AMClientCapData getExternalInstance()
throws AMClientCapException {
if (externalInstance == null) {
try {
} catch (Exception e) {
throw new AMClientCapException(
}
}
return externalInstance;
}
/**
* @return the dn for the client
*/
}
/**
* Get a Map of all the properties for the Client. The Map contains key of
* property names and a Set for the values.
*
* @param clientType
* Client Type Name.
* @return Map of the properties or null if client not found
*/
try {
}
} catch (SSOException ssoe) {
// admin token has timed out, retry
adminToken = null;
if (isInternalInstance()) {
} else {
}
try {
}
}
}
return props;
}
/**
* Gets the minimal client info for the specified client.
*/
try {
}
} catch (Exception e) {
}
return props;
}
/**
* The ldap attribute names for the client properties and prefixed with
* "sunamclient" to make them unique. This method gets the ldap attrs and
* converts them to client property names.
*/
continue;
}
}
} else {
if (propertyName != null) {
}
}
}
return props;
}
if (s == null) {
s = new HashSet(2);
}
// works on the Set in the Map, so we dont need another put.
}
if (s == null) {
} else {
}
return;
}
/**
* Gets the profile manager xlob as a string. Used by the MAPClientDetector.
*
* @return ProfileManager.xml
*/
public String getProfileManagerXML() {
}
return profileManagerXML;
}
/**
* getProfileManagerXML()
*
* @param attributeName
* The name of the attribute.
* @return String The attribute as a string
*/
return set;
}
{
}
return set;
}
/**
* Get a Set of all the Property names for the classification. Valid
* classifications are:
* <ol>
* <li>generalPropertyNames</li>
* <li>hardwarePlatformNames</li>
* <li>softwarePlatformNames</li>
* <li>networkCharacteristicsNames</li>
* <li>browserUANames</li>
* <li>wapCharacteristicsNames</li>
* <li>pushCharacteristicsNames</li>
* <li>additionalPropertiesNames</li>
* </ol>
*
* @return Set of PropertyNames belonging to classification or null if
* nothing exists.
*/
if (classification != null) {
}
return names;
}
/**
* Checks if the clientType exists in the db.
*
* @return true if present, false otherwise
*/
boolean exists = false;
try {
} catch (SSOException ssoe) {
/**
* Cannot happen since we are using the AdminToken
*/
}
return exists;
}
/**
* Get the value of the clientType property from the Map.
*
* @return The value of the "clientType" property
*/
}
return clientType;
}
/**
* Parse the allProps Map and return the known properties, and the
* additional ones in a Set of name=value Strings with the Map index being
* the ldap attr "sunamclientadditionalProperties"
*/
{
continue;
}
// separate multi-values with comma
}
} else {
}
}
//
// Add to the ADDITIONAL_PROPERTIES_ATTR in clientschema
//
if (e != null) {
}
}
return newPropsMap;
}
/**
* Add a client. For every property in the Map, it looks up the schema to
* check if the property is known, if not known adds it to the
* additionalProperties schema element. <br>
*
* <b>Note: To add a property in the external db to mask the corresponding
* property value in internal db, add the property with a " "
* ("<space>") not an empty "" string. This is required because, when
* dsame fetches the value from directory and sees it has no value, it
* returns an empty set. (And we discard empty sets internally - bcos dsame
* stores values for every property defined in the schema).</b>
*
* @param token
* SSOToken to validate the user
* @param props
* Map of profiles known to ClientCap. The Map "must" have a
* property "clientType"
*
* @return 0 on success
* @exception AMClientCapException
* if Client could not be added - permission problems or if
* the clientType property is mising in the Map.
*/
{
int status = 0;
try {
} catch (Exception e) {
throw ace;
}
return status;
}
/**
* Modify the properties of the Client instance in externalDB. Valid only
* with instance of externalDB. <br>
* <b>Note: To add a property in the external db to mask the corresponding
* property value in internal db, add the property with a " "
* ("<space>") not an empty "" string. This is required because, when
* dsame fetches the value from directory and sees it has no value, it
* returns an empty set. (And we discard empty sets internally - bcos dsame
* stores values for every property defined in the schema).</b>
*
* Also, if the additionalProperties are being modified, it should contain
* both the modified and the unmodified ones. This is required since all the
* additionalProperties are stored in a single Attribute
* "additionalProperties".
*
* @param token
* SSOToken to validate the user.
* @param props
* Map of profiles known to ClientCapabilities. The Map contains
* key of property name(s) and Set for the values. It wont
* overwrite the property names not in the Map. A key with an
* empty Set for the values will delete the property (DSAME
* cannot handle null values - throws NullPointerExcptn). The Map
* "must" have a property "clientType"
*
* @return 0 on success
* @exception AMClientCapException
* if Client could not be modified - permission problems OR
* if the clientType property is mising in the Map.
*/
throws AMClientCapException {
int status = 0;
if (isInternalInstance()) {
throw new AMClientCapException(
}
try {
} else {
//
// Need to add if the entry doesn't exist
//
}
} catch (Exception e) {
throw ace;
}
return status;
}
/**
* Remove a Client - removes the client from the externalDB. Valid only with
* instance of externalDB.
*
* @param token
* SSOToken to validate the user
* @param clientType
* Client Type Name.
*
* @return 0 on success
* @exception AMClientCapException
* if Client could not be removed - permission problems
*/
throws AMClientCapException {
if (isInternalInstance()) {
throw new AMClientCapException(
}
try {
} catch (Exception e) {
throw ace;
}
return 0;
}
/**
* This method returns the name of the "defined" client properties in the
* Schema. To get the AttributeSchema of these elements, iterate through
* each of these names and call the getAttributeSchema() on it. Can be used
*
* @return a Set of "defined" property names.
*/
public synchronized static Set getSchemaElements() {
return set;
}
/**
* Returns the schema for an property given the name. Can be used with
*
* @param propName Name of the property
* @return com.sun.identity.sm.AttributeSchema Look at OpenSSO
* API
*
* @see com.sun.identity.sm.AttributeSchema
*/
return attrSchema;
}
/**
* Cache for the attribute schemas.
*/
private synchronized static Map getSchemaMap() {
}
}
return schemaMap;
}
/**
* Checks the enableClientCliention attr in Service. Used by the
* ClientTypesManager when creating new Clients in the internal DB.
*
*/
public boolean canCreateInternalClients() {
boolean allow = false;
}
return allow;
}
/**
* register for listening to Client data changes
*/
synchronized (listeners) {
}
}
}
//
// The ServiceListener interface methods
//
}
if (debug.messageEnabled()) {
}
return; // cannot notify correctly !
}
return;
}
int dbType = -1;
} else {
return; // unknown dbType
}
if (debug.messageEnabled()) {
}
synchronized (listeners) {
for (int i = 0; i < size; i++) {
.get(i);
try {
} catch (Throwable t) {
}
}
}
return;
}
// TODO Add code here to handle the situation of all entries changed.
public void allEntriesChanged() {
}
/**
* @return the valid classifications.
*/
public String[] getClassifications() {
return dsameAttributeNames;
}
/**
* Demand Load stuff
*/
/**
* Gets a minimal set of client properties for all clients.
*
* @return Set of Maps. Each Map has the propertyNames for the Key and Value
* is Set of Property values. By default, the keys returned are
* clientType, userAgent & parentID.
*/
public Set getMinimalClientInfo() {
try {
long st = currentTimeMillis();
long end = currentTimeMillis();
if (debug.messageEnabled()) {
+ "getMinimalClientInfo() Srch Time (ms) = "
}
st = currentTimeMillis();
}
end = currentTimeMillis();
if (debug.messageEnabled()) {
+ "getMinimalClientInfo() Parse Time (ms) = "
}
} catch (Exception e) {
}
return clients;
}
/*
* (non-Javadoc)
*
* @see com.iplanet.services.ldap.event.IDSEventListener#getBase()
*/
return clientDataDN;
}
/*
* (non-Javadoc)
*
* @see com.iplanet.services.ldap.event.IDSEventListener#getFilter()
*/
return SEARCH_FILTER;
}
/*
* (non-Javadoc)
*
* @see com.iplanet.services.ldap.event.IDSEventListener#getOperations()
*/
public int getOperations() {
return OPERATIONS;
}
/*
* (non-Javadoc)
*
* @see com.iplanet.services.ldap.event.IDSEventListener#getScope()
*/
public int getScope() {
}
/*
* (non-Javadoc)
*
* @see com.iplanet.services.ldap.event.IDSEventListener#setListener()
*/
// noop.
}
}