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




























































Copyright © 2010-2017, ForgeRock All Rights Reserved.