View Javadoc

1   /**
2    * Copyright 2005-2015 The Kuali Foundation
3    *
4    * Licensed under the Educational Community 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.opensource.org/licenses/ecl2.php
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  package org.kuali.rice.krad.uif.component;
17  
18  import org.kuali.rice.krad.datadictionary.parse.BeanTag;
19  import org.kuali.rice.krad.datadictionary.parse.BeanTagAttribute;
20  import org.kuali.rice.krad.datadictionary.uif.UifDictionaryBeanBase;
21  
22  import java.io.Serializable;
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  /**
27   * Component security is used to flag permissions that exist in KIM for various component state (like edit and view)
28   *
29   * <p>
30   * In addition, properties such as additional role and permission details can be configured to use when
31   * checking the KIM permissions
32   * </p>
33   *
34   * <p>
35   * Security subclasses exist adding on flags apporiate for that component
36   * </p>
37   *
38   * @author Kuali Rice Team (rice.collab@kuali.org)
39   */
40  @BeanTag(name = "componentSecurity-bean")
41  public class ComponentSecurity extends UifDictionaryBeanBase implements Serializable {
42      private static final long serialVersionUID = 726347449984853891L;
43  
44      private boolean editAuthz;
45      private boolean viewAuthz;
46  
47      private String namespaceAttribute;
48      private String componentAttribute;
49      private String idAttribute;
50  
51      private Map<String, String> additionalPermissionDetails;
52      private Map<String, String> additionalRoleQualifiers;
53  
54      public ComponentSecurity() {
55          editAuthz = false;
56          viewAuthz = false;
57  
58          additionalPermissionDetails = new HashMap<String, String>();
59          additionalRoleQualifiers = new HashMap<String, String>();
60      }
61  
62      /**
63       * Indicates whether the component has edit authorization and KIM should be consulted
64       *
65       * @return true if the component has edit authorization, false if not
66       */
67      @BeanTagAttribute(name="editAuthz")
68      public boolean isEditAuthz() {
69          return editAuthz;
70      }
71  
72      /**
73       * Setter for the edit authorization flag
74       *
75       * @param editAuthz
76       */
77      public void setEditAuthz(boolean editAuthz) {
78          this.editAuthz = editAuthz;
79      }
80  
81      /**
82       * Indicates whether the component has view authorization and KIM should be consulted
83       *
84       * @return true if the component has view authorization, false if not
85       */
86      @BeanTagAttribute(name="viewAuthz")
87      public boolean isViewAuthz() {
88          return viewAuthz;
89      }
90  
91      /**
92       * Setter for the view authorization flag
93       *
94       * @param viewAuthz
95       */
96      public void setViewAuthz(boolean viewAuthz) {
97          this.viewAuthz = viewAuthz;
98      }
99  
100     /**
101      * Namespace code that should be sent as permission detail when doing a permission check on this field
102      *
103      * <p>
104      * When the namespace code is a detail for a permission check, this property can be configured to override the
105      * namespace derived by the system
106      * </p>
107      *
108      * @return namespace code
109      */
110     @BeanTagAttribute(name="namespaceAttribute")
111     public String getNamespaceAttribute() {
112         return namespaceAttribute;
113     }
114 
115     /**
116      * Setter for the namespace code to use for details
117      *
118      * @param namespaceAttribute
119      */
120     public void setNamespaceAttribute(String namespaceAttribute) {
121         this.namespaceAttribute = namespaceAttribute;
122     }
123 
124     /**
125      * Component code that should be sent as permission detail when doing a permission check on this field
126      *
127      * <p>
128      * When the component code is a detail for a permission check, this property can be configured to override the
129      * component code derived by the system
130      * </p>
131      *
132      * @return component code
133      */
134     @BeanTagAttribute(name="componentAttribute")
135     public String getComponentAttribute() {
136         return componentAttribute;
137     }
138 
139     /**
140      * Setter for the component code to use for details
141      *
142      * @param componentAttribute
143      */
144     public void setComponentAttribute(String componentAttribute) {
145         this.componentAttribute = componentAttribute;
146     }
147 
148     /**
149      * Id that should be sent as permission detail when doing a permission check on this field
150      *
151      * <p>
152      * By default they system will send the component id as a permission detail, this property can be configured to
153      * send a different id for the permission check
154      * </p>
155      *
156      * @return id
157      */
158     @BeanTagAttribute(name="idAttribute")
159     public String getIdAttribute() {
160         return idAttribute;
161     }
162 
163     /**
164      * Setter for the id to use for details
165      *
166      * @param idAttribute
167      */
168     public void setIdAttribute(String idAttribute) {
169         this.idAttribute = idAttribute;
170     }
171 
172     /**
173      * Map of key value pairs that should be added as permission details when doing KIM permission checks for this
174      * component
175      *
176      * <p>
177      * Any details given here that will override details with the same key that were derived by the system
178      * </p>
179      *
180      * @return Map<String, String>
181      */
182     @BeanTagAttribute(name="additionalPermissionDetails",type= BeanTagAttribute.AttributeType.MAPVALUE)
183     public Map<String, String> getAdditionalPermissionDetails() {
184         return additionalPermissionDetails;
185     }
186 
187     /**
188      * Setter for the map of additional permission details
189      *
190      * @param additionalPermissionDetails
191      */
192     public void setAdditionalPermissionDetails(Map<String, String> additionalPermissionDetails) {
193         this.additionalPermissionDetails = additionalPermissionDetails;
194     }
195 
196     /**
197      * Map of key value pairs that should be added as role qualifiers when doing KIM permission checks for this
198      * component
199      *
200      * <p>
201      * Any qualifiers given here that will override qualifiers with the same key that were derived by the system
202      * </p>
203      *
204      * @return Map<String, String>
205      */
206     @BeanTagAttribute(name="additionalRoleQualifiers",type= BeanTagAttribute.AttributeType.MAPVALUE)
207     public Map<String, String> getAdditionalRoleQualifiers() {
208         return additionalRoleQualifiers;
209     }
210 
211     /**
212      * Setter for the map of additional role qualifiers
213      *
214      * @param additionalRoleQualifiers
215      */
216     public void setAdditionalRoleQualifiers(Map<String, String> additionalRoleQualifiers) {
217         this.additionalRoleQualifiers = additionalRoleQualifiers;
218     }
219 
220     @Override
221     protected void finalize() throws Throwable {
222         try {
223             idAttribute = null;
224             componentAttribute = null;
225             namespaceAttribute = null;
226             additionalRoleQualifiers = null;
227             additionalPermissionDetails = null;
228         } finally {
229             // don't call super.finalize() in attempt to avoid loop between maps.
230         }
231     }
232 
233     /**
234      * Returns a copy of the component security.
235      *
236      * @return ComponentSecurity copy of the component
237      */
238     public <T> T copy() {
239         T copiedClass = null;
240         try {
241             copiedClass = (T)this.getClass().newInstance();
242         }
243         catch(Exception exception) {
244             throw new RuntimeException();
245         }
246 
247         copyProperties(copiedClass);
248 
249         return copiedClass;
250     }
251 
252     protected <T> void copyProperties(T componentSecurity) {
253         super.copyProperties(componentSecurity);
254         ComponentSecurity componentSecurityCopy = (ComponentSecurity) componentSecurity;
255 
256         if (this.additionalPermissionDetails != null) {
257             componentSecurityCopy.setAdditionalPermissionDetails(new HashMap<String, String>(this.additionalPermissionDetails));
258         }
259 
260         if (this.additionalRoleQualifiers != null) {
261             componentSecurityCopy.setAdditionalRoleQualifiers(new HashMap<String, String>(this.additionalRoleQualifiers));
262         }
263 
264         componentSecurityCopy.setComponentAttribute(this.componentAttribute);
265         componentSecurityCopy.setEditAuthz(this.editAuthz);
266         componentSecurityCopy.setIdAttribute(this.idAttribute);
267         componentSecurityCopy.setNamespaceAttribute(this.namespaceAttribute);
268         componentSecurityCopy.setViewAuthz(this.viewAuthz);
269     }
270 }