|
@@ -1,66 +1,55 @@ |
1 |
1 |
|
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
2 |
|
package org.litesoft.GWT.eventbus.server; |
3 |
3 |
|
|
4 |
|
- |
import java.io.*; |
5 |
|
- |
|
6 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
7 |
|
- |
|
8 |
|
- |
import java.util.*; |
9 |
|
- |
import javax.servlet.http.*; |
10 |
|
- |
|
11 |
4 |
|
import org.litesoft.GWT.client.*; |
12 |
5 |
|
import org.litesoft.GWT.eventbus.client.*; |
13 |
6 |
|
import org.litesoft.GWT.eventbus.client.eventpackages.*; |
14 |
7 |
|
import org.litesoft.GWT.eventbus.client.nonpublic.*; |
15 |
8 |
|
import org.litesoft.GWT.eventbus.server.nonpublic.*; |
16 |
9 |
|
import org.litesoft.*; |
|
10 |
+ |
import org.litesoft.commonfoundation.typeutils.*; |
17 |
11 |
|
import org.litesoft.configuration.*; |
18 |
12 |
|
import org.litesoft.util.template.*; |
19 |
13 |
|
|
20 |
|
- |
public abstract class AbstractAuthenticatingHtmlLauncherServerApp extends AbstractAuthenticatingServerApp |
21 |
|
- |
{ |
|
14 |
+ |
import javax.servlet.http.*; |
|
15 |
+ |
import java.io.*; |
|
16 |
+ |
import java.util.*; |
|
17 |
+ |
|
|
18 |
+ |
public abstract class AbstractAuthenticatingHtmlLauncherServerApp extends AbstractAuthenticatingServerApp { |
22 |
19 |
|
private static final String LOGOUT_TEMPLATE_HTML = "Logout.template.html"; |
23 |
20 |
|
private static final String LOGIN_TEMPLATE_HTML = "Login.template.html"; |
24 |
21 |
|
private static final String PROPERTY_APP_PAGE_URL = "appPageUrl"; |
25 |
22 |
|
|
26 |
|
- |
private boolean isPortalDebugMode() |
27 |
|
- |
{ |
|
23 |
+ |
private boolean isPortalDebugMode() { |
28 |
24 |
|
return Configuration.getBoolean( "PortalDebugMode", false ); |
29 |
25 |
|
} |
30 |
26 |
|
|
31 |
|
- |
private String getCSSfileRef() |
32 |
|
- |
{ |
|
27 |
+ |
private String getCSSfileRef() { |
33 |
28 |
|
return Strings.noEmpty( Configuration.getString( "CSSfileRef" ) ); |
34 |
29 |
|
} |
35 |
30 |
|
|
36 |
|
- |
private String getCSSclass() |
37 |
|
- |
{ |
|
31 |
+ |
private String getCSSclass() { |
38 |
32 |
|
String zCSSclass = Strings.noEmpty( Configuration.getString( "CSSclass" ) ); |
39 |
33 |
|
return (zCSSclass != null) ? zCSSclass : "Classless"; |
40 |
34 |
|
} |
41 |
35 |
|
|
42 |
|
- |
protected String getTemplatePath() |
43 |
|
- |
{ |
|
36 |
+ |
protected String getTemplatePath() { |
44 |
37 |
|
return ServerConfiguration.getPath( "HTMLtemplatesPath", "" ); |
45 |
38 |
|
} |
46 |
39 |
|
|
47 |
40 |
|
protected Reader getLogoutReader() |
48 |
|
- |
throws IOException |
49 |
|
- |
{ |
|
41 |
+ |
throws IOException { |
50 |
42 |
|
return getTemplateReader( LOGOUT_TEMPLATE_HTML ); |
51 |
43 |
|
} |
52 |
44 |
|
|
53 |
45 |
|
protected Reader getLoginReader() |
54 |
|
- |
throws IOException |
55 |
|
- |
{ |
|
46 |
+ |
throws IOException { |
56 |
47 |
|
return getTemplateReader( LOGIN_TEMPLATE_HTML ); |
57 |
48 |
|
} |
58 |
49 |
|
|
59 |
50 |
|
private Reader getTemplateReader( String pTemplateID ) |
60 |
|
- |
throws IOException |
61 |
|
- |
{ |
62 |
|
- |
if ( Configuration.getString( pTemplateID, "" ).trim().length() == 0 ) |
63 |
|
- |
{ |
|
51 |
+ |
throws IOException { |
|
52 |
+ |
if ( Configuration.getString( pTemplateID, "" ).trim().length() == 0 ) { |
64 |
53 |
|
String zPath = getTemplatePath(); |
65 |
54 |
|
return new FileReader( new File( zPath, pTemplateID ) ); |
66 |
55 |
|
} |
|
@@ -75,25 +64,21 @@ |
75 |
64 |
|
private WindowNameClientIdCodec mWindowNameClientIdCodec; |
76 |
65 |
|
|
77 |
66 |
|
protected AbstractAuthenticatingHtmlLauncherServerApp( String pServletRelativeReference, String pAppPageURL, IAuthenticationService pAuthenticationService, |
78 |
|
- |
AppNames pAppNames ) |
79 |
|
- |
{ |
|
67 |
+ |
AppNames pAppNames ) { |
80 |
68 |
|
super( pAuthenticationService ); |
81 |
69 |
|
mServletRelativeReference = pServletRelativeReference; |
82 |
70 |
|
mAppPageURL = System.getProperty( PROPERTY_APP_PAGE_URL, pAppPageURL ); |
83 |
71 |
|
mWindowNameClientIdCodec = new WindowNameClientIdCodec( pAppNames ); |
84 |
72 |
|
} |
85 |
73 |
|
|
86 |
|
- |
public void logoutRequestComplete( ServerEventBus pServerEventBus ) |
87 |
|
- |
{ |
|
74 |
+ |
public void logoutRequestComplete( ServerEventBus pServerEventBus ) { |
88 |
75 |
|
pServerEventBus.publishIfNotDisposed( CloseClientEventPackage.INSTANCE ); |
89 |
76 |
|
} |
90 |
77 |
|
|
91 |
78 |
|
private String mCSSfileRef = null; |
92 |
79 |
|
|
93 |
|
- |
private String cachedCSSfileRef() |
94 |
|
- |
{ |
95 |
|
- |
if ( mCSSfileRef == null ) |
96 |
|
- |
{ |
|
80 |
+ |
private String cachedCSSfileRef() { |
|
81 |
+ |
if ( mCSSfileRef == null ) { |
97 |
82 |
|
String zRef = getCSSfileRef(); |
98 |
83 |
|
|
99 |
84 |
|
mCSSfileRef = (zRef == null) ? // |
|
@@ -105,10 +90,8 @@ |
105 |
90 |
|
|
106 |
91 |
|
private String mCSSclass = null; |
107 |
92 |
|
|
108 |
|
- |
private String cachedCSSclass() |
109 |
|
- |
{ |
110 |
|
- |
if ( mCSSclass == null ) |
111 |
|
- |
{ |
|
93 |
+ |
private String cachedCSSclass() { |
|
94 |
+ |
if ( mCSSclass == null ) { |
112 |
95 |
|
mCSSclass = getCSSclass(); |
113 |
96 |
|
} |
114 |
97 |
|
return mCSSclass; |
|
@@ -123,27 +106,22 @@ |
123 |
106 |
|
private static final String NO_POPUP = "!Popup"; |
124 |
107 |
|
|
125 |
108 |
|
protected TemplateControl resolveQuery( HttpServletRequest pRequest, String pQuery ) |
126 |
|
- |
throws IOException |
127 |
|
- |
{ |
128 |
|
- |
if ( QUERY_EQ_LOGOUT.equals( pQuery ) ) |
129 |
|
- |
{ |
|
109 |
+ |
throws IOException { |
|
110 |
+ |
if ( QUERY_EQ_LOGOUT.equals( pQuery ) ) { |
130 |
111 |
|
ServerEventBusSessionMapper.setLogoutMessage( pRequest, this, null ); |
131 |
112 |
|
logout( pRequest ); |
132 |
113 |
|
return createLoginPage( " " ); |
133 |
114 |
|
} |
134 |
|
- |
if ( QUERY_EQ_LOGIN.equals( pQuery ) ) |
135 |
|
- |
{ |
|
115 |
+ |
if ( QUERY_EQ_LOGIN.equals( pQuery ) ) { |
136 |
116 |
|
return loginRequest( pRequest, // |
137 |
117 |
|
pRequest.getParameter( "LoginName" ), // |
138 |
118 |
|
pRequest.getParameter( "Passwd" ) ); |
139 |
119 |
|
} |
140 |
|
- |
if ( QUERY_EQ_PORTAL_FRAME.equals( pQuery ) ) |
141 |
|
- |
{ |
|
120 |
+ |
if ( QUERY_EQ_PORTAL_FRAME.equals( pQuery ) ) { |
142 |
121 |
|
String zHeight = "100%"; |
143 |
122 |
|
String zDebugDiv = " "; |
144 |
123 |
|
String zOverflow = PLUS_OVERFLOW_HIDDEN; |
145 |
|
- |
if ( isPortalDebugMode() ) |
146 |
|
- |
{ |
|
124 |
+ |
if ( isPortalDebugMode() ) { |
147 |
125 |
|
zHeight = "300"; |
148 |
126 |
|
zDebugDiv = "<div id='dbg'></div>"; |
149 |
127 |
|
zOverflow = ""; |
|
@@ -158,13 +136,11 @@ |
158 |
136 |
|
"DebugDiv", zDebugDiv, // |
159 |
137 |
|
KEY_SERVLET_RELATIVE_REFERENCE, mServletRelativeReference ); |
160 |
138 |
|
} |
161 |
|
- |
if ( pQuery.startsWith( QUERY_SW_LOGIN_PAGE_REQUEST ) ) |
162 |
|
- |
{ |
|
139 |
+ |
if ( pQuery.startsWith( QUERY_SW_LOGIN_PAGE_REQUEST ) ) { |
163 |
140 |
|
String zMessage = Strings.noEmpty( ServerEventBusSessionMapper.getLogoutMessage( pRequest, this ) ); |
164 |
141 |
|
return createLoginPage( (zMessage != null) ? zMessage : " " ); |
165 |
142 |
|
} |
166 |
|
- |
if ( pQuery.startsWith( QUERY_SW_LOGOUT_PAGE_REQUEST ) ) |
167 |
|
- |
{ |
|
143 |
+ |
if ( pQuery.startsWith( QUERY_SW_LOGOUT_PAGE_REQUEST ) ) { |
168 |
144 |
|
return new TemplateControl( getLogoutReader(), // |
169 |
145 |
|
"InitScript", "portalsupport/LogoutScript.js", // |
170 |
146 |
|
"CSSfileRef", cachedCSSfileRef(), // |
|
@@ -173,11 +149,9 @@ |
173 |
149 |
|
"Version", getApplicationVersion(), // |
174 |
150 |
|
"SubmitAction", mServletRelativeReference + "?Logout" ); |
175 |
151 |
|
} |
176 |
|
- |
if ( pQuery.startsWith( QUERY_SW_STATUS ) ) |
177 |
|
- |
{ |
|
152 |
+ |
if ( pQuery.startsWith( QUERY_SW_STATUS ) ) { |
178 |
153 |
|
int at = pQuery.indexOf( ')' ); |
179 |
|
- |
if ( at != -1 ) |
180 |
|
- |
{ |
|
154 |
+ |
if ( at != -1 ) { |
181 |
155 |
|
return getStatus( pRequest, pQuery.substring( QUERY_SW_STATUS.length(), at ).trim() ); |
182 |
156 |
|
} |
183 |
157 |
|
} |
|
@@ -185,8 +159,7 @@ |
185 |
159 |
|
} |
186 |
160 |
|
|
187 |
161 |
|
private TemplateControl createLoginPage( String pMessage ) |
188 |
|
- |
throws IOException |
189 |
|
- |
{ |
|
162 |
+ |
throws IOException { |
190 |
163 |
|
return new TemplateControl( getLoginReader(), "InitScript", "portalsupport/LoginScript.js", // |
191 |
164 |
|
"CSSfileRef", cachedCSSfileRef(), // |
192 |
165 |
|
"CSSclass", cachedCSSclass(), // |
|
@@ -199,36 +172,28 @@ |
199 |
172 |
|
} |
200 |
173 |
|
|
201 |
174 |
|
private TemplateControl loginRequest( HttpServletRequest pRequest, String pLoginName, String pPassword ) |
202 |
|
- |
throws IOException |
203 |
|
- |
{ |
|
175 |
+ |
throws IOException { |
204 |
176 |
|
pLoginName = Strings.noEmpty( pLoginName ); |
205 |
177 |
|
|
206 |
178 |
|
String zError = null; |
207 |
179 |
|
ClientWindowInstanceDataManager zDataManager = null; |
208 |
|
- |
try |
209 |
|
- |
{ |
|
180 |
+ |
try { |
210 |
181 |
|
ISystemUser zSystemUser = authenticate( pLoginName, pPassword ); |
211 |
|
- |
if ( zSystemUser == null ) |
212 |
|
- |
{ |
|
182 |
+ |
if ( zSystemUser == null ) { |
213 |
183 |
|
zError = "Invalid User"; |
214 |
|
- |
} |
215 |
|
- |
else |
216 |
|
- |
{ |
|
184 |
+ |
} else { |
217 |
185 |
|
zDataManager = getAuthenticationService().createNewClientWindowInstanceData( zSystemUser ); |
218 |
186 |
|
} |
219 |
187 |
|
} |
220 |
|
- |
catch ( AuthenticationException e ) |
221 |
|
- |
{ |
|
188 |
+ |
catch ( AuthenticationException e ) { |
222 |
189 |
|
zError = e.getMessage(); |
223 |
190 |
|
} |
224 |
|
- |
catch ( RuntimeException e ) |
225 |
|
- |
{ |
|
191 |
+ |
catch ( RuntimeException e ) { |
226 |
192 |
|
getLogger().error.log( e ); |
227 |
193 |
|
zError = "Authentication Issue"; |
228 |
194 |
|
} |
229 |
195 |
|
|
230 |
|
- |
if ( zError != null ) |
231 |
|
- |
{ |
|
196 |
+ |
if ( zError != null ) { |
232 |
197 |
|
return createLoginPage( zError ); |
233 |
198 |
|
} |
234 |
199 |
|
|
|
@@ -292,47 +257,36 @@ |
292 |
257 |
|
/** |
293 |
258 |
|
* Logout the current user! Should NOT Error |
294 |
259 |
|
*/ |
295 |
|
- |
protected void logout( HttpServletRequest pRequest ) |
296 |
|
- |
{ |
|
260 |
+ |
protected void logout( HttpServletRequest pRequest ) { |
297 |
261 |
|
ServerEventBusSessionMapper.dropAllServerEventBusesFor( pRequest, this, "HtmlLauncher-Logout" ); |
298 |
262 |
|
} |
299 |
263 |
|
|
300 |
|
- |
protected boolean isLoggedIn( HttpServletRequest pRequest ) |
301 |
|
- |
{ |
|
264 |
+ |
protected boolean isLoggedIn( HttpServletRequest pRequest ) { |
302 |
265 |
|
return ServerEventBusSessionMapper.anyServerEventBusesFor( pRequest, this ); |
303 |
266 |
|
} |
304 |
267 |
|
|
305 |
|
- |
private TemplateControl getStatus( HttpServletRequest pRequest, String pParameters ) |
306 |
|
- |
{ |
|
268 |
+ |
private TemplateControl getStatus( HttpServletRequest pRequest, String pParameters ) { |
307 |
269 |
|
boolean noPopup = false; |
308 |
|
- |
if ( pParameters.length() != 0 ) |
309 |
|
- |
{ |
|
270 |
+ |
if ( pParameters.length() != 0 ) { |
310 |
271 |
|
List<Integer> zAdds = new ArrayList<Integer>(); |
311 |
272 |
|
List<Integer> zDrops = new ArrayList<Integer>(); |
312 |
273 |
|
|
313 |
274 |
|
String s = pParameters + ","; |
314 |
|
- |
for ( int at; -1 != (at = s.indexOf( ',' )); s = s.substring( at + 1 ) ) |
315 |
|
- |
{ |
316 |
|
- |
if ( at > 0 ) |
317 |
|
- |
{ |
|
275 |
+ |
for ( int at; -1 != (at = s.indexOf( ',' )); s = s.substring( at + 1 ) ) { |
|
276 |
+ |
if ( at > 0 ) { |
318 |
277 |
|
String zParam = s.substring( 0, at ); |
319 |
|
- |
if ( NO_POPUP.equals( zParam ) ) |
320 |
|
- |
{ |
|
278 |
+ |
if ( NO_POPUP.equals( zParam ) ) { |
321 |
279 |
|
noPopup = true; |
322 |
280 |
|
continue; |
323 |
281 |
|
} |
324 |
|
- |
if ( at > 1 ) |
325 |
|
- |
{ |
|
282 |
+ |
if ( at > 1 ) { |
326 |
283 |
|
Integer zClientID = ClientIdCodec.decode( zParam.substring( 1 ) ); |
327 |
|
- |
if ( zClientID != null ) |
328 |
|
- |
{ |
329 |
|
- |
if ( s.charAt( 0 ) == '+' ) |
330 |
|
- |
{ |
|
284 |
+ |
if ( zClientID != null ) { |
|
285 |
+ |
if ( s.charAt( 0 ) == '+' ) { |
331 |
286 |
|
zAdds.add( zClientID ); |
332 |
287 |
|
continue; |
333 |
288 |
|
} |
334 |
|
- |
if ( s.charAt( 0 ) == '-' ) |
335 |
|
- |
{ |
|
289 |
+ |
if ( s.charAt( 0 ) == '-' ) { |
336 |
290 |
|
zDrops.add( zClientID ); |
337 |
291 |
|
continue; |
338 |
292 |
|
} |
|
@@ -342,17 +296,14 @@ |
342 |
296 |
|
return null; |
343 |
297 |
|
} |
344 |
298 |
|
|
345 |
|
- |
if ( !zDrops.isEmpty() ) |
346 |
|
- |
{ |
|
299 |
+ |
if ( !zDrops.isEmpty() ) { |
347 |
300 |
|
getLogger().debug.log( "Status Drops: ", zDrops ); |
348 |
301 |
|
} |
349 |
|
- |
if ( !zAdds.isEmpty() ) |
350 |
|
- |
{ |
|
302 |
+ |
if ( !zAdds.isEmpty() ) { |
351 |
303 |
|
getLogger().debug.log( "Status Adds: ", zAdds ); |
352 |
304 |
|
} |
353 |
305 |
|
} |
354 |
|
- |
if ( noPopup ) |
355 |
|
- |
{ |
|
306 |
+ |
if ( noPopup ) { |
356 |
307 |
|
logout( pRequest ); |
357 |
308 |
|
ServerEventBusSessionMapper.setLogoutMessage( pRequest, this, "Pop-up Blocked!" ); |
358 |
309 |
|
} |