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