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