001: /*
002: * Copyright 2005-2007 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: // Created on Dec 13, 2005
018: package edu.iu.uis.eden.test.web;
019:
020: import javax.servlet.ServletContext;
021:
022: import org.springframework.mock.web.MockHttpServletRequest;
023:
024: import edu.iu.uis.eden.EdenConstants;
025: import edu.iu.uis.eden.KEWServiceLocator;
026: import edu.iu.uis.eden.exception.EdenUserNotFoundException;
027: import edu.iu.uis.eden.user.AuthenticationUserId;
028: import edu.iu.uis.eden.user.UserId;
029: import edu.iu.uis.eden.user.WorkflowUser;
030: import edu.iu.uis.eden.web.session.UserSession;
031:
032: /**
033: * Subclass of MockHttpServletRequest that initializes the request with a user session
034: * @author Aaron Hamid
035: */
036: public class WorkflowServletRequest extends MockHttpServletRequest {
037: public WorkflowServletRequest() {
038: super ();
039: }
040:
041: public WorkflowServletRequest(ServletContext context,
042: String method, String requestURI) {
043: super (context, method, requestURI);
044: }
045:
046: public WorkflowServletRequest(ServletContext context) {
047: super (context);
048: }
049:
050: public WorkflowServletRequest(String method, String requestURI) {
051: super (method, requestURI);
052: }
053:
054: public WorkflowServletRequest(String user)
055: throws EdenUserNotFoundException {
056: setUser(user);
057: }
058:
059: public void setUser(String user) throws EdenUserNotFoundException {
060: WorkflowUser wfuser;
061: if (user == null) {
062: wfuser = null;
063: } else {
064: wfuser = KEWServiceLocator.getUserService()
065: .getWorkflowUser(new AuthenticationUserId(user));
066: }
067: setWorkflowUser(wfuser);
068: }
069:
070: public String getUser() {
071: WorkflowUser user = getWorkflowUser();
072: if (user == null)
073: return null;
074: UserId userId = user.getAuthenticationUserId();
075: if (userId == null)
076: return null;
077: return userId.getId();
078: }
079:
080: public void setBackdoorId(String backdoorId)
081: throws EdenUserNotFoundException {
082: UserSession session = getUserSession();
083: if (session == null) {
084: throw new IllegalStateException(
085: "Session must be set before backdoor id is set");
086: }
087: session.setBackdoorId(backdoorId);
088: }
089:
090: public String getBackdoorId() {
091: UserId userId = getBackdoorUserId();
092: if (userId == null)
093: return null;
094: return userId.getId();
095: }
096:
097: public void setWorkflowUser(WorkflowUser user) {
098: if (user == null) {
099: setUserSession(null);
100: } else {
101: setUserSession(new UserSession(user));
102: }
103: }
104:
105: public WorkflowUser getWorkflowUser() {
106: UserSession session = getUserSession();
107: if (session == null)
108: return null;
109: return session.getLoggedInWorkflowUser();
110: }
111:
112: public UserId getBackdoorUserId() {
113: UserSession session = getUserSession();
114: if (session == null)
115: return null;
116: return session.getBackdoorId();
117: }
118:
119: public void setUserSession(UserSession userSession) {
120: getSession().setAttribute(EdenConstants.USER_SESSION_KEY,
121: userSession);
122: }
123:
124: public UserSession getUserSession() {
125: return (UserSession) getSession().getAttribute(
126: EdenConstants.USER_SESSION_KEY);
127: }
128: }
|