View Javadoc
1   /*
2    * Copyright 2009 The Kuali Foundation.
3    *
4    * Licensed under the Educational Community License, Version 1.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/ecl1.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.ole.sec.businessobject;
17  
18  import java.sql.Timestamp;
19  
20  import org.apache.commons.lang.StringUtils;
21  import org.kuali.ole.sys.context.SpringContext;
22  import org.kuali.rice.core.api.membership.MemberType;
23  import org.kuali.rice.core.api.util.type.KualiInteger;
24  import org.kuali.rice.kim.api.group.Group;
25  import org.kuali.rice.kim.api.group.GroupService;
26  import org.kuali.rice.kim.api.identity.Person;
27  import org.kuali.rice.kim.api.identity.PersonService;
28  import org.kuali.rice.kim.api.role.Role;
29  import org.kuali.rice.kim.api.services.KimApiServiceLocator;
30  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
31  
32  
33  /**
34   * Associates a member (principal, role, or group) to a model. These become the members of the model role created in KIM
35   */
36  public class SecurityModelMember extends PersistableBusinessObjectBase {
37      protected KualiInteger modelId;
38      protected String memberId;
39      protected String memberTypeCode;
40      protected Timestamp activeFromDate;
41      protected Timestamp activeToDate;
42  
43      protected SecurityModel securityModel;
44  
45      // non db
46      protected String memberName = "";
47  
48      protected ModelMember modelMember;
49  
50      /**
51       * Gets the modelId attribute.
52       *
53       * @return Returns the modelId.
54       */
55      public KualiInteger getModelId() {
56          return modelId;
57      }
58  
59  
60      /**
61       * Sets the modelId attribute value.
62       *
63       * @param modelId The modelId to set.
64       */
65      public void setModelId(KualiInteger modelId) {
66          this.modelId = modelId;
67      }
68  
69  
70      /**
71       * Gets the memberId attribute.
72       *
73       * @return Returns the memberId.
74       */
75      public String getMemberId() {
76          return memberId;
77      }
78  
79  
80      /**
81       * Sets the memberId attribute value.
82       *
83       * @param memberId The memberId to set.
84       */
85      public void setMemberId(String memberId) {
86          this.memberId = memberId;
87          memberName = "";
88      }
89  
90  
91      /**
92       * Gets the memberTypeCode attribute.
93       *
94       * @return Returns the memberTypeCode.
95       */
96      public String getMemberTypeCode() {
97          return memberTypeCode;
98      }
99  
100 
101     /**
102      * Sets the memberTypeCode attribute value.
103      *
104      * @param memberTypeCode The memberTypeCode to set.
105      */
106     public void setMemberTypeCode(String memberTypeCode) {
107         this.memberTypeCode = memberTypeCode;
108         memberName = "";
109     }
110 
111 
112     /**
113      * Gets the activeFromDate attribute.
114      *
115      * @return Returns the activeFromDate.
116      */
117     public Timestamp getActiveFromDate() {
118         return activeFromDate;
119     }
120 
121 
122     /**
123      * Sets the activeFromDate attribute value.
124      *
125      * @param activeFromDate The activeFromDate to set.
126      */
127     public void setActiveFromDate(Timestamp activeFromDate) {
128         this.activeFromDate = activeFromDate;
129     }
130 
131 
132     /**
133      * Gets the activeToDate attribute.
134      *
135      * @return Returns the activeToDate.
136      */
137     public Timestamp getActiveToDate() {
138         return activeToDate;
139     }
140 
141 
142     /**
143      * Sets the activeToDate attribute value.
144      *
145      * @param activeToDate The activeToDate to set.
146      */
147     public void setActiveToDate(Timestamp activeToDate) {
148         this.activeToDate = activeToDate;
149     }
150 
151 
152     /**
153      * Gets the memberName attribute.
154      *
155      * @return Returns the memberName.
156      */
157     public String getMemberName() {
158         if ( StringUtils.isBlank(memberName) ) {
159         if (StringUtils.isNotBlank(memberTypeCode) && StringUtils.isNotBlank(memberId)) {
160                 if (MemberType.PRINCIPAL.getCode().equals(memberTypeCode)) {
161                 Person person = SpringContext.getBean(PersonService.class).getPerson(memberId);
162                 if (person != null) {
163                         memberName = person.getName();
164                 }
165                 } else if (MemberType.ROLE.getCode().equals(memberTypeCode)) {
166                     Role roleInfo = KimApiServiceLocator.getRoleService().getRole(memberId);
167                 if (roleInfo != null) {
168                         memberName = roleInfo.getName();
169             }
170                 } else if (MemberType.GROUP.getCode().equals(memberTypeCode)) {
171                     Group groupInfo = KimApiServiceLocator.getGroupService().getGroup(memberId);
172                 if (groupInfo != null) {
173                         memberName = groupInfo.getName();
174                     }
175                 }
176             }
177         }
178 
179         return memberName;
180     }
181 
182 
183     /**
184      * Sets the memberName attribute value.
185      *
186      * @param memberName The memberName to set.
187      */
188     public void setMemberName(String memberName) {
189         this.memberName = memberName;
190     }
191 
192 
193     /**
194      * Gets the securityModel attribute.
195      *
196      * @return Returns the securityModel.
197      */
198     public SecurityModel getSecurityModel() {
199         return securityModel;
200     }
201 
202 
203     /**
204      * Sets the securityModel attribute value.
205      *
206      * @param securityModel The securityModel to set.
207      */
208     public void setSecurityModel(SecurityModel securityModel) {
209         this.securityModel = securityModel;
210     }
211 
212 
213     /**
214      * Gets the modelMember attribute.
215      *
216      * @return Returns the modelMember.
217      */
218     public ModelMember getModelMember() {
219         return modelMember;
220     }
221 
222 
223     /**
224      * Sets the modelMember attribute value.
225      *
226      * @param modelMember The modelMember to set.
227      */
228     public void setModelMember(ModelMember modelMember) {
229         this.modelMember = modelMember;
230     }
231 
232     /**
233      * Builds a string representation of the model definition assignmentss
234      *
235      * @return String
236      */
237     public String getModelDefinitionSummary() {
238         String summary = "";
239 
240         for (SecurityModelDefinition modelDefinition : securityModel.getModelDefinitions()) {
241             summary += "Definition Name: " + modelDefinition.getSecurityDefinition().getName();
242             summary += ", Constraint Code: " + modelDefinition.getConstraintCode();
243             summary += ", Operator Code: " + modelDefinition.getOperatorCode();
244             summary += ", Value: " + modelDefinition.getAttributeValue();
245             summary += "; ";
246         }
247 
248         return summary;
249     }
250 
251 
252     @Override
253     public String toString() {
254         StringBuilder builder = new StringBuilder();
255         builder.append("SecurityModelMember [");
256         if (modelId != null) {
257             builder.append("modelId=");
258             builder.append(modelId);
259             builder.append(", ");
260         }
261         if (memberId != null) {
262             builder.append("memberId=");
263             builder.append(memberId);
264             builder.append(", ");
265         }
266         if (memberTypeCode != null) {
267             builder.append("memberTypeCode=");
268             builder.append(memberTypeCode);
269             builder.append(", ");
270         }
271         if (activeFromDate != null) {
272             builder.append("activeFromDate=");
273             builder.append(activeFromDate);
274             builder.append(", ");
275         }
276         if (activeToDate != null) {
277             builder.append("activeToDate=");
278             builder.append(activeToDate);
279             builder.append(", ");
280         }
281         if (getMemberName() != null) {
282             builder.append("getMemberName()=");
283             builder.append(getMemberName());
284             builder.append(", ");
285         }
286         if (getModelDefinitionSummary() != null) {
287             builder.append("getModelDefinitionSummary()=");
288             builder.append(getModelDefinitionSummary());
289     }
290         builder.append("]");
291         return builder.toString();
292     }
293 
294 
295 }