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: AMAuthenticationInstance.java,v 1.2 2008/06/25 05:41:51 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.authentication.config;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceConfig;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Iterator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class provides implementation of an individual instance
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of a module type. A module instance has a name, type and
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * its own configuration data, which can be accessed through
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>ServiceConfig</code> interface.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class AMAuthenticationInstance {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String moduleName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String moduleType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private ServiceConfig serviceConfig = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private ServiceSchema globalSchema = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructs a module instance object. This constructor can
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * only be called through <code>ModuleInstanceManager</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name The name of the module instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param type The type this module belongs to. e.g. LDAP, JDBC, etc.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param config Service configuration for the module instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected AMAuthenticationInstance(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String type,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceConfig config,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceSchema global) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster moduleName = name;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster moduleType = type;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster serviceConfig = config;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster globalSchema = global;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the name of the module instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Name of the module instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return moduleName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the type of the module instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Type of the module instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getType() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return moduleType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a <code>ServiceConfig</code> instance which can be used to access
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and make changes to the module instance configuration data.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return A <code>ServiceConfig</code> object for this module instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public ServiceConfig getServiceConfig() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return serviceConfig;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the configuration attributes of the module instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Map of attribute name to a set of attribute values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map getAttributeValues(){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map org = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (serviceConfig != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster org = serviceConfig.getAttributes();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map global = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (globalSchema != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster global = globalSchema.getAttributeDefaults();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster HashMap totalAttrs = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (global != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster totalAttrs.putAll(global);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (org != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster totalAttrs.putAll(org);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return totalAttrs;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the configuration attribute values for the specified attributes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param names Set of specified attributes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Map of attribute name to a set of attribute values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map getAttributeValues(Set names) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map allAttrs = getAttributeValues();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map attrs = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator it = names.iterator(); it.hasNext(); ){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object key = it.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (allAttrs.containsKey(key)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrs.put(key, allAttrs.get(key));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return attrs;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the configuration parameters. This method will replace the existing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * attribute values with the given ones. For attributes that are not in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>values</code>, they will not be modified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param values the <code>Map</code> in which keys are the attribute names
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and values are the <code>Set</code> of attribute values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException if there is an error occurred while performing the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * operation.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the user's SSO token is invalid or expired.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setAttributeValues(Map values)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (serviceConfig != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster serviceConfig.setAttributes(values);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets a configuration parameter with the specified value
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>values</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name the name of the attribute to be set.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param values the <code>Set</code> of values for that attribute.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException if there is an error occurred while performing the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * operation.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the user's SSO token is invalid or expired.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setAttribute(String name, Set values)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (serviceConfig != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster serviceConfig.addAttribute(name, values);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}