View Javadoc
1   /**
2    * Copyright 2018 Internet2
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  
17  package edu.internet2.middleware.grouper.app.deprovisioning;
18  
19  import java.util.LinkedHashSet;
20  import java.util.Set;
21  
22  import org.apache.commons.lang3.StringUtils;
23  
24  import edu.internet2.middleware.grouper.GrouperSourceAdapter;
25  import edu.internet2.middleware.grouper.cfg.GrouperConfig;
26  import edu.internet2.middleware.grouper.subj.InternalSourceAdapter;
27  import edu.internet2.middleware.grouper.util.GrouperUtil;
28  import edu.internet2.middleware.grouperClient.util.ExpirableCache;
29  import edu.internet2.middleware.subject.Source;
30  import edu.internet2.middleware.subject.provider.SourceManager;
31  
32  /**
33   * 
34   */
35  public class GrouperDeprovisioningSettings {
36  
37    /**
38     * if deprovisioning is enabled
39     * @return if deprovisioning enabled
40     */
41    public static boolean deprovisioningEnabled() {
42      // if turned off or if no affiliations then this is not enabled
43      boolean deprovisioningEnabled = GrouperConfig.retrieveConfig().propertyValueBoolean("deprovisioning.enable", true) 
44          && GrouperUtil.length(GrouperDeprovisioningAffiliation.retrieveDeprovisioningAffiliations()) > 0;
45          
46      return deprovisioningEnabled;
47          
48    }
49  
50    /**
51     * 
52     * @return the stem name with no last colon
53     */
54    public static String deprovisioningStemName() {
55      return GrouperUtil.stripSuffix(GrouperConfig.retrieveConfig().propertyValueString("deprovisioning.systemFolder", 
56          GrouperConfig.retrieveConfig().propertyValueString("grouper.rootStemForBuiltinObjects") + ":deprovisioning"), ":");
57    }
58  
59    /**
60     * users in this group who are admins of a affiliation but who are not Grouper SysAdmins
61     * @return the group name
62     */
63    public static String retrieveDeprovisioningAdminGroupName() {
64      
65      // # users in this group who are admins of a affiliation but who are not Grouper SysAdmins, will be 
66      // # able to deprovision from all grouper groups/objects, not just groups they have access to UPDATE/ADMIN
67      // deprovisioning.admin.group = $$deprovisioning.systemFolder$$:deprovisioningAdmins
68      return GrouperConfig.retrieveConfig().propertyValueString("deprovisioning.admin.group");
69    
70    }
71  
72    /**
73     * get the sources to deprovision, dont include the group source or the internal source
74     * @return the sources to deprovision
75     */
76    public static Set<Source> retrieveSourcesAllowedToDeprovision() {
77      
78      Set<Source> result = retrieveSourcesAllowedToDeprovisionCache.get(Boolean.TRUE);
79      
80      if (result == null) {
81      
82        synchronized(retrieveSourcesAllowedToDeprovisionCache) {
83    
84          result = retrieveSourcesAllowedToDeprovisionCache.get(Boolean.TRUE);
85          
86          if (result == null) {
87            result = new LinkedHashSet<Source>();
88            
89            for (Source source : SourceManager.getInstance().getSources()) {
90              if (StringUtils.equals(source.getId(), GrouperSourceAdapter.groupSourceId())) {
91                continue;
92              }
93              if (StringUtils.equals(source.getId(), InternalSourceAdapter.ID)) {
94                continue;
95              }
96              result.add(source);
97            }
98            
99            retrieveSourcesAllowedToDeprovisionCache.put(Boolean.TRUE, result);
100         }
101         
102       }
103     }
104     
105     return result;
106   }
107 
108   /**
109    * cache the sources allowed for a tad
110    */
111   private static ExpirableCache<Boolean, Set<Source>> retrieveSourcesAllowedToDeprovisionCache = new ExpirableCache<Boolean, Set<Source>>();
112 
113 }