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: AMAuthenticationSchema.java,v 1.3 2008/06/25 05:41:52 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.AttributeSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SchemaException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSException;
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 Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This class implements a subset of the service schema operations
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * for the <code>AMModule</code> instance.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class AMAuthenticationSchema
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private ServiceSchema serviceSchema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected AMAuthenticationSchema(ServiceSchema schema) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster serviceSchema = schema;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the name of this schema.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a String value of the schema name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return serviceSchema.getName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the name of the service schema.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the name of the service schema.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getServiceName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return serviceSchema.getServiceName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a set of required attribute names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a <code>Set</code> of the required attribute names of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the subject schema.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set getRequiredAttributeNames() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set names = new HashSet();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator it = getAttributeNames().iterator(); it.hasNext(); ){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String attr = (String)it.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema as = getAttributeSchema(attr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String anyValue = as.getAny();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (anyValue != null && (anyValue.indexOf("required") != -1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster names.add(attr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return names;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a set of all the attribute names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a <code>Set</code> of all the attribute names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set getAttributeNames(){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return serviceSchema.getAttributeSchemaNames();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns an <code>AttributeSchema</code> of the specified attribute name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attr the specified attribute name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the <code>AttributeSchema</code> of the attribute.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public AttributeSchema getAttributeSchema(String attr) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return serviceSchema.getAttributeSchema(attr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a Set which contains all the <code>AttributeSchemas</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Set of <code>AttributeSchema</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Set getAttributeSchemas() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return serviceSchema.getAttributeSchemas();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the default values for all the attributes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a <code>Map</code> that contains all the default attributes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and their values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map getAttributeValues(){
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return serviceSchema.getAttributeDefaults();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the default values for the specified attributes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param names a <code>Set</code> of attribute names in String values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a <code>Map</code> that contains all the default attributes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * and their values for the specified attributes.
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 default attribute values.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param values A map of the names of <code>AttributeSchema</code> to
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * modify, and a Set of Values which should replace the default
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * values of the current schema.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SchemaException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException if an error occurred while performing the operation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the single sign on token is invalid or expired
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setAttributeValues(Map values)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws SchemaException, SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster serviceSchema.setAttributeDefaults(values);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets default value for a specific attribute.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attrName Name of the attribute for which defaults
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * values need to be replaced.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param values Set of new values to replace the old ones.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SchemaException if an error occurred while parsing the XML
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SMSException if an error occurred while performing the operation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws SSOException if the single sign on token is invalid or expired
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setAttribute(String attrName, Set values)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws SchemaException, SMSException, SSOException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster serviceSchema.setAttributeDefaults(attrName, values);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}