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: AMAuthConfigType.java,v 1.3 2008/06/25 05:41:51 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.authentication.config;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Represents an Authentication Configuration type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class AMAuthConfigType {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = Debug.getInstance("amAuthConfig");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final int USER = 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final int ORGANIZATION = 2;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final int ROLE = 3;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final int SERVICE = 4;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final int MODULE = 5;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String configName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String orgDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String indexName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String clientType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private int indexType = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigType (String name) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // parse the configuration name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (name.startsWith(AMAuthConfigUtils.MODULE_KEY)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for organization dn
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int orgP = name.indexOf(";" + AMAuthConfigUtils.ORG_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for client type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int cliP = name.indexOf(";" + AMAuthConfigUtils.CLIENT_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (orgP == -1 || cliP == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // invalid config name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Invalid module config name " + name);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // valid module index
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexType = MODULE;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexName = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.MODULE_KEY.length() + 1, orgP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgDN = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgP + AMAuthConfigUtils.ORG_KEY.length() + 2, cliP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientType = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cliP + AMAuthConfigUtils.CLIENT_KEY.length() + 2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (name.startsWith(AMAuthConfigUtils.USER_KEY)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for organization dn
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int orgP = name.indexOf(";" + AMAuthConfigUtils.ORG_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for client type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int cliP = name.indexOf(";" + AMAuthConfigUtils.CLIENT_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (orgP == -1 || cliP == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // invalid config name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Invalid module config name " + name);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // valid user index
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexType = USER;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexName = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.USER_KEY.length() + 1, orgP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgDN = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgP + AMAuthConfigUtils.ORG_KEY.length() + 2, cliP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientType = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cliP + AMAuthConfigUtils.CLIENT_KEY.length() + 2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (name.startsWith(AMAuthConfigUtils.ORG_KEY)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for client type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int cliP = name.indexOf(";" + AMAuthConfigUtils.CLIENT_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (cliP == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // invalid config name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Invalid module config name " + name);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // valid organization index
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexType = ORGANIZATION;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexName = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.ORG_KEY.length() + 1, cliP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgDN = indexName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientType = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cliP + AMAuthConfigUtils.CLIENT_KEY.length() + 2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (name.startsWith(AMAuthConfigUtils.SERVICE_KEY)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for organization dn
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int orgP = name.indexOf(";" + AMAuthConfigUtils.ORG_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for client type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int cliP = name.indexOf(";" + AMAuthConfigUtils.CLIENT_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (orgP == -1 || cliP == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // invalid config name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Invalid module config name " + name);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // valid service index
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexType = SERVICE;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexName = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.SERVICE_KEY.length() + 1, orgP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgDN = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgP + AMAuthConfigUtils.ORG_KEY.length() + 2, cliP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientType = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cliP + AMAuthConfigUtils.CLIENT_KEY.length() + 2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (name.startsWith(AMAuthConfigUtils.ROLE_KEY)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for organization dn
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int orgP = name.indexOf(";" + AMAuthConfigUtils.ORG_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // index point for client type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int cliP = name.indexOf(";" + AMAuthConfigUtils.CLIENT_KEY + "=");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (orgP == -1 || cliP == -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // invalid config name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("Invalid module config name " + name);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // valid role index
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexType = ROLE;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster indexName = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.ROLE_KEY.length() + 1, orgP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgDN = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgP + AMAuthConfigUtils.ORG_KEY.length() + 2, cliP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster clientType = name.substring(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster cliP + AMAuthConfigUtils.CLIENT_KEY.length() + 2);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // invalid index type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("Invalid index type in config name " + name);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("indexType = " + indexType +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "\nindexName=" + indexName +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "\norgDN=" + orgDN +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "\nclientType=" + clientType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * return organization DN
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String getOrganization() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return orgDN;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * return client type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String getClientType() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return clientType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * return index name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String getIndexName() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return indexName;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * return index type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int getIndexType() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return indexType;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}