001/**
002 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003 *
004 * Copyright (c) 2006 Sun Microsystems Inc. All Rights Reserved
005 *
006 * The contents of this file are subject to the terms
007 * of the Common Development and Distribution License
008 * (the License). You may not use this file except in
009 * compliance with the License.
010 *
011 * You can obtain a copy of the License at
012 * https://opensso.dev.java.net/public/CDDLv1.0.html or
013 * opensso/legal/CDDLv1.0.txt
014 * See the License for the specific language governing
015 * permission and limitations under the License.
016 *
017 * When distributing Covered Code, include this CDDL
018 * Header Notice in each file and include the License file
019 * at opensso/legal/CDDLv1.0.txt.
020 * If applicable, add the following below the CDDL Header,
021 * with the fields enclosed by brackets [] replaced by
022 * your own identifying information:
023 * "Portions Copyrighted [year] [name of copyright owner]"
024 *
025 * $Id: ProxyPolicyEvaluatorFactory.java,v 1.2 2008/06/25 05:43:44 qcheng Exp $
026 *
027 * Portions Copyrighted 2014 ForgeRock AS.
028 */
029
030
031package com.sun.identity.policy;
032
033import com.iplanet.sso.SSOException;
034import com.iplanet.sso.SSOToken;
035import com.iplanet.am.util.Cache;
036
037/**
038 * Factory class used to get ProxyPolicyEvaluator instances. 
039 * This is a singleton.
040 *
041 * @supported.all.api
042 * @deprecated since 12.0.0
043 */
044@Deprecated
045public class ProxyPolicyEvaluatorFactory {
046
047    private static final int CACHE_SIZE = 100;
048
049    private static ProxyPolicyEvaluatorFactory proxyPolicyEvaluatorFactory;
050
051    private Cache evaluatorCache;
052
053    /**
054     * Private constructor, disables instances being created from outside
055     * of this class 
056     */
057    private ProxyPolicyEvaluatorFactory() {
058        evaluatorCache = new Cache(CACHE_SIZE);
059    }
060
061    /**
062     * Gets an instance of ProxyPolicyEvaluatorFactory. 
063     *
064     * @return proxy policy evaluator factory
065     * @throws PolicyException any policy exception coming from policy frame 
066     *                         work
067     */
068    synchronized public static ProxyPolicyEvaluatorFactory getInstance() 
069        throws PolicyException
070    {
071        if (proxyPolicyEvaluatorFactory == null) {
072            proxyPolicyEvaluatorFactory = new ProxyPolicyEvaluatorFactory();
073        }
074        return proxyPolicyEvaluatorFactory;
075    }
076
077    /**
078     * Gets an instance of <code>ProxyPolicyEvaluator</code>.
079     * Only privileged users can get <code>ProxyPolicyEvaluator</code>. 
080     * Only top level admin, realm admin or policy admin can get
081     * <code>ProxyPolicyEvaluator</code>.
082     *
083     * @param token sso token used to get the proxy policy evaluator
084     * @param serviceType service type for which get the proxy policy 
085     *                    evaluator 
086     * @return proxy policy evaluator 
087     * @throws SSOException if the token is invalid
088     * @throws NoPermissionException if the token does not have privileges 
089     *                               to get proxy policy evaluator
090     * @throws NameNotFoundException if the serviceType is not found in
091     *         registered service types
092     *         
093     * @throws PolicyException any policy exception coming from policy frame 
094     *                         work
095     */
096    synchronized public ProxyPolicyEvaluator getProxyPolicyEvaluator(
097        SSOToken token, String serviceType) 
098        throws NoPermissionException, NameNotFoundException, 
099        PolicyException, SSOException 
100    {
101        String key = token.getTokenID().toString() + ":" + serviceType;
102        ProxyPolicyEvaluator ppe 
103                = (ProxyPolicyEvaluator)evaluatorCache.get(key);
104        if (ppe == null) {
105            if (PolicyManager.debug.messageEnabled()) {
106                PolicyManager.debug.message(
107                        " Admin: " + token.getPrincipal().getName()
108                        + " created proxy policy evaluator for "
109                        + " for serviceType: " + serviceType);
110            }
111            ppe = new ProxyPolicyEvaluator(token, serviceType);
112            evaluatorCache.put(key, ppe);
113        }
114        if (PolicyManager.debug.messageEnabled()) {
115            PolicyManager.debug.message(
116                    " Admin: " + token.getPrincipal().getName()
117                    + " gotproxy policy evaluator for "
118                    + " for serviceType: " + serviceType);
119        }
120        return ppe;
121    }
122}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.