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: AuthConfigurationEntry.java,v 1.4 2008/06/25 05:41:52 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.authentication.config;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.io.Serializable;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport org.w3c.dom.Node;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Represents one Authentication Configuration Entry
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class AuthConfigurationEntry implements Serializable {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = Debug.getInstance("amAuthConfig");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String module = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String flag = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String options = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructor.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param module Login Module class name example
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>com.sun.identity.authentication.modules.ldap.LDAP</code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param flag Control flag, one of
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code>REQUIRED, OPTIONAL, REQUISITE, SUFFICIENT</code>
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param options Options as space separated string.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws AMConfigurationException if module or flag is null or flag is
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * invalid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public AuthConfigurationEntry(String module, String flag, String options)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws AMConfigurationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster checkModule(module);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster checkFlag(flag);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.module = module;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.flag = flag;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.options = options;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructor.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected AuthConfigurationEntry(Node node)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws AMConfigurationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("AuthConfigEntry, value=" + node.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String value = node.getFirstChild().getNodeValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (value == null || value.length() == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("AuthConfigEntry, invalid value=" + value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMConfigurationException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.bundleName, "invalidConfig");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = value.trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int pos = value.indexOf(" ");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (pos == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("AuthConfigEntry, invalid value=" + value);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMConfigurationException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.bundleName, "invalidConfig");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // set module
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.module = value.substring(0, pos);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = value.substring(pos + 1).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster pos = value.indexOf(" ");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (pos == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // no options
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.flag = value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.flag = value.substring(0, pos);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.options = value.substring(pos + 1).trim();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster checkFlag(this.flag);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns string representation of this object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return string representation of this object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String toString() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (options == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return module + " " + flag;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return module + " " + flag + " " + options;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns login module name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return login module name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getLoginModuleName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return module;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets login module name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param moduleName module name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws AMConfigurationException if module is null.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setLoginModuleName(String moduleName)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws AMConfigurationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster checkModule(moduleName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster module = moduleName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns control flag .
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return control flag .
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getControlFlag() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return flag;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets control flag.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param flag control flag
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws AMConfigurationException if flag is null or invalid.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setControlFlag(String flag) throws AMConfigurationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster checkFlag(flag);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.flag = flag;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns options.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return options.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getOptions() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return options;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets options.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param options
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setOptions(String options) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster this.options = options;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void checkModule(String module) throws AMConfigurationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (module == null || module.length() == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMConfigurationException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.bundleName, "invalidConfig");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void checkFlag(String flag) throws AMConfigurationException{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (flag == null || flag.length() == 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMConfigurationException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.bundleName, "invalidConfig");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (!flag.equalsIgnoreCase("REQUIRED") &&
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster !flag.equalsIgnoreCase("OPTIONAL") &&
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster !flag.equalsIgnoreCase("REQUISITE") &&
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster !flag.equalsIgnoreCase("SUFFICIENT")) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.warning("AuthConfigEntry, invalid flag : " + flag);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new AMConfigurationException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.bundleName, "invalidConfig");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}