8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
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: EntityObjectImpl.java,v 1.3 2008/06/25 05:43:26 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.entity;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.rmi.RemoteException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Iterator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMConstants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMEntity;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMEntityType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMOrganization;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMStoreConnection;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.util.Cache;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOToken;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOTokenManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Implementation class for the interface EntityObjectIF
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class EntityObjectImpl implements EntityObjectIF {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static Cache oCache;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static Object lock = new Object();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected SSOToken token;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected AMStoreConnection amsc;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected AMOrganization entity = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static SSOTokenManager tokenManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates entities.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param ssotoken
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * String representing user's SSO Token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityName
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Name of this entity.eg.cn=websphereAgent
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Type of entity being created. eg. Agent The types supported by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * SDK are configured in the list of Managed Objects in the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>DAI</code> service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityLocation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Location of the entity creation.eg.www.abc.com
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attributes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Map to represent Attribute-Value Pairs
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Returns a set of Entity DNs created.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws EntityException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if there is an internal error in the AM Store
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if the sign on is no longer valid
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set createEntity(String ssotoken, String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityType, String entityLocation, Map attributes)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws EntityException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set entitySet = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster initializeObject(ssotoken, entityLocation);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int type = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster type = getIntTypeFromStr(entityType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map input = new HashMap(2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster input.put(entityName, attributes);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (entity != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set entityObjs = entity.createEntities(type, input);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator it = entityObjs.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (it.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster entitySet.add(((AMEntity) it.next()).getDN());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (AMException amex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.error("EntityObjectImpl.createEntity() : "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Create Entity Failed. " + amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw EntityUtils.convertException(amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return entitySet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Deletes entities.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param ssoToken User's Single Sign On Token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityName Name of this entity. example
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>cn=websphereAgent</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityType Type of entity being created. eg. Agent The types
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * supported by SDK are configured in the list of Managed Objects
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * in the <code>DAI</code> service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityLocation Location of the entity creation. example
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>www.abc.com</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws EntityException if there is an internal error in the AM Store.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the sign on is no longer valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void deleteEntity(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ssoToken,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityLocation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws EntityException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster initializeObject(ssoToken, entityLocation);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set entityNameSet = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int type = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster type = getIntTypeFromStr(entityType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entDN = getEntityDN(entityName, type, entityLocation);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster entityNameSet.add(entDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (entity != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster entity.deleteEntities(type, entityNameSet);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (EntityUtils.debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .message("EntityObjectImpl.deleteEntity():"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + " Deleted " + entityNameSet.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (AMException amex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.error("EntityObjectImpl.deleteEntity() : "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Delete Entity Failed. " + amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw EntityUtils.convertException(amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the entity object for each entity given the entityType and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * entityName(s) in that particular organization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param ssoToken User's Single Sign On Token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityName Name of this entity. example
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>cn=websphereAgent</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityType Type of entity being created. eg. Agent The types
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * supported by SDK are configured in the list of Managed Objects
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * in the <code>DAI</code> service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityLocation Location of the entity creation. example
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>www.abc.com</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Set of Entity objects.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws EntityException if there is an internal error in the AM Store.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the sign on is no longer valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RemoteException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map getEntity(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ssoToken,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityLocation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws EntityException, SSOException, RemoteException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster initializeObject(ssoToken, entityLocation);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map entityMap = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return entityMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a set of Entity Names given the Entity Type for that particular
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * organization.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param ssoToken User's Single Sign On Token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityType Type of entity being created. eg. Agent The types
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * supported by SDK are configured in the list of Managed Objects
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * in the <code>DAI</code> service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityLocation Location of the entity creation. example
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>www.abc.com</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityFilter
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Set of Entity Names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws EntityException if there is an internal error in the AM Store.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the sign on is no longer valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RemoteException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set getEntityNames(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ssoToken,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityLocation,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityFilter
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws EntityException, SSOException, RemoteException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster initializeObject(ssoToken, entityLocation);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set entitySet = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return entitySet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets or replaces attribute values with the new values supplied and Stores
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the changes to directory server.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param ssoToken User's Single Sign Token.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityName Name of this entity. example
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>cn=websphereAgent</code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityType Type of entity being created. eg. Agent The types
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * supported by SDK are configured in the list of Managed Objects
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * in the <code>DAI</code> service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param entityLocation Location of the entity creation. example
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>www.abc.com</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws EntityException if there is an internal error in the AM Store.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the sign on is no longer valid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws RemoteException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void modifyEntity(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ssoToken,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityLocation,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map attributes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws EntityException, SSOException, RemoteException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster initializeObject(ssoToken, entityLocation);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity = getAMEntity(ssoToken, entityName, entityType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster entityLocation);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (amEntity != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amEntity.setAttributes(attributes);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amEntity.store();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (AMException amex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.error("EntityObjectImpl.modifyEntity() : "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Modify Entity Failed. " + amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw EntityUtils.convertException(amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Method to get the token manager handle.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static void checkInitialization() throws SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tokenManager == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster synchronized (lock) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (tokenManager == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tokenManager = SSOTokenManager.getInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster oCache = new Cache(1000);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException ssoe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "EntityObjectImpl:checkInitialization() " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ": Unable to get SSOTokenManager",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw (ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Method to get the AMEntity object from the storeconnection.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected AMEntity getAMEntity(String ssoToken, String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityType, String entityLocation) throws EntityException,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster checkInitialization();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntity amEntity;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int type = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster type = getIntTypeFromStr(entityType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entDN = getEntityDN(entityName, type, entityLocation);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String key = ssoToken + "/" + entDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amEntity = (AMEntity) oCache.get(key);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (amEntity == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amEntity = amsc.getEntity(entDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster oCache.put(key, amEntity);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException ssoe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.error("EntityObjectImpl.getAMEntity(): "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Unable to convert SSOToken: " + ssoToken, ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw ssoe;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return amEntity;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Method to initialize the object. The AMStoreConnection handle is obtained
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * by creating a valid SSOToken.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void initializeObject(String ssoToken, String entityLocation)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws EntityException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster checkInitialization();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster token = tokenManager.createSSOToken(ssoToken);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster amsc = new AMStoreConnection(token);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String orgDN = amsc.getOrganizationDN(entityLocation, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster entity = amsc.getOrganization(orgDN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (AMException amex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.error("EntityObjectImpl.initializeObject() : "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Unable to get Organization DN " + amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw EntityUtils.convertException(amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (SSOException ssoe) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.error("EntityObjectImpl.initializeObject() : "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Unable to convert SSOToken: " + ssoToken, ssoe);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw ssoe;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (EntityUtils.debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.message("EntityObjectImpl.getAMEntity(): "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Obtained ssotoken: " + ssoToken);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.message("EntityObjectImpl.getAMEntity(): "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Obtained AMSToreConnection object for SSOToken: "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + ssoToken);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Method to convert the entity type from string to integer recognizable by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * SDK.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private int getIntTypeFromStr(String entityType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int type = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set supportedTypes = amsc.getEntityTypes();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator iter = supportedTypes.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (iter.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMEntityType amEntityType = (AMEntityType) iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (amEntityType.getName().equalsIgnoreCase(entityType)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster type = amEntityType.getType();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster break;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return type;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Method to get the DN of the entity based on the search results for the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * entityName from the entityLocation.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String getEntityDN(String entityName, int entityType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityLocation) throws EntityException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entDN = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set entityResults = entity.searchEntities(entityType, "*",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMConstants.SCOPE_SUB, new HashMap());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator iter = entityResults.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster while (iter.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster entDN = (String) iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (entDN.indexOf(entityName) >= 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster break;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (AMException amex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntityUtils.debug.error("EntityObjectImpl.getEntityDN() : "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + "Unable to get DN for the Entity " + amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw EntityUtils.convertException(amex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return entDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}