001: /**********************************************************************************
002: * $URL: https://source.sakaiproject.org/svn/metaobj/tags/sakai_2-4-1/metaobj-impl/api-impl/src/java/org/sakaiproject/metaobj/shared/model/impl/AgentImpl.java $
003: * $Id: AgentImpl.java 14225 2006-09-05 17:39:44Z chmaurer@iupui.edu $
004: ***********************************************************************************
005: *
006: * Copyright (c) 2004, 2005, 2006 The Sakai Foundation.
007: *
008: * Licensed under the Educational Community License, Version 1.0 (the "License");
009: * you may not use this file except in compliance with the License.
010: * You may obtain a copy of the License at
011: *
012: * http://www.opensource.org/licenses/ecl1.php
013: *
014: * Unless required by applicable law or agreed to in writing, software
015: * distributed under the License is distributed on an "AS IS" BASIS,
016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
017: * See the License for the specific language governing permissions and
018: * limitations under the License.
019: *
020: **********************************************************************************/package org.sakaiproject.metaobj.shared.model.impl;
021:
022: import java.util.ArrayList;
023: import java.util.List;
024:
025: import org.apache.commons.codec.digest.DigestUtils;
026: import org.sakaiproject.metaobj.shared.mgt.HomeFactory;
027: import org.sakaiproject.metaobj.shared.model.Agent;
028: import org.sakaiproject.metaobj.shared.model.Artifact;
029: import org.sakaiproject.metaobj.shared.model.Id;
030: import org.sakaiproject.metaobj.shared.model.StructuredArtifact;
031:
032: public class AgentImpl implements Agent {
033: static public final String ID = "id";
034: static public final String REAL_NAME = "realName";
035: static public final String EMAIL = "email";
036: static public final String ROLES = "roles";
037:
038: private Id id;
039: private Id eid;
040: private StructuredArtifact profile;
041: private String[] roles;
042: private HomeFactory homeFactory;
043: private String displayName;
044: private String md5Password;
045: private String password;
046: private String role;
047: private boolean initialized = false;
048:
049: public AgentImpl() {
050:
051: }
052:
053: public AgentImpl(Id id) {
054: this .id = id;
055: }
056:
057: public AgentImpl(StructuredArtifact profile) {
058: this .profile = profile;
059: }
060:
061: public Id getId() {
062: return id;
063: }
064:
065: public void setId(Id id) {
066: this .id = id;
067: }
068:
069: public Id getEid() {
070: return eid;
071: }
072:
073: public void setEid(Id eid) {
074: this .eid = eid;
075: }
076:
077: public Artifact getProfile() {
078: return profile;
079: }
080:
081: public void setProfile(StructuredArtifact profile) {
082: this .profile = profile;
083: }
084:
085: public Object getProperty(String key) {
086: return profile.get(key);
087: }
088:
089: public String getDisplayName() {
090: return displayName;
091: }
092:
093: public boolean isInRole(String role) {
094:
095: for (int i = 0; i < getRoles().length; i++) {
096: if (role.equals(getRoles()[i])) {
097: return true;
098: }
099: }
100:
101: return false;
102: }
103:
104: public boolean isInitialized() {
105: return initialized;
106: }
107:
108: public void setInitialized(boolean initialized) {
109: this .initialized = initialized;
110: }
111:
112: public void setDisplayName(String displayName) {
113: this .displayName = displayName;
114: }
115:
116: /**
117: * I imagine this will probably move into a authz call and out of here
118: *
119: * @return
120: */
121: public String[] getRoles() {
122: /* if (roles == null) {
123: //TODO implement for multiple roles
124: roles = new String[1];
125: roles[0] = (String) profile.get("role");
126: }
127: */
128: roles = new String[1];
129: roles[0] = role;
130:
131: return roles;
132: }
133:
134: public void setRoles(String[] roles) {
135: this .roles = roles;
136: }
137:
138: public HomeFactory getHomeFactory() {
139: return homeFactory;
140: }
141:
142: public void setHomeFactory(HomeFactory homeFactory) {
143: this .homeFactory = homeFactory;
144: }
145:
146: public String getPassword() {
147: return getMd5Password();
148: }
149:
150: public String getClearPassword() {
151: return password;
152: }
153:
154: public void setPassword(String password) {
155: this .password = password;
156: this .md5Password = DigestUtils.md5Hex(password);
157: }
158:
159: public String getMd5Password() {
160: return md5Password;
161: }
162:
163: public void setMd5Password(String md5Password) {
164: this .md5Password = md5Password;
165: }
166:
167: public String getRole() {
168: return role;
169: }
170:
171: public List getWorksiteRoles(String worksiteId) {
172: return new ArrayList();
173: }
174:
175: public List getWorksiteRoles() {
176: return new ArrayList();
177: }
178:
179: public boolean isRole() {
180: return false;
181: }
182:
183: public void setRole(String role) {
184: this .role = role;
185: }
186:
187: public String naturalKey() {
188: return "" + displayName;
189: }
190:
191: public boolean equals(Object o) {
192: if (this == o) {
193: return true;
194: }
195: if (!(o instanceof AgentImpl)) {
196: return false;
197: }
198:
199: final AgentImpl agent = (AgentImpl) o;
200: return naturalKey().equals(agent.naturalKey());
201: }
202:
203: public int hashCode() {
204: return naturalKey().hashCode();
205: }
206:
207: /**
208: * Returns the name of this principal.
209: *
210: * @return the name of this principal.
211: */
212: public String getName() {
213: return getDisplayName();
214: }
215:
216: }
|