8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2006 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: GatewayServletUtils.java,v 1.5 2008/06/25 05:43:54 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted [2011] [ForgeRock AS]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.policy.util;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.config.AMAuthConfigUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.debug.Debug;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSEntry;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceConfig;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceConfigManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceListener;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Iterator;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class GatewayServletUtils implements ServiceListener {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static Debug debug = Debug.getInstance("amGateway");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String moduleName = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static ServiceConfigManager sConfigMgr = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static String CERT_PORT_ATTR = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static HashMap AuthConfigMap = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // constructor
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public GatewayServletUtils (ServiceConfigManager scm, String module) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sConfigMgr = scm;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster CERT_PORT_ATTR = "iplanet-am-auth-" + module.toLowerCase() +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "-port-number";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster moduleName = module;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method is used to receive notifications if schema changes.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param serviceName the name of the service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param version the version of the service.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void schemaChanged (String serviceName, String version) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //No op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method for implementing ServiceListener.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * As this object listens for changes in schema of amConsoleService.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * this method is No-op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param serviceName name of the service
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param version version of the service
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param groupName name of the group
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param serviceComponent service component
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param type type of modification
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void globalConfigChanged (
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String serviceName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String version,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String groupName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String serviceComponent,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //No op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method for implementing ServiveListener.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * As this object listens for changes in schema of amConsoleService.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * this method is No-op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void organizationConfigChanged () {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster organizationConfigChanged (null, null, null, null, null, 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method for implementing ServiveListener.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * As this object listens for changes in schema of amConsoleService.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * this method is No-op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void organizationConfigChanged (String orgName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster organizationConfigChanged (null, null, orgName, null, null, 0);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method for implementing ServiveListener.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * As this object listens for changes in schema of amConsoleService.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * this method is No-op.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param serviceName name of the service
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param version version of the service
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param orgName name of the org
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param groupName name of the group
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param serviceComponent service component
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param type type of modification
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void organizationConfigChanged (
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String serviceName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String version,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String orgName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String groupName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String serviceComponent,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int type
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String certModulePortNumber = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String certModuleLevel = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (orgName == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orgName = SMSEntry.getRootSuffix();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get the port number for Cert module
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ServiceConfig config =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sConfigMgr.getOrganizationConfig(orgName, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map configAttrs = config.getAttributes();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (debug.messageEnabled()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.message("GatewayServlet:configAttrs : "
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster + configAttrs.toString());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get the cert port number
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set attrs = (Set) configAttrs.get(CERT_PORT_ATTR);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (attrs == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Iterator values = attrs.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (values.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster certModulePortNumber = (String) values.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get cert auth level
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster attrs = (Set) configAttrs.get(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AMAuthConfigUtils.getAuthLevelAttribute(configAttrs, moduleName));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (attrs == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster values = attrs.iterator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (values.hasNext()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster certModuleLevel = (String) values.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthServiceConfigInfo info =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster new AuthServiceConfigInfo(orgName, moduleName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster certModulePortNumber, certModuleLevel);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthConfigMap.put(orgName, info);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug.error("GatewayServletUtils : "+
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "Unable to get Cert Module Level and/or Port Number", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method is used to retrieve port number of Cert auth module.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getPortNumber(String orgName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthServiceConfigInfo info = getAuthConfigInfo(orgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return info.getPortNumber();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method is used to retrieve Auth Level of Cert auth module.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String getAuthLevel(String orgName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthServiceConfigInfo info = getAuthConfigInfo(orgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return info.getAuthLevel();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This method is used to retrieve Auth Level of Cert auth module.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public AuthServiceConfigInfo getAuthConfigInfo(String orgName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AuthServiceConfigInfo info =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster (AuthServiceConfigInfo)AuthConfigMap.get(orgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (info == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster organizationConfigChanged(orgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster info = (AuthServiceConfigInfo)AuthConfigMap.get(orgName);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return info;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}