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.util.ArrayList;
19  import java.util.LinkedHashMap;
20  import java.util.List;
21  
22  import org.apache.commons.lang.StringUtils;
23  import org.kuali.ole.sys.OLEPropertyConstants;
24  import org.kuali.ole.sys.context.SpringContext;
25  import org.kuali.rice.kim.api.identity.Person;
26  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
27  
28  /**
29   * Represents the assignment of one or more security definitions and one or more models to a principal
30   */
31  public class SecurityPrincipal extends PersistableBusinessObjectBase {
32      protected String principalId;
33  
34      protected Person securityPerson;
35  
36      protected List<SecurityPrincipalDefinition> principalDefinitions = new ArrayList<SecurityPrincipalDefinition>();
37      protected List<SecurityModelMember> principalModels = new ArrayList<SecurityModelMember>();
38  
39      /**
40       * Gets the principalId attribute.
41       * 
42       * @return Returns the principalId.
43       */
44      public String getPrincipalId() {
45          return principalId;
46      }
47  
48  
49      /**
50       * Sets the principalId attribute value.
51       * 
52       * @param principalId The principalId to set.
53       */
54      public void setPrincipalId(String principalId) {
55          this.principalId = principalId;
56      }
57  
58  
59      /**
60       * Gets the securityPerson attribute.
61       * 
62       * @return Returns the securityPerson.
63       */
64      public Person getSecurityPerson() {
65          securityPerson = SpringContext.getBean(org.kuali.rice.kim.api.identity.PersonService.class).updatePersonIfNecessary(principalId, securityPerson);
66          return securityPerson;
67      }
68  
69  
70      /**
71       * Sets the securityPerson attribute value.
72       * 
73       * @param securityPerson The securityPerson to set.
74       */
75      public void setSecurityPerson(Person securityPerson) {
76          this.securityPerson = securityPerson;
77      }
78  
79  
80      /**
81       * Gets the principalDefinitions attribute.
82       * 
83       * @return Returns the principalDefinitions.
84       */
85      public List<SecurityPrincipalDefinition> getPrincipalDefinitions() {
86          return principalDefinitions;
87      }
88  
89  
90      /**
91       * Sets the principalDefinitions attribute value.
92       * 
93       * @param principalDefinitions The principalDefinitions to set.
94       */
95      public void setPrincipalDefinitions(List<SecurityPrincipalDefinition> principalDefinitions) {
96          this.principalDefinitions = principalDefinitions;
97      }
98  
99  
100     /**
101      * Gets the principalModels attribute.
102      * 
103      * @return Returns the principalModels.
104      */
105     public List<SecurityModelMember> getPrincipalModels() {
106         return principalModels;
107     }
108 
109 
110     /**
111      * Sets the principalModels attribute value.
112      * 
113      * @param principalModels The principalModels to set.
114      */
115     public void setPrincipalModels(List<SecurityModelMember> principalModels) {
116         this.principalModels = principalModels;
117     }
118 
119     /**
120      * Returns String of definition names assigned to principal
121      */
122     public String getPrincipalDefinitionNames() {
123         String definitionNames = "";
124 
125         for (SecurityPrincipalDefinition definition : principalDefinitions) {
126             if (StringUtils.isNotBlank(definitionNames)) {
127                 definitionNames += ", ";
128             }
129             definitionNames += definition.getSecurityDefinition().getName();
130         }
131 
132         return definitionNames;
133     }
134 
135     /**
136      * Returns String of model names assigned to principal
137      */
138     public String getPrincipalModelNames() {
139         String modelNames = "";
140 
141         for (SecurityModelMember modelMember : principalModels) {
142             if (StringUtils.isNotBlank(modelNames)) {
143                 modelNames += ", ";
144             }
145             modelNames += modelMember.getSecurityModel().getName();
146         }
147 
148         return modelNames;
149     }
150 
151 
152     @Override
153     public String toString() {
154         StringBuilder builder = new StringBuilder();
155         builder.append("SecurityPrincipal [");
156         if (principalId != null) {
157             builder.append("principalId=");
158             builder.append(principalId);
159             builder.append(", ");
160         }
161         if (getPrincipalDefinitionNames() != null) {
162             builder.append("getPrincipalDefinitionNames()=");
163             builder.append(getPrincipalDefinitionNames());
164             builder.append(", ");
165         }
166         if (getPrincipalModelNames() != null) {
167             builder.append("getPrincipalModelNames()=");
168             builder.append(getPrincipalModelNames());
169     }
170         builder.append("]");
171         return builder.toString();
172     }
173 
174 
175 }