View Javadoc
1   /*******************************************************************************
2    * Copyright 2012 Internet2
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the License at
6    * 
7    * http://www.apache.org/licenses/LICENSE-2.0
8    * 
9    * Unless required by applicable law or agreed to in writing, software distributed under
10   * the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
11   * KIND, either express or implied. See the License for the specific language governing
12   * permissions and limitations under the License.
13   ******************************************************************************/
14  /**
15   * 
16   */
17  package edu.internet2.middleware.grouper.ws;
18  
19  import java.util.List;
20  import java.util.Map;
21  import java.util.Properties;
22  import java.util.Set;
23  import java.util.regex.Pattern;
24  
25  import org.apache.commons.lang.StringUtils;
26  
27  import edu.internet2.middleware.grouperClient.config.ConfigPropertiesCascadeBase.ConfigFile;
28  
29  /**
30   * config constants for WS
31   * 
32   * @author mchyzer
33   * 
34   */
35  public final class GrouperWsConfig {
36  
37    /**
38     * use the factory
39     */
40    private GrouperWsConfig() {
41  
42    }
43  
44    /**
45     * retrieve a config from the config file or from cache
46     * @return the config object
47     */
48    public static GrouperWsConfig retrieveConfig() {
49      GrouperWsConfigWsConfig.html#GrouperWsConfig">GrouperWsConfig grouperWsConfig = new GrouperWsConfig();
50      grouperWsConfig.grouperWsConfigInApi = GrouperWsConfigInApi.retrieveConfig();
51      return grouperWsConfig;
52    }
53  
54    /**
55     * delegate
56     */
57    private GrouperWsConfigInApi grouperWsConfigInApi = null;
58    
59    /**
60     * Get a Grouper configuration parameter.
61     * 
62     * <pre class="eg">
63     * String wheel = GrouperConfig.getProperty(&quot;groups.wheel.group&quot;);
64     * </pre>
65     * 
66     * @param property to lookup
67     * @return Value of configuration parameter or an empty string if parameter
68     *         is invalid.
69     * @since 1.1.0
70     * @deprecated use GrouperWsConfig.retrieveConfig().propertyValueString instead
71     */
72    @Deprecated
73    public static String getPropertyString(String property) {
74      return retrieveConfig().propertyValueString(property, "");
75    }
76  
77    /**
78     * get all properties
79     * @return all properties
80     * @deprecated use GrouperWsConfig.retrieveConfig().properties()
81     */
82    @Deprecated
83    public static Properties getProperties() {
84      return retrieveConfig().properties();
85    }
86  
87    /**
88     * Get a Grouper configuration parameter.
89     * 
90     * <pre class="eg">
91     * String wheel = GrouperConfig.getProperty(&quot;groups.wheel.group&quot;);
92     * </pre>
93     * 
94     * @param property to lookup
95     * @param defaultValue is the value if the property isnt found
96     * @return Value of configuration parameter or the default value (will trim the value)
97     * @since 1.1.0
98     * @deprecated use GrouperWsConfig.retrieveConfig().propertyValueString instead
99     */
100   @Deprecated
101   public static String getPropertyString(String property, String defaultValue) {
102     String value = retrieveConfig().propertyValueString(property, defaultValue);
103     if (StringUtils.isBlank(value)) {
104       return defaultValue;
105     }
106     return value;
107   }
108 
109   /**
110    * Get a Grouper configuration parameter an integer
111    * 
112    * @param property to lookup
113    * @param defaultValue of the int if not there
114    * @return Value of configuration parameter or null if parameter isnt
115    *         specified. Exception is thrown if not formatted correcly
116    * @deprecated use GrouperWsConfig.retrieveConfig().propertyValueInt instead
117    */
118   @Deprecated
119   public static int getPropertyInt(String property, int defaultValue) {
120     return retrieveConfig().propertyValueInt(property, defaultValue);
121   }
122 
123   /**
124    * Get a Grouper configuration parameter as boolean (must be true|t|false|f
125    * case-insensitive)
126    * 
127    * @param property to lookup
128    * @param defaultValue if the property is not there
129    * @return Value of configuration parameter or null if parameter isnt
130    *         specified. Exception is thrown if not formatted correcly
131    * @deprecated use GrouperWsConfig.retrieveConfig().propertyValueBoolean instead
132    */
133   @Deprecated
134   public static boolean getPropertyBoolean(String property, boolean defaultValue) {
135     return GrouperWsConfig.retrieveConfig().propertyValueBoolean(property, defaultValue);
136   }
137 
138   /**
139    * name of param for add member web service max, default is 1000000
140    *  # Max number of subjects to be able to pass to addMember service,
141    * default is 1000000 ws.add.member.subjects.max = 20000
142    * 
143    */
144   public static final String WS_ADD_MEMBER_SUBJECTS_MAX = "ws.add.member.subjects.max";
145 
146   /**
147    * name of param for member change subject web service max, default is 1000000
148    *  # Max number of members to pass to memberChangeSubject,
149    * default is 1000000 ws.member.change.subject.max = 20000
150    * 
151    */
152   public static final String WS_MEMBER_CHANGE_SUBJECT_MAX = "ws.member.change.subject.max";
153 
154   /**
155    * name of param for get groups web service max, default is 1000000
156    *  # Max number of subjects to be able to pass to getGroups service,
157    * default is 1000000 ws.get.groups.subjects.max = 20000
158    * 
159    */
160   public static final String WS_GET_GROUPS_SUBJECTS_MAX = "ws.get.groups.subjects.max";
161 
162   /**
163    * name of param for group delete, max groups to be able to delete at once,
164    * default is 1000000
165    *  # Max number of groups to be able to pass to groupDelete service,
166    * default is 1000000 ws.group.delete.max = 20000
167    * 
168    */
169   public static final String WS_GROUP_DELETE_MAX = "ws.group.delete.max";
170 
171   /**
172    * name of param for attributedefname delete, max attributedefnames to be able to delete at once,
173    * default is 1000000
174    *  # Max number of attributedefnames to be able to pass to attributedefnameDelete service,
175    * default is 1000000 ws.attributedefname.delete.max = 20000
176    * 
177    */
178   public static final String WS_ATTRIBUTE_DEF_NAME_DELETE_MAX = "ws.attributeDefName.delete.max";
179   
180   /**
181    * name of param for attributedef delete, max attributedefs to be able to delete at once,
182    * default is 1000000
183    *  # Max number of attributedefs to be able to pass to attributedefDelete service,
184    * default is 1000000 ws.attributedef.delete.max = 20000
185    * 
186    */
187   public static final String WS_ATTRIBUTE_DEF_DELETE_MAX = "ws.attributeDef.delete.max";
188 
189   /**
190    * name of param for group save, max groups to be able to save at once,
191    * default is 1000000
192    *  # Max number of groups to be able to pass to groupSave service,
193    * default is 1000000 ws.group.save.max = 20000
194    * 
195    */
196   public static final String WS_GROUP_SAVE_MAX = "ws.group.save.max";
197 
198   /**
199    * name of param for attributeDefName save, max attributeDefNames to be able to save at once,
200    * default is 1000000
201    *  # Max number of attributeDefNames to be able to pass to attributeDefNameSave service,
202    * default is 1000000 ws.attributeDefName.save.max = 20000
203    * 
204    */
205   public static final String WS_ATTRIBUTE_DEF_NAME_SAVE_MAX = "ws.attributeDefName.save.max";
206   
207   /**
208    * name of param for attributeDef save, max attributeDef to be able to save at once,
209    * default is 1000000
210    *  # Max number of attributeDefs to be able to pass to attributeDefSave service,
211    * default is 1000000 ws.attributeDef.save.max = 20000
212    * 
213    */
214   public static final String WS_ATTRIBUTE_DEF_SAVE_MAX = "ws.attributeDef.save.max";
215 
216   /**
217    * name of param for stem delete, max stems to be able to delete at once,
218    * default is 1000000
219    *  # Max number of stems to be able to pass to stemDelete service,
220    * default is 1000000 ws.stem.delete.max = 20000
221    * 
222    */
223   public static final String WS_STEM_DELETE_MAX = "ws.stem.delete.max";
224 
225   /**
226    * name of param for assignAttributeDefNameInheritance save, max assignAttributeDefNameInheritance to be able to save at once,
227    * default is 1000000
228    *  # Max number of assignAttributeDefNameInheritance to be able to pass to assignAttributeDefNameInheritance service,
229    * default is 1000000 ws.assign.attributeDefName.inheritance.max = 20000
230    * 
231    */
232   public static final String WS_ASSIGN_ATTRIBUTE_DEF_NAME_INHERITANCE_MAX = "ws.assign.attributeDefName.inheritance.max";
233 
234   /**
235    * name of param for stem save, max stems to be able to save at once,
236    * default is 1000000
237    *  # Max number of stems to be able to pass to stemSave service,
238    * default is 1000000 ws.stem.save.max = 20000
239    * 
240    */
241   public static final String WS_STEM_SAVE_MAX = "ws.stem.save.max";
242 
243   /**
244    * name of param for group attribute, max groups to be able to view/edit attributes at once,
245    * default is 1000000
246    *  # Max number of subjects to be able to pass to addMember service,
247    * default is 1000000 ws.group.save.max = 20000
248    * 
249    */
250   public static final String WS_GROUP_ATTRIBUTE_MAX = "ws.group.attribute.max";
251 
252   /**
253    * name of param for delete member web service max, default is 1000000
254    *  # Max number of subjects to be able to pass to deleteMember service,
255    * default is 1000000 ws.delete.member.subjects.max = 20000
256    * 
257    */
258   public static final String WS_DELETE_MEMBER_SUBJECTS_MAX = "ws.delete.member.subjects.max";
259 
260   /**
261    * name of param for has member web service max, default is 1000000
262    *  # Max number of subjects to be able to pass to addMember service,
263    * default is 1000000 ws.has.member.subjects.max = 20000
264    */
265   public static final String WS_HAS_MEMBER_SUBJECTS_MAX = "ws.has.member.subjects.max";
266 
267   /**
268    * name of param for subject result attribute names when extended data is requested
269    *  # subject result attribute names when extended data is requested (comma separated)
270    * default is name, description
271    * note, these will be in addition to ws.subject.result.attribute.names
272    */
273   public static final String WS_SUBJECT_RESULT_DETAIL_ATTRIBUTE_NAMES = "ws.subject.result.detail.attribute.names";
274 
275   /**
276    * subject attribute names to send back when a WsSubject is sent, comma separated
277    * e.g. name, netid
278    * default is none
279    */
280   public static final String WS_SUBJECT_RESULT_ATTRIBUTE_NAMES = "ws.subject.result.attribute.names";
281 
282   /** when packing things in a single param, this is the separator */
283   public static final String WS_SEPARATOR = "::::";
284 
285   /**
286    * name of param
287    * # Web service users who are in the following group can use the actAs field to act as someone else
288    * # You can put multiple groups separated by commas.  e.g. a:b:c, e:f:g
289    * # You can put a single entry as the group the calling user has to be in, and the grouper the actAs has to be in
290    * # separated by 4 colons
291    * # e.g. if the configured values is:       a:b:c, e:f:d :::: r:e:w, x:e:w
292    * # then if the calling user is in a:b:c or x:e:w, then the actAs can be anyone
293    * # if not, then if the calling user is in e:f:d, then the actAs must be in r:e:w.  If multiple rules, then 
294    * # if one passes, then it is a success, if they all fail, then fail.
295    *
296    * field to act as someone else ws.act.as.group = aStem:aGroup
297    */
298   public static final String WS_ACT_AS_GROUP = "ws.act.as.group";
299 
300   /**
301    * name of param: ws.act.as.cache.seconds
302    * cache the decision to allow a user to actAs another, so it doesnt have to be calculated each time
303    * defaults to 30 minutes: 
304    */
305   public static final String WS_ACT_AS_CACHE_MINUTES = "ws.act.as.cache.minutes";
306 
307   /**
308    * name of param: ws.logged.in.subject.default.source
309    * if you have subject namespace overlap (or not), set the default subject 
310    * source to lookup the user if none specified in user name
311    */
312   public static final String WS_LOGGED_IN_SUBJECT_DEFAULT_SOURCE = "ws.logged.in.subject.default.source";
313 
314   /**
315    * name of param for save privileges web service max, default is 1000000
316    *  # Max number of subjects to be able to pass to savePrivileges service,
317    * default is 1000000 ws.view.or.edit.privileges.subjects.max = 20000
318    */
319   public static final String WS_VIEW_OR_EDIT_PRIVILEGES_SUBJECTS_MAX = "ws.view.or.edit.privileges.subjects.max";
320 
321   /**
322    * name of param: ws.rest.default.response.content.type
323    * if the request has no content type (http params), and the response content type is not
324    * specified in the url, then put it here.  must be a valid value of WsLiteResponseContentType
325    * defaults to xhtml if blank
326    */
327   public static final String WS_REST_DEFAULT_RESPONSE_CONTENT_TYPE = "ws.rest.default.response.content.type";
328 
329   /**
330    * to provide custom authentication (instead of the default httpServletRequest.getUserPrincipal()
331    * for non-Rampart authentication.  Class must implement the interface:
332    * edu.internet2.middleware.grouper.ws.security.WsCustomAuthentication
333    * class must be fully qualified.  e.g. edu.school.whatever.MyAuthenticator
334    * blank means use default: edu.internet2.middleware.grouper.ws.security.WsGrouperDefaultAuthentication
335    * ws.security.non-rampart.authentication.class = 
336    */
337   public static final String WS_SECURITY_NON_RAMPART_AUTHENTICATION_CLASS =
338       "ws.security.non-rampart.authentication.class";
339 
340   /**
341    * to provide rampart authentication, Class must implement the interface:
342    * edu.internet2.middleware.grouper.ws.security.GrouperWssecAuthentication
343    * class must be fully qualified.  e.g. edu.school.whatever.MyAuthenticator
344    * blank means rampart will throw 404 status code
345    */
346   public static final String WS_SECURITY_RAMPART_AUTHENTICATION_CLASS =
347       "ws.security.rampart.authentication.class";
348 
349   /**
350    * name of param: ws.client.user.group.name
351    * If there is an entry here for group name, then all web service client 
352    * users must be in this group (before the actAs)
353    * e.g. etc:webServiceClientUsers
354    */
355   public static final String WS_CLIENT_USER_GROUP_NAME = "ws.client.user.group.name";
356 
357   /**
358    * name of param: ws.client.user.group.cache.minutes
359    * cache the decision to allow a user to user web services, so it doesnt have to be calculated each time
360    * defaults to 30 minutes: 
361    */
362   public static final String WS_CLIENT_USER_GROUP_CACHE_MINUTES = "ws.client.user.group.cache.minutes";
363 
364   /**
365    * if the key is there, whether or not the value is blank
366    * @param key
367    * @return true or false
368    */
369   public boolean containsKey(String key) {
370     
371     return this.grouperWsConfigInApi.containsKey(key);
372     
373   }
374 
375   /**
376    * get the underlying properties for the config ui
377    * @return the config files
378    */
379   public List<ConfigFile> internalRetrieveConfigFiles() {
380     return this.grouperWsConfigInApi.internalRetrieveConfigFiles();
381   }
382 
383   /**
384    * get the properties object for this config file
385    * @return the properties
386    */
387   public Properties properties() {
388     return this.grouperWsConfigInApi.properties();
389   }
390 
391   /**
392    * find all keys/values with a certain pattern in a properties file.
393    * return the keys.  if none, will return the empty set, not null set
394    * @param pattern
395    * @return the keys.  if none, will return the empty set, not null set
396    */
397   public Map<String, String> propertiesMap(Pattern pattern) {
398     return this.grouperWsConfigInApi.propertiesMap(pattern);
399   }
400 
401   /**
402    * override map for properties for testing
403    * @return the override map
404    */
405   public Map<String, String> propertiesOverrideMap() {
406     return this.grouperWsConfigInApi.propertiesOverrideMap();
407   }
408 
409   /**
410    * override map for properties in thread local to be used in a web server or the like, based on property class
411    * this is static since the properties class can get reloaded, but these shouldnt
412    * @return the override map
413    */
414   public Map<String, String> propertiesThreadLocalOverrideMap() {
415     return this.grouperWsConfigInApi.propertiesThreadLocalOverrideMap();
416   }
417 
418   /**
419    * 
420    * @return the set of names
421    */
422   @SuppressWarnings("unchecked")
423   public Set<String> propertyNames() {    
424     return this.grouperWsConfigInApi.propertyNames();
425   }
426 
427   /**
428    * get a boolean and validate from grouper.client.properties or null if not there
429    * @param key
430    * @return the boolean or null
431    */
432   public Boolean propertyValueBoolean(String key) {
433     return this.grouperWsConfigInApi.propertyValueBoolean(key);
434   }
435 
436   /**
437    * get a boolean and validate from grouper.client.properties
438    * @param key
439    * @param defaultValue
440    * @return the string
441    */
442   public boolean propertyValueBoolean(String key, boolean defaultValue) {
443     return this.grouperWsConfigInApi.propertyValueBoolean(key, defaultValue);
444   }
445 
446   /**
447    * get a boolean and validate from grouper.client.properties
448    * @param key
449    * @return the string
450    */
451   public boolean propertyValueBooleanRequired(String key) {
452     return this.grouperWsConfigInApi.propertyValueBooleanRequired(key);
453   }
454 
455   /**
456    * get a boolean and validate from grouper.client.properties
457    * @param key
458    * @return the int or null if there
459    */
460   public Integer propertyValueInt(String key ) {
461     return this.grouperWsConfigInApi.propertyValueInt(key);
462   }
463 
464   /**
465    * get a boolean and validate from grouper.client.properties
466    * @param key
467    * @param defaultValue
468    * @return the string
469    */
470   public int propertyValueInt(String key, int defaultValue ) {
471     return this.grouperWsConfigInApi.propertyValueInt(key, defaultValue);
472   }
473 
474   /**
475    * get a boolean and validate from grouper.client.properties
476    * @param key
477    * @return the string
478    */
479   public int propertyValueIntRequired(String key) {
480     return this.grouperWsConfigInApi.propertyValueIntRequired(key);
481   }
482 
483   /**
484    * get the property value as a string or null if not there
485    * @param key
486    * @return the property value
487    */
488   public String propertyValueString(String key) {
489     return this.grouperWsConfigInApi.propertyValueString(key);
490   }
491 
492   /**
493    * get the property value as a string
494    * @param key
495    * @param defaultValue
496    * @return the property value
497    */
498   public String propertyValueString(String key, String defaultValue) {
499     return this.grouperWsConfigInApi.propertyValueString(key, defaultValue);
500   }
501 
502   /**
503    * get the property value as a string
504    * @param key
505    * @return the property value
506    */
507   public String propertyValueStringRequired(String key) {
508     return this.grouperWsConfigInApi.propertyValueStringRequired(key);
509   }
510   
511 }