a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2009 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: ApplicationTypeManager.java,v 1.1 2009/08/19 05:40:32 veiming Exp $
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest *
a4544a5a0e622ef69e38641f87ab1b5685e05911Phill Cunnington * Portions Copyrighted 2015 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.entitlement;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.entitlement.interfaces.ISaveIndex;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.entitlement.interfaces.ISearchIndex;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.entitlement.interfaces.ResourceName;
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrestimport org.forgerock.openam.entitlement.PolicyConstants;
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.HashSet;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport java.util.Set;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport javax.security.auth.Subject;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Application Type manager.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic final class ApplicationTypeManager {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String URL_APPLICATION_TYPE_NAME =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "iPlanetAMWebAgentService";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String DELEGATION_APPLICATION_TYPE_NAME =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "sunAMDelegationService";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static final String WEB_SERVICE_APPLICATION_TYPE_NAME =
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "webservices";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns application type names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param adminSubject Admin Subject who has the rights to access
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * configuration datastore.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return application type names.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static Set<String> getApplicationTypeNames(Subject adminSubject) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set<String> names = new HashSet<String>();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntitlementConfiguration ec = EntitlementConfiguration.getInstance(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adminSubject, "/");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set<ApplicationType> applications = ec.getApplicationTypes();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (ApplicationType a : applications) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster names.add(a.getName());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return names;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns application type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param adminSubject Admin Subject who has the rights to access
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * configuration datastore.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name Name of application type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return application type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static ApplicationType getAppplicationType(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Subject adminSubject,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntitlementConfiguration ec = EntitlementConfiguration.getInstance(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adminSubject, "/");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set<ApplicationType> applications = ec.getApplicationTypes();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (ApplicationType a : applications) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (a.getName().equals(name)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return a;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes application type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param adminSubject Admin Subject who has the rights to access
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * configuration datastore.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name Name of application type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @throws EntitlementException if application type cannot be removed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void removeApplicationType(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Subject adminSubject,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws EntitlementException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntitlementConfiguration ec = EntitlementConfiguration.getInstance(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adminSubject, "/");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ec.removeApplicationType(name);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Stores application type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param adminSubject Admin Subject who has the rights to access
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * configuration datastore.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param appType Application type.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void saveApplicationType(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Subject adminSubject,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ApplicationType appType
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ) throws EntitlementException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster EntitlementConfiguration ec = EntitlementConfiguration.getInstance(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster adminSubject, "/");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster ec.storeApplicationType(appType);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns search index class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param className Search index implementation class name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return search index class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static Class getSearchIndex(String className) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (className == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Class clazz = Class.forName(className);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object o = clazz.newInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (o instanceof ISearchIndex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return clazz;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (InstantiationException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getSearchIndex", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (IllegalAccessException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getSearchIndex", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (ClassNotFoundException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getSearchIndex", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns save index class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param className Save index implementation class name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return saveindex class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static Class getSaveIndex(String className) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (className == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Class clazz = Class.forName(className);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object o = clazz.newInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (o instanceof ISaveIndex) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return clazz;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (InstantiationException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getSaveIndex", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (IllegalAccessException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getSaveIndex", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (ClassNotFoundException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getSaveIndex", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns resource comparator implementation class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param className Resource comparator implementation class name.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return resource comparator implementation class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static Class getResourceComparator(String className) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (className == null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Class clazz = Class.forName(className);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object o = clazz.newInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (o instanceof ResourceName) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return clazz;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (InstantiationException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getResourceComparator", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (IllegalAccessException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getResourceComparator", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (ClassNotFoundException ex) {
402cd5da45d9182b81c16a13c3568faf78701827Andrew Forrest PolicyConstants.DEBUG.error(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "ApplicationTypeManager.getResourceComparator", ex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}