1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.rice.kew.test.web;
17
18 import javax.servlet.ServletContext;
19
20 import org.kuali.rice.kim.api.identity.principal.Principal;
21 import org.kuali.rice.kim.api.services.KimApiServiceLocator;
22 import org.kuali.rice.krad.UserSession;
23 import org.kuali.rice.krad.util.KRADConstants;
24 import org.springframework.mock.web.MockHttpServletRequest;
25
26
27
28
29
30
31 public class WorkflowServletRequest extends MockHttpServletRequest {
32 public WorkflowServletRequest() {
33 super();
34 }
35 public WorkflowServletRequest(ServletContext context, String method, String requestURI) {
36 super(context, method, requestURI);
37 }
38 public WorkflowServletRequest(ServletContext context) {
39 super(context);
40 }
41 public WorkflowServletRequest(String method, String requestURI) {
42 super(method, requestURI);
43 }
44
45 public WorkflowServletRequest(String user) {
46 setUser(user);
47 }
48
49 public void setUser(String user) {
50 Principal wfuser;
51 if (user == null) {
52 wfuser = null;
53 } else {
54 wfuser = KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(user);
55 }
56 setWorkflowUser(wfuser);
57 }
58
59 public String getUser() {
60 Principal user = getWorkflowUser();
61 if (user == null) return null;
62 return user.getPrincipalName();
63 }
64
65 public void setBackdoorId(String backdoorId) {
66 UserSession session = getUserSession();
67 if (session == null) {
68 throw new IllegalStateException("Session must be set before backdoor id is set");
69 }
70 session.setBackdoorUser(backdoorId);
71 }
72
73 public void setWorkflowUser(Principal user) {
74 if (user == null) {
75 setUserSession(null);
76 } else {
77 setUserSession(new UserSession(user.getPrincipalName()));
78 }
79 }
80
81 public Principal getWorkflowUser() {
82 UserSession session = getUserSession();
83 if (session == null) return null;
84 return KimApiServiceLocator.getIdentityService().getPrincipalByPrincipalName(session.getLoggedInUserPrincipalName());
85 }
86
87 public String getBackdoorPrincipalId() {
88 UserSession session = getUserSession();
89 if (session == null) return null;
90 return session.getPrincipalId();
91 }
92
93 public void setUserSession(UserSession userSession) {
94 getSession().setAttribute(KRADConstants.USER_SESSION_KEY, userSession);
95 }
96
97 public UserSession getUserSession() {
98 return (UserSession) getSession().getAttribute(KRADConstants.USER_SESSION_KEY);
99 }
100 }