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: ConfiguredAuthServices.java,v 1.6 2008/06/25 05:42:04 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts/*
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts * Portions Copyrighted 2014 ForgeRock AS
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.authentication.service;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.security.AccessController;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Collections;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashMap;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Map;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.iplanet.sso.SSOToken;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.authentication.util.ISAuthConstants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.Constants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.security.AdminTokenAction;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ChoiceValues;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.SMSEntry;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceConfig;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceConfigManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The class determines the configured Identity Types for Identity Repository.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This list is computed per realm.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class ConfiguredAuthServices extends ChoiceValues {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Creates <code>ConfiguredAuthServices</code> object.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Default constructor that will be used by the SMS
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * to create an instance of this class
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public ConfiguredAuthServices() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // do nothing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the choice values and their corresponding localization keys.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the choice values and their corresponding localization keys.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map getChoiceValues() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return getChoiceValues(Collections.EMPTY_MAP);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the choice values from configured environment params.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param envParams map for configured parameters
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the choice values from configured environment params.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public Map getChoiceValues(Map envParams) {
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts String org = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster SSOToken adminToken = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (envParams != null) {
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts org = (String)envParams.get(Constants.ORGANIZATION_NAME);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adminToken = (SSOToken)envParams.get(Constants.SSO_TOKEN);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts if (org == null || org.length() == 0) {
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts org = SMSEntry.getRootSuffix();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (adminToken == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adminToken = (SSOToken)AccessController.doPrivileged(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AdminTokenAction.getInstance());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set namedConfigs = Collections.EMPTY_SET;
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts ServiceConfig namedConfig = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map answer = new HashMap();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Get the named config node
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts ServiceConfigManager scm = new ServiceConfigManager(SERVICE_NAME, adminToken);
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts ServiceConfig oConfig = scm.getOrganizationConfig(org, null);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (oConfig != null) {
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts namedConfig = oConfig.getSubConfig(NAMED_CONFIGURATION);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (namedConfig != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // get all sub config names
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster namedConfigs = namedConfig.getSubConfigNames("*");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (Exception e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // do nothing as namedConfigs will be empty.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (namedConfigs != null && !namedConfigs.isEmpty()) {
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts Set<String> configs = filterConfigs(namedConfigs, namedConfig, org, adminToken);
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts for (String config : configs) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster answer.put(config, config);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster answer.put(ISAuthConstants.BLANK, ISAuthConstants.BLANK);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //return the choice values map
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (answer);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts /**
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts * Extensions will want to restrict the list of auth services. The default implementation just returns all.
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts * @param namedConfigs The auth services that have been found.
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts * @param parentConfig The ServiceConfig parent of all auth services.
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts * @param realm The current realm.
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts * @param adminToken The current SSO token.
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts * @return The filtered list of auth services.
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts */
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts protected Set<String> filterConfigs(Set<String> namedConfigs, ServiceConfig parentConfig, String realm,
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts SSOToken adminToken) {
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts return namedConfigs;
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts }
1cb968daf78963d139ff89a7b192e85314e82509James Phillpotts
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String SERVICE_NAME = "iPlanetAMAuthConfiguration";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static final String NAMED_CONFIGURATION = "Configurations";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}