001 /*
002 * Copyright 2011 The Kuali Foundation.
003 *
004 * Licensed under the Educational Community License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.opensource.org/licenses/ecl2.php
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016 package org.kuali.kfs.sec.businessobject;
017
018 import java.util.LinkedHashMap;
019 import java.util.List;
020
021 import org.apache.commons.lang.StringUtils;
022 import org.kuali.kfs.sys.KFSPropertyConstants;
023 import org.kuali.kfs.sys.context.SpringContext;
024 import org.kuali.rice.kim.bo.Person;
025 import org.kuali.rice.kns.bo.PersistableBusinessObjectBase;
026 import org.kuali.rice.kns.util.TypedArrayList;
027
028 /**
029 * Represents the assignment of one or more security definitions and one or more models to a principal
030 */
031 public class SecurityPrincipal extends PersistableBusinessObjectBase {
032 private String principalId;
033
034 private Person securityPerson;
035
036 private List<SecurityPrincipalDefinition> principalDefinitions;
037 private List<SecurityModelMember> principalModels;
038
039 public SecurityPrincipal() {
040 super();
041
042 principalDefinitions = new TypedArrayList(SecurityPrincipalDefinition.class);
043 principalModels = new TypedArrayList(SecurityModelMember.class);
044 }
045
046
047 /**
048 * Gets the principalId attribute.
049 *
050 * @return Returns the principalId.
051 */
052 public String getPrincipalId() {
053 return principalId;
054 }
055
056
057 /**
058 * Sets the principalId attribute value.
059 *
060 * @param principalId The principalId to set.
061 */
062 public void setPrincipalId(String principalId) {
063 this.principalId = principalId;
064 }
065
066
067 /**
068 * Gets the securityPerson attribute.
069 *
070 * @return Returns the securityPerson.
071 */
072 public Person getSecurityPerson() {
073 securityPerson = SpringContext.getBean(org.kuali.rice.kim.service.PersonService.class).updatePersonIfNecessary(principalId, securityPerson);
074 return securityPerson;
075 }
076
077
078 /**
079 * Sets the securityPerson attribute value.
080 *
081 * @param securityPerson The securityPerson to set.
082 */
083 public void setSecurityPerson(Person securityPerson) {
084 this.securityPerson = securityPerson;
085 }
086
087
088 /**
089 * Gets the principalDefinitions attribute.
090 *
091 * @return Returns the principalDefinitions.
092 */
093 public List<SecurityPrincipalDefinition> getPrincipalDefinitions() {
094 return principalDefinitions;
095 }
096
097
098 /**
099 * Sets the principalDefinitions attribute value.
100 *
101 * @param principalDefinitions The principalDefinitions to set.
102 */
103 public void setPrincipalDefinitions(List<SecurityPrincipalDefinition> principalDefinitions) {
104 this.principalDefinitions = principalDefinitions;
105 }
106
107
108 /**
109 * Gets the principalModels attribute.
110 *
111 * @return Returns the principalModels.
112 */
113 public List<SecurityModelMember> getPrincipalModels() {
114 return principalModels;
115 }
116
117
118 /**
119 * Sets the principalModels attribute value.
120 *
121 * @param principalModels The principalModels to set.
122 */
123 public void setPrincipalModels(List<SecurityModelMember> principalModels) {
124 this.principalModels = principalModels;
125 }
126
127 /**
128 * Returns String of definition names assigned to principal
129 */
130 public String getPrincipalDefinitionNames() {
131 String definitionNames = "";
132
133 for (SecurityPrincipalDefinition definition : principalDefinitions) {
134 if (StringUtils.isNotBlank(definitionNames)) {
135 definitionNames += ", ";
136 }
137 definitionNames += definition.getSecurityDefinition().getName();
138 }
139
140 return definitionNames;
141 }
142
143 /**
144 * Returns String of model names assigned to principal
145 */
146 public String getPrincipalModelNames() {
147 String modelNames = "";
148
149 for (SecurityModelMember modelMember : principalModels) {
150 if (StringUtils.isNotBlank(modelNames)) {
151 modelNames += ", ";
152 }
153 modelNames += modelMember.getSecurityModel().getName();
154 }
155
156 return modelNames;
157 }
158
159 /**
160 * @see org.kuali.rice.kns.bo.BusinessObjectBase#toStringMapper()
161 */
162 @Override
163 protected LinkedHashMap toStringMapper() {
164 LinkedHashMap m = new LinkedHashMap();
165
166 m.put(KFSPropertyConstants.PRINCIPAL_ID, this.principalId);
167
168 return m;
169 }
170
171 }