8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2009 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: BackwardCompSupport.java,v 1.1 2009/09/05 01:30:45 veiming Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted [2011] [ForgeRock AS]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.common;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.am.sdk.AMObject;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.common.admin.AdminInterfaceUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.idm.IdType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.AttributeSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceManager;
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 Fosterpublic class BackwardCompSupport {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static BackwardCompSupport instance;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String DEBUG_NAME = "common";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Map mapIdTypeToServiceName = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Map mapIdTypeToSchemaType = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Map mapIdTypeToSubSchemaName = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String namingAttribute = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private BackwardCompSupport() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToServiceName.put(IdType.USER.getName(),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "iPlanetAMUserService");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToSchemaType.put(IdType.USER.getName(), "user");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToServiceName.put(IdType.AGENT.getName(),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "iPlanetAMAgentService");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToSchemaType.put(IdType.AGENT.getName(), "user");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToServiceName.put(IdType.GROUP.getName(),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "iPlanetAMEntrySpecificService");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToSubSchemaName.put(IdType.GROUP.getName(), "Group");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToServiceName.put(IdType.ROLE.getName(),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "iPlanetAMEntrySpecificService");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToSubSchemaName.put(IdType.ROLE.getName(), "Role");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToServiceName.put(IdType.FILTEREDROLE.getName(),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "iPlanetAMEntrySpecificService");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapIdTypeToSubSchemaName.put(IdType.FILTEREDROLE.getName(),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "FilteredRole");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (ServiceManager.isAMSDKEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster namingAttribute = AdminInterfaceUtils.getNamingAttribute(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMObject.USER, Debug.getInstance(DEBUG_NAME));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Since naming attribute cannot be obtained for IdRepo
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // hardcode to "uid"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster namingAttribute = "uid";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static BackwardCompSupport getInstance() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (instance == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster instance = new BackwardCompSupport();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return instance;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getServiceName(String idType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (String)mapIdTypeToServiceName.get(idType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getSchemaType(String idType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (String)mapIdTypeToSchemaType.get(idType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getSubSchemaName(String idType) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (String)mapIdTypeToSubSchemaName.get(idType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void beforeDisplay(String idType, Set attributeSchemas) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idType != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idType.equalsIgnoreCase(IdType.USER.getName())) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster beforeDisplayUser(attributeSchemas);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void beforeDisplayUser(Set attributeSchemas) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = attributeSchemas.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema as = (AttributeSchema)iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = as.getName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (name.equals(namingAttribute) || name.equals("ChangePassword")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster iter.remove();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void beforeCreate(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String idType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idType.equalsIgnoreCase(IdType.USER.getName())) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster beforeCreateUser(idType, entityName, values);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void beforeModify(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String idType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idType.equalsIgnoreCase(IdType.USER.getName())) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster beforeModifyUser(idType, entityName, values);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void beforeCreateUser(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String idType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set set = new HashSet(2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster set.add(entityName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster values.put(namingAttribute, set);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void beforeModifyUser(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String idType,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String entityName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map values
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set set = new HashSet(2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster set.add(entityName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster values.put(namingAttribute, set);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}