001: /*
002: * Copyright 2005-2006 The Kuali Foundation.
003: *
004: *
005: * Licensed under the Educational Community License, Version 1.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * You may obtain a copy of the License at
008: *
009: * http://www.opensource.org/licenses/ecl1.php
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package edu.iu.uis.eden.web.session;
018:
019: import java.io.Serializable;
020: import java.util.ArrayList;
021: import java.util.HashMap;
022: import java.util.List;
023: import java.util.Map;
024:
025: import org.kuali.rice.core.Core;
026:
027: import edu.iu.uis.eden.EdenConstants;
028: import edu.iu.uis.eden.KEWServiceLocator;
029: import edu.iu.uis.eden.actionlist.ActionListFilter;
030: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
031: import edu.iu.uis.eden.preferences.Preferences;
032: import edu.iu.uis.eden.user.AuthenticationUserId;
033: import edu.iu.uis.eden.user.EmplId;
034: import edu.iu.uis.eden.user.UserId;
035: import edu.iu.uis.eden.user.UserService;
036: import edu.iu.uis.eden.user.WorkflowUser;
037: import edu.iu.uis.eden.util.Utilities;
038: import edu.iu.uis.eden.workgroup.GroupNameId;
039: import edu.iu.uis.eden.workgroup.Workgroup;
040:
041: /**
042: * Represents an authenticated user within the Workflow system.
043: *
044: * <p>The current authenticated UserSession is stored in a ThreadLocal and can be
045: * accessed using UserSession.getAuthenticatedUser().
046: *
047: * @author ewestfal
048: */
049: public class UserSession implements Serializable {
050:
051: private static final long serialVersionUID = 1L;
052:
053: private static ThreadLocal currentUserSession = new ThreadLocal();
054:
055: private UserId backdoorId;
056: private WorkflowUser workflowUser;
057: private WorkflowUser backdoorWorkflowUser;
058: private WorkflowUser helpDeskActionListUser;
059: private int nextObjectKey;
060: private transient Map objectMap = new HashMap();
061: private ActionListFilter actionListFilter;
062: private Preferences preferences;
063: private List authentications = new ArrayList();
064:
065: public UserSession(WorkflowUser user) {
066: this .workflowUser = user;
067: this .nextObjectKey = 0;
068: }
069:
070: public static UserSession getAuthenticatedUser() {
071: return (UserSession) currentUserSession.get();
072: }
073:
074: public static void setAuthenticatedUser(
075: UserSession currentUserSession) {
076: UserSession.currentUserSession.set(currentUserSession);
077: }
078:
079: public WorkflowUser getHelpDeskActionListUser() {
080: return helpDeskActionListUser;
081: }
082:
083: public void setHelpDeskActionListUser(
084: WorkflowUser helpDeskActionListUser) {
085: this .helpDeskActionListUser = helpDeskActionListUser;
086: }
087:
088: public Preferences getPreferences() {
089: return preferences;
090: }
091:
092: public void setPreferences(Preferences preferences) {
093: this .preferences = preferences;
094: }
095:
096: public ActionListFilter getActionListFilter() {
097: return actionListFilter;
098: }
099:
100: public void setActionListFilter(ActionListFilter actionListFilter) {
101: this .actionListFilter = actionListFilter;
102: }
103:
104: public String getNetworkId() {
105: if (backdoorId != null) {
106: return backdoorWorkflowUser.getAuthenticationUserId()
107: .getAuthenticationId();
108: } else {
109: return workflowUser.getAuthenticationUserId()
110: .getAuthenticationId();
111: }
112: }
113:
114: public WorkflowUser getWorkflowUser() {
115: if (backdoorId != null) {
116: return backdoorWorkflowUser;
117: } else {
118: return workflowUser;
119: }
120: }
121:
122: public WorkflowUser getLoggedInWorkflowUser() {
123: return workflowUser;
124: }
125:
126: public boolean setBackdoorId(String id)
127: throws EdenUserNotFoundException {
128: if (!EdenConstants.PROD_DEPLOYMENT_CODE.equalsIgnoreCase(Core
129: .getCurrentContextConfig().getEnvironment())) {
130: if (id.matches("^\\d*$")) {
131: this .backdoorId = new EmplId(id);
132: } else {
133: this .backdoorId = new AuthenticationUserId(id);
134: }
135: this .backdoorWorkflowUser = ((UserService) KEWServiceLocator
136: .getUserService()).getWorkflowUser(this .backdoorId);
137: }
138: return this .backdoorWorkflowUser != null;
139: }
140:
141: public void clearBackdoor() {
142: this .backdoorId = null;
143: setPreferences(KEWServiceLocator.getPreferencesService()
144: .getPreferences(workflowUser));
145: }
146:
147: public String addObject(Object object) {
148: String objectKey = nextObjectKey++ + "";
149: getObjectMap().put(objectKey, object);
150: return objectKey;
151: }
152:
153: public Object retrieveObject(String objectKey) {
154: return getObjectMap().get(objectKey);
155: }
156:
157: public void removeObject(String objectKey) {
158: getObjectMap().remove(objectKey);
159: }
160:
161: public boolean isBackdoorInUse() {
162: return backdoorId != null;
163: }
164:
165: public String getEmailAddress() {
166: if (backdoorId != null) {
167: return backdoorWorkflowUser.getEmailAddress();
168: } else {
169: return workflowUser.getEmailAddress();
170: }
171: }
172:
173: public int getNextObjectKey() {
174: return nextObjectKey;
175: }
176:
177: public void setNextObjectKey(int nextObjectKey) {
178: this .nextObjectKey = nextObjectKey;
179: }
180:
181: public Map getObjectMap() {
182: if (objectMap == null) {
183: objectMap = new HashMap();
184: }
185: return objectMap;
186: }
187:
188: public void setObjectMap(Map objectMap) {
189: this .objectMap = objectMap;
190: }
191:
192: public String getDisplayName() {
193: if (backdoorId != null) {
194: return backdoorWorkflowUser.getDisplayName();
195: } else {
196: return workflowUser.getDisplayName();
197: }
198: }
199:
200: public UserId getBackdoorId() {
201: return backdoorId;
202: }
203:
204: public boolean isAdmin() {
205: Workgroup workflowAdminGroup = KEWServiceLocator
206: .getWorkgroupService()
207: .getWorkgroup(
208: new GroupNameId(
209: Utilities
210: .getApplicationConstant(EdenConstants.WORKFLOW_ADMIN_WORKGROUP_NAME_KEY)));
211: return workflowAdminGroup.hasMember(getWorkflowUser());
212: }
213:
214: /**
215: * Returns a List of Authentications on the UserSession. This List identifies the various types of
216: * authentications that the user has performed (i.e. Kerberos, Safeword, etc.)
217: */
218: public List getAuthentications() {
219: return authentications;
220: }
221:
222: public void addAuthentication(Authentication authentication) {
223: getAuthentications().add(authentication);
224: }
225:
226: public void removeAuthentication(Authentication authentication) {
227: getAuthentications().remove(authentication);
228: }
229: }
|