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: ReferralTypeManager.java,v 1.3 2008/06/25 05:43:44 qcheng Exp $
026 *
027 * Portions Copyrighted 2014 ForgeRock AS.
028 */
029
030
031
032
033package com.sun.identity.policy;
034
035import java.util.*;
036
037import com.iplanet.sso.SSOToken;
038import com.iplanet.sso.SSOException;
039import com.sun.identity.sm.*;
040import com.sun.identity.policy.interfaces.Referral;
041
042import com.sun.identity.shared.locale.AMResourceBundleCache;
043import com.sun.identity.shared.debug.Debug;
044import com.sun.identity.shared.locale.Locale;
045
046
047/**
048 * The class <code>ReferralTypeManager</code> provides
049 * methods to get a list of configured <code>Referral
050 * </code> objects
051 *
052 * @supported.all.api
053 * @deprecated since 12.0.0
054 */
055@Deprecated
056public class ReferralTypeManager {
057
058    private static String REFERRAL = "Referral";
059
060    private SSOToken token;
061    private PolicyManager pm;
062
063    private ResourceBundle rb;
064    private static AMResourceBundleCache amCache = 
065            AMResourceBundleCache.getInstance();
066
067    static Debug debug = PolicyManager.debug;
068
069    /**
070     * Creates a <code>ReferralTypeManager</code> object
071     */
072    protected ReferralTypeManager() throws SSOException {
073        token = ServiceTypeManager.getSSOToken();
074        String lstr = token.getProperty("Locale");
075        java.util.Locale loc = com.sun.identity.shared.locale.Locale.getLocale(
076            lstr);
077        rb = amCache.getResBundle(ResBundleUtils.rbName, loc);
078    }
079
080    /**
081     * Creates a <code>ReferralTypeManager</code> object
082     * @param pm <code>PolicyManager</code> to initialize 
083     * the <code>ReferralTypeManager</code> with
084     */
085    protected ReferralTypeManager(PolicyManager pm) {
086        this.pm = pm;
087        token = pm.token;
088        java.util.Locale loc ;
089        try {
090            String lstr = token.getProperty("Locale");
091            loc = com.sun.identity.shared.locale.Locale.getLocale(lstr);
092        } catch (SSOException ex) {
093            debug.error(
094                "ConditionTypeManager:Unable to retreive locale from SSOToken",
095                ex);
096            loc = Locale.getDefaultLocale();
097        }
098
099         if (debug.messageEnabled()) {
100            debug.message("SubjectManager locale="+loc+"\tI18nFileName = "+
101                     ResBundleUtils.rbName);
102        }
103        rb = amCache.getResBundle(ResBundleUtils.rbName, loc);
104    }
105
106    /**
107     * Returns a set of all valid referral type names defined by the policy
108     * service.
109     * Examples are <code>PeerOrgReferral</code>, <code>SubOrgReferral</code>
110     *
111     * @return a set of all valid referral type names defined by the policy
112     *         service.
113     * @throws SSOException if the <code>SSOToken</code> used to create 
114     *                      the <code>PolicyManager</code> has become invalid
115     * @throws PolicyException for any other abnormal condition
116     */
117    public Set getReferralTypeNames() throws SSOException,
118            PolicyException {
119        return (PolicyManager.getPluginSchemaNames(REFERRAL));
120    }
121
122    /**
123     * Returns a set of valid referral type names configured for the
124     * organization.
125     * Examples are <code>PeerOrgReferral</code>, <code>SubOrgReferral</code>
126     *
127     * @return a set of valid referral type names configured for the
128     *         organization.
129     * @throws SSOException if the <code>SSOToken</code> used to create 
130     *                      the <code>PolicyManager</code> has become invalid
131     * @throws PolicyException for any other abnormal condition
132     */
133    public Set getSelectedReferralTypeNames() throws SSOException,
134            PolicyException {
135        Map policyConfig = pm.getPolicyConfig();
136        Set selectedReferrals = null;
137        if (policyConfig != null) {
138            selectedReferrals = 
139                    (Set)policyConfig.get(PolicyConfig.SELECTED_REFERRALS); 
140        }
141        if (selectedReferrals == null) {
142            selectedReferrals = Collections.EMPTY_SET;
143        }
144        return selectedReferrals;
145    }
146
147    /**
148     * Returns the type of the <code>Referral</code> implementation.
149     * For example, <code>PeerOrgReferral</code>, <code>SubOrgReferral</code>
150     *
151     * @param referral referral object for which this method will
152     * return its associated type
153     *
154     * @return type of the referral, e.g., <code>PeerOrgReferral</code>,
155     * <code>SubOrgReferral</code> Returns <code>null</code> if not present.
156     */
157    public String getReferralTypeName(Referral referral) {
158        return (referralTypeName(referral));
159    }
160
161    /**
162     * Returns the I18N properties file name that should be
163     * used to localize display names for the given
164     * referral type.
165     *
166     * @param referralType referral type name
167     *
168     * @return i18n properties file name
169     */
170    protected String getI18NPropertiesFileName(String referralType) {
171        // %%% Need to get the file name from plugin schema
172        return (null);
173    }
174
175    /**
176     * Returns the I18N key to be used to localize the
177     * display name for the referral type name.
178     *
179     * @param referralType referral type name
180     *
181     * @return i18n key to obtain the display name
182     */
183    public String getI18NKey(String referralType) {
184        PluginSchema ps = PolicyManager.getPluginSchema(REFERRAL, referralType);
185        if (ps != null) {
186            return (ps.getI18NKey());
187        }
188        return (null);
189    }
190
191
192    /**
193     * Gets the display name for the referral type
194     * @param referralType referral type
195     * @return display name for the referral type
196     */
197    public String getDisplayName(String referralType) {
198        String displayName = null;
199        String i18nKey = getI18NKey(referralType);
200        if (i18nKey == null || i18nKey.length()==0 ) {
201            displayName = referralType;
202        } else {
203            displayName = Locale.getString(rb,i18nKey,debug);
204        }
205        return displayName;
206    }
207
208    /**
209     * Returns an instance of the <code>Referral</code>
210     * given the referral type name.
211     *
212     * @param referralType type of referral.
213     * @return an instance of the <code>Referral</code> given the referral type
214     *         name.
215     * @throws NameNotFoundException if the <code>Referral</code> for the
216     *            <code>referralType</code> name is not found
217     * @throws PolicyException for any other abnormal condition
218     */
219    public Referral getReferral(String referralType)
220        throws NameNotFoundException, PolicyException {
221        PluginSchema ps = PolicyManager.getPluginSchema(REFERRAL, referralType);
222        if (ps == null) {
223            throw (new NameNotFoundException(ResBundleUtils.rbName,
224                "invalid_referral", null,
225                referralType, PolicyException.USER_COLLECTION));
226        }
227
228        // Construct the object
229        Referral answer = null;
230        try {
231            String className = ps.getClassName();
232            answer = (Referral) Class.forName(className).newInstance();
233        } catch (Exception e) {
234            throw (new PolicyException(e));
235        }
236
237        // Construct the Referral and return
238        Map policyConfig = pm.getPolicyConfig();
239        answer.initialize(policyConfig);
240        return (answer);
241    }
242
243
244    /**
245     * Returns the type name for the <code>Referral</code>
246     * @param referral <code>Referral</code> for which to find the type
247     * @return the type name for the <code>Referral</code>
248     */
249    static String referralTypeName(Referral referral) {
250        if (referral == null) {
251            return (null);
252        }
253        String answer = null;
254        String className = referral.getClass().getName();
255        Iterator items =
256            PolicyManager.getPluginSchemaNames(REFERRAL).iterator();
257        while (items.hasNext()) {
258            String pluginName = (String) items.next();
259            PluginSchema ps = PolicyManager.getPluginSchema(
260                REFERRAL, pluginName);
261            if (className.equals(ps.getClassName())) {
262                answer = pluginName;
263                break;
264            }
265        }
266        return (answer);
267    }
268
269    /**
270     * Gets the view bean URL given the Referral
271     *
272     * @param referral referral for which to get the view bean URL
273     *
274     * @return view bean URL defined for the referral plugin in the policy
275     *         service <code>PluginSchema</code>
276     */
277    public String getViewBeanURL(Referral referral) {
278        return PolicyManager.getViewBeanURL(
279            REFERRAL, referral.getClass().getName());
280    }
281
282}




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.