1
|
=== modified file 'src/com/goldencode/p2j/main/WebHandler.java'
|
2
|
--- src/com/goldencode/p2j/main/WebHandler.java 2015-05-18 20:48:28 +0000
|
3
|
+++ src/com/goldencode/p2j/main/WebHandler.java 2016-01-28 12:36:53 +0000
|
4
|
@@ -19,18 +19,22 @@
|
5
|
** 007 OM 20150108 Passed null map as additional environment to WebClientSpawner.spawn().
|
6
|
** 008 GES 20150127 Cleanup code formatting.
|
7
|
** 009 GES 20150311 Modified this to support both chui and gui web clients.
|
8
|
+** 010 SBI 20160128 Changed the redirect HTTP response to the "text/html" response containing
|
9
|
+** the redirect path in its body.
|
10
|
*/
|
11
|
|
12
|
package com.goldencode.p2j.main;
|
13
|
|
14
|
import java.io.*;
|
15
|
import java.util.logging.*;
|
16
|
+
|
17
|
import javax.servlet.*;
|
18
|
import javax.servlet.http.*;
|
19
|
+
|
20
|
import org.eclipse.jetty.http.*;
|
21
|
import org.eclipse.jetty.server.*;
|
22
|
import org.eclipse.jetty.server.handler.*;
|
23
|
-import com.goldencode.p2j.ui.client.chui.driver.web.*;
|
24
|
+
|
25
|
import com.goldencode.p2j.util.*;
|
26
|
import com.goldencode.util.PlatformHelper;
|
27
|
|
28
|
@@ -228,7 +232,7 @@
|
29
|
}
|
30
|
}
|
31
|
|
32
|
- response.sendRedirect(remoteUri);
|
33
|
+ sendRedirectPath(remoteUri, base, request, response);
|
34
|
}
|
35
|
else
|
36
|
{
|
37
|
@@ -244,6 +248,51 @@
|
38
|
}
|
39
|
|
40
|
/**
|
41
|
+ * Sends the redirect to the main application site that requires users to be authorized.
|
42
|
+ *
|
43
|
+ * @param remoteUri
|
44
|
+ * The redirect url provided with the authorization parameter.
|
45
|
+ * @param base
|
46
|
+ * The base request.
|
47
|
+ * @param request
|
48
|
+ * The http request.
|
49
|
+ * @param response
|
50
|
+ * The http response.
|
51
|
+ */
|
52
|
+ private void sendRedirectPath(
|
53
|
+ String remoteUri,
|
54
|
+ Request base,
|
55
|
+ HttpServletRequest request,
|
56
|
+ HttpServletResponse response)
|
57
|
+ {
|
58
|
+ response.setContentType(MimeTypes.Type.TEXT_HTML.asString());
|
59
|
+ response.setStatus(HttpServletResponse.SC_OK);
|
60
|
+ response.setHeader(HttpHeader.CACHE_CONTROL.asString(),
|
61
|
+ "no-cache, no-store, must-revalidate");
|
62
|
+ response.setDateHeader(HttpHeader.EXPIRES.asString(), 0);
|
63
|
+
|
64
|
+ try
|
65
|
+ {
|
66
|
+ PrintWriter writer = response.getWriter();
|
67
|
+ writer.println(remoteUri);
|
68
|
+ writer.flush();
|
69
|
+ }
|
70
|
+ catch (IOException ioe)
|
71
|
+ {
|
72
|
+ LOG.logp(Level.SEVERE,
|
73
|
+ "WebHandler.sendRedirectPath()",
|
74
|
+ "",
|
75
|
+ LogHelper.generate("IOException!"),
|
76
|
+ ioe);
|
77
|
+ }
|
78
|
+ finally
|
79
|
+ {
|
80
|
+ // mark the request as handled
|
81
|
+ base.setHandled(true);
|
82
|
+ }
|
83
|
+ }
|
84
|
+
|
85
|
+ /**
|
86
|
* Process the given string and make any replacements of parameter
|
87
|
* values as needed. The replacement placeholder follow the JEE
|
88
|
* expression language (EL) format for immediate evaluation.
|
89
|
|
90
|
=== modified file 'src/com/goldencode/p2j/main/web_client.html'
|
91
|
--- src/com/goldencode/p2j/main/web_client.html 2015-05-18 20:48:28 +0000
|
92
|
+++ src/com/goldencode/p2j/main/web_client.html 2016-01-28 12:32:29 +0000
|
93
|
@@ -2,11 +2,94 @@
|
94
|
<html>
|
95
|
<head>
|
96
|
<title>Operating System Login (P2J ${client_ui_type} Web Client)</title>
|
97
|
- </head>
|
98
|
+<script type="text/javascript">
|
99
|
+
|
100
|
+"use strict";
|
101
|
+
|
102
|
+/**
|
103
|
+ * Creates the HTTP request object, posts the form, parces the response and changes
|
104
|
+ * the document location to the new redirect path.
|
105
|
+ */
|
106
|
+var requestHelper = function()
|
107
|
+{
|
108
|
+ var me = {};
|
109
|
+
|
110
|
+ var postForm;
|
111
|
+
|
112
|
+ function PostForm(formElement)
|
113
|
+ {
|
114
|
+ var httpRequest;
|
115
|
+
|
116
|
+ if (window.XMLHttpRequest)
|
117
|
+ {
|
118
|
+ httpRequest = new XMLHttpRequest();
|
119
|
+ }
|
120
|
+ else
|
121
|
+ {
|
122
|
+ httpRequest = null;
|
123
|
+ }
|
124
|
+
|
125
|
+ function stateChanged ()
|
126
|
+ {
|
127
|
+ try
|
128
|
+ {
|
129
|
+ if (httpRequest.readyState === 4) {
|
130
|
+ if (httpRequest.status === 200)
|
131
|
+ {
|
132
|
+ if (httpRequest.responseText)
|
133
|
+ {
|
134
|
+ window.location.assign(httpRequest.responseText);
|
135
|
+ }
|
136
|
+ }
|
137
|
+ }
|
138
|
+ }
|
139
|
+ catch(ex)
|
140
|
+ {
|
141
|
+ console.error(JSON.stringify(ex));
|
142
|
+ }
|
143
|
+ }
|
144
|
+
|
145
|
+ function sendRequest()
|
146
|
+ {
|
147
|
+ if (httpRequest !== null)
|
148
|
+ {
|
149
|
+ httpRequest.onreadystatechange = stateChanged;
|
150
|
+ httpRequest.open('POST', window.location.href);
|
151
|
+ httpRequest.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
|
152
|
+ httpRequest.responseType = "text";
|
153
|
+ httpRequest.send("usr=" + encodeURIComponent(formElement.usr.value) +
|
154
|
+ "&psw=" + encodeURIComponent(formElement.psw.value));
|
155
|
+ }
|
156
|
+ }
|
157
|
+
|
158
|
+ this.sendRequest = sendRequest;
|
159
|
+ }
|
160
|
+
|
161
|
+ /**
|
162
|
+ * Initializes the request helper object in order to post the form.
|
163
|
+ */
|
164
|
+ me.initialize = function ()
|
165
|
+ {
|
166
|
+ postForm = new PostForm(document.loginForm);
|
167
|
+ }
|
168
|
+
|
169
|
+ /**
|
170
|
+ * Posts the form.
|
171
|
+ */
|
172
|
+ me.sendRequest = function ()
|
173
|
+ {
|
174
|
+ postForm.sendRequest();
|
175
|
+ return false;
|
176
|
+ }
|
177
|
+
|
178
|
+ return me;
|
179
|
+}();
|
180
|
+</script>
|
181
|
+</head>
|
182
|
<body>
|
183
|
<div style="margin-top:150px;">
|
184
|
<div align="center">
|
185
|
- <form method="POST">
|
186
|
+ <form name="loginForm" method="POST" onsubmit="return requestHelper.sendRequest();" >
|
187
|
<table>
|
188
|
<tr>
|
189
|
<td>User Name:</td><td><input type="text" size="20" name="usr" autofocus></td>
|
190
|
@@ -21,6 +104,7 @@
|
191
|
</form>
|
192
|
</div>
|
193
|
<div align="center" style="margin-top:100px">${error}</div>
|
194
|
- </div>
|
195
|
+ </div>
|
196
|
+ <script type="text/javascript">requestHelper.initialize();</script>
|
197
|
</body>
|
198
|
</html>
|
199
|
\ No newline at end of file
|
200
|
|