View Javadoc
1   /*
2    * The Kuali Financial System, a comprehensive financial management system for higher education.
3    * 
4    * Copyright 2005-2014 The Kuali Foundation
5    * 
6    * This program is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU Affero General Public License as
8    * published by the Free Software Foundation, either version 3 of the
9    * License, or (at your option) any later version.
10   * 
11   * This program is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14   * GNU Affero General Public License for more details.
15   * 
16   * You should have received a copy of the GNU Affero General Public License
17   * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18   */
19  package org.kuali.kfs.sec.businessobject;
20  
21  import java.util.ArrayList;
22  import java.util.LinkedHashMap;
23  import java.util.List;
24  
25  import org.apache.commons.lang.StringUtils;
26  import org.kuali.kfs.sys.KFSPropertyConstants;
27  import org.kuali.kfs.sys.context.SpringContext;
28  import org.kuali.rice.kim.api.identity.Person;
29  import org.kuali.rice.krad.bo.PersistableBusinessObjectBase;
30  
31  /**
32   * Represents the assignment of one or more security definitions and one or more models to a principal
33   */
34  public class SecurityPrincipal extends PersistableBusinessObjectBase {
35      protected String principalId;
36  
37      protected Person securityPerson;
38  
39      protected List<SecurityPrincipalDefinition> principalDefinitions = new ArrayList<SecurityPrincipalDefinition>();
40      protected List<SecurityModelMember> principalModels = new ArrayList<SecurityModelMember>();
41  
42      /**
43       * Gets the principalId attribute.
44       * 
45       * @return Returns the principalId.
46       */
47      public String getPrincipalId() {
48          return principalId;
49      }
50  
51  
52      /**
53       * Sets the principalId attribute value.
54       * 
55       * @param principalId The principalId to set.
56       */
57      public void setPrincipalId(String principalId) {
58          this.principalId = principalId;
59      }
60  
61  
62      /**
63       * Gets the securityPerson attribute.
64       * 
65       * @return Returns the securityPerson.
66       */
67      public Person getSecurityPerson() {
68          securityPerson = SpringContext.getBean(org.kuali.rice.kim.api.identity.PersonService.class).updatePersonIfNecessary(principalId, securityPerson);
69          return securityPerson;
70      }
71  
72  
73      /**
74       * Sets the securityPerson attribute value.
75       * 
76       * @param securityPerson The securityPerson to set.
77       */
78      public void setSecurityPerson(Person securityPerson) {
79          this.securityPerson = securityPerson;
80      }
81  
82  
83      /**
84       * Gets the principalDefinitions attribute.
85       * 
86       * @return Returns the principalDefinitions.
87       */
88      public List<SecurityPrincipalDefinition> getPrincipalDefinitions() {
89          return principalDefinitions;
90      }
91  
92  
93      /**
94       * Sets the principalDefinitions attribute value.
95       * 
96       * @param principalDefinitions The principalDefinitions to set.
97       */
98      public void setPrincipalDefinitions(List<SecurityPrincipalDefinition> principalDefinitions) {
99          this.principalDefinitions = principalDefinitions;
100     }
101 
102 
103     /**
104      * Gets the principalModels attribute.
105      * 
106      * @return Returns the principalModels.
107      */
108     public List<SecurityModelMember> getPrincipalModels() {
109         return principalModels;
110     }
111 
112 
113     /**
114      * Sets the principalModels attribute value.
115      * 
116      * @param principalModels The principalModels to set.
117      */
118     public void setPrincipalModels(List<SecurityModelMember> principalModels) {
119         this.principalModels = principalModels;
120     }
121 
122     /**
123      * Returns String of definition names assigned to principal
124      */
125     public String getPrincipalDefinitionNames() {
126         String definitionNames = "";
127 
128         for (SecurityPrincipalDefinition definition : principalDefinitions) {
129             if (StringUtils.isNotBlank(definitionNames)) {
130                 definitionNames += ", ";
131             }
132             definitionNames += definition.getSecurityDefinition().getName();
133         }
134 
135         return definitionNames;
136     }
137 
138     /**
139      * Returns String of model names assigned to principal
140      */
141     public String getPrincipalModelNames() {
142         String modelNames = "";
143 
144         for (SecurityModelMember modelMember : principalModels) {
145             if (StringUtils.isNotBlank(modelNames)) {
146                 modelNames += ", ";
147             }
148             modelNames += modelMember.getSecurityModel().getName();
149         }
150 
151         return modelNames;
152     }
153 
154 
155     @Override
156     public String toString() {
157         StringBuilder builder = new StringBuilder();
158         builder.append("SecurityPrincipal [");
159         if (principalId != null) {
160             builder.append("principalId=");
161             builder.append(principalId);
162             builder.append(", ");
163         }
164         if (getPrincipalDefinitionNames() != null) {
165             builder.append("getPrincipalDefinitionNames()=");
166             builder.append(getPrincipalDefinitionNames());
167             builder.append(", ");
168         }
169         if (getPrincipalModelNames() != null) {
170             builder.append("getPrincipalModelNames()=");
171             builder.append(getPrincipalModelNames());
172         }
173         builder.append("]");
174         return builder.toString();
175     }
176 
177     
178 }