|
@@ -1,325 +1,325 @@ |
1 |
|
- |
// This Source Code is in the Public Domain per: http://unlicense.org |
2 |
|
- |
package org.litesoft.GWT.eventbus.server; |
3 |
|
- |
|
4 |
|
- |
import org.litesoft.GWT.client.*; |
5 |
|
- |
import org.litesoft.GWT.eventbus.client.*; |
6 |
|
- |
import org.litesoft.GWT.eventbus.client.eventpackages.*; |
7 |
|
- |
import org.litesoft.GWT.eventbus.client.nonpublic.*; |
8 |
|
- |
import org.litesoft.GWT.eventbus.server.nonpublic.*; |
9 |
|
- |
import org.litesoft.*; |
10 |
|
- |
import org.litesoft.commonfoundation.typeutils.*; |
11 |
|
- |
import org.litesoft.configuration.*; |
12 |
|
- |
import org.litesoft.util.template.*; |
13 |
|
- |
|
14 |
|
- |
import javax.servlet.http.*; |
15 |
|
- |
import java.io.*; |
16 |
|
- |
import java.util.*; |
17 |
|
- |
|
18 |
|
- |
public abstract class AbstractAuthenticatingHtmlLauncherServerApp extends AbstractAuthenticatingServerApp { |
19 |
|
- |
private static final String LOGOUT_TEMPLATE_HTML = "Logout.template.html"; |
20 |
|
- |
private static final String LOGIN_TEMPLATE_HTML = "Login.template.html"; |
21 |
|
- |
private static final String PROPERTY_APP_PAGE_URL = "appPageUrl"; |
22 |
|
- |
|
23 |
|
- |
private boolean isPortalDebugMode() { |
24 |
|
- |
return Configuration.getBoolean( "PortalDebugMode", false ); |
25 |
|
- |
} |
26 |
|
- |
|
27 |
|
- |
private String getCSSfileRef() { |
28 |
|
- |
return Strings.noEmpty( Configuration.getString( "CSSfileRef" ) ); |
29 |
|
- |
} |
30 |
|
- |
|
31 |
|
- |
private String getCSSclass() { |
32 |
|
- |
String zCSSclass = Strings.noEmpty( Configuration.getString( "CSSclass" ) ); |
33 |
|
- |
return (zCSSclass != null) ? zCSSclass : "Classless"; |
34 |
|
- |
} |
35 |
|
- |
|
36 |
|
- |
protected String getTemplatePath() { |
37 |
|
- |
return ServerConfiguration.getPath( "HTMLtemplatesPath", "" ); |
38 |
|
- |
} |
39 |
|
- |
|
40 |
|
- |
protected Reader getLogoutReader() |
41 |
|
- |
throws IOException { |
42 |
|
- |
return getTemplateReader( LOGOUT_TEMPLATE_HTML ); |
43 |
|
- |
} |
44 |
|
- |
|
45 |
|
- |
protected Reader getLoginReader() |
46 |
|
- |
throws IOException { |
47 |
|
- |
return getTemplateReader( LOGIN_TEMPLATE_HTML ); |
48 |
|
- |
} |
49 |
|
- |
|
50 |
|
- |
private Reader getTemplateReader( String pTemplateID ) |
51 |
|
- |
throws IOException { |
52 |
|
- |
if ( Configuration.getString( pTemplateID, "" ).trim().length() == 0 ) { |
53 |
|
- |
String zPath = getTemplatePath(); |
54 |
|
- |
return new FileReader( new File( zPath, pTemplateID ) ); |
55 |
|
- |
} |
56 |
|
- |
String zPath = ServerConfiguration.getPath( pTemplateID, "Not Found: " + pTemplateID ).trim(); |
57 |
|
- |
return new FileReader( new File( zPath ) ); |
58 |
|
- |
} |
59 |
|
- |
|
60 |
|
- |
public static final String KEY_SERVLET_RELATIVE_REFERENCE = "ServletRelativeReference"; |
61 |
|
- |
|
62 |
|
- |
private String mServletRelativeReference; |
63 |
|
- |
private String mAppPageURL; |
64 |
|
- |
private WindowNameClientIdCodec mWindowNameClientIdCodec; |
65 |
|
- |
|
66 |
|
- |
protected AbstractAuthenticatingHtmlLauncherServerApp( String pServletRelativeReference, String pAppPageURL, IAuthenticationService pAuthenticationService, |
67 |
|
- |
AppNames pAppNames ) { |
68 |
|
- |
super( pAuthenticationService ); |
69 |
|
- |
mServletRelativeReference = pServletRelativeReference; |
70 |
|
- |
mAppPageURL = System.getProperty( PROPERTY_APP_PAGE_URL, pAppPageURL ); |
71 |
|
- |
mWindowNameClientIdCodec = new WindowNameClientIdCodec( pAppNames ); |
72 |
|
- |
} |
73 |
|
- |
|
74 |
|
- |
public void logoutRequestComplete( ServerEventBus pServerEventBus ) { |
75 |
|
- |
pServerEventBus.publishIfNotDisposed( CloseClientEventPackage.INSTANCE ); |
76 |
|
- |
} |
77 |
|
- |
|
78 |
|
- |
private String mCSSfileRef = null; |
79 |
|
- |
|
80 |
|
- |
private String cachedCSSfileRef() { |
81 |
|
- |
if ( mCSSfileRef == null ) { |
82 |
|
- |
String zRef = getCSSfileRef(); |
83 |
|
- |
|
84 |
|
- |
mCSSfileRef = (zRef == null) ? // |
85 |
|
- |
"<!-- No CSSfileRef -->" : // |
86 |
|
- |
"<link type='text/css' rel='stylesheet' href='" + zRef + "'/>"; |
87 |
|
- |
} |
88 |
|
- |
return mCSSfileRef; |
89 |
|
- |
} |
90 |
|
- |
|
91 |
|
- |
private String mCSSclass = null; |
92 |
|
- |
|
93 |
|
- |
private String cachedCSSclass() { |
94 |
|
- |
if ( mCSSclass == null ) { |
95 |
|
- |
mCSSclass = getCSSclass(); |
96 |
|
- |
} |
97 |
|
- |
return mCSSclass; |
98 |
|
- |
} |
99 |
|
- |
|
100 |
|
- |
private static final String QUERY_SW_STATUS = "Status("; |
101 |
|
- |
private static final String QUERY_SW_LOGIN_PAGE_REQUEST = "LoginPageRequest-"; |
102 |
|
- |
private static final String QUERY_SW_LOGOUT_PAGE_REQUEST = "LogoutPageRequest-"; |
103 |
|
- |
private static final String QUERY_EQ_LOGOUT = "Logout"; |
104 |
|
- |
private static final String QUERY_EQ_PORTAL_FRAME = "PortalFrame"; |
105 |
|
- |
private static final String QUERY_EQ_LOGIN = "Login"; |
106 |
|
- |
private static final String NO_POPUP = "!Popup"; |
107 |
|
- |
|
108 |
|
- |
protected TemplateControl resolveQuery( HttpServletRequest pRequest, String pQuery ) |
109 |
|
- |
throws IOException { |
110 |
|
- |
if ( QUERY_EQ_LOGOUT.equals( pQuery ) ) { |
111 |
|
- |
ServerEventBusSessionMapper.setLogoutMessage( pRequest, this, null ); |
112 |
|
- |
logout( pRequest ); |
113 |
|
- |
return createLoginPage( " " ); |
114 |
|
- |
} |
115 |
|
- |
if ( QUERY_EQ_LOGIN.equals( pQuery ) ) { |
116 |
|
- |
return loginRequest( pRequest, // |
117 |
|
- |
pRequest.getParameter( "LoginName" ), // |
118 |
|
- |
pRequest.getParameter( "Passwd" ) ); |
119 |
|
- |
} |
120 |
|
- |
if ( QUERY_EQ_PORTAL_FRAME.equals( pQuery ) ) { |
121 |
|
- |
String zHeight = "100%"; |
122 |
|
- |
String zDebugDiv = " "; |
123 |
|
- |
String zOverflow = PLUS_OVERFLOW_HIDDEN; |
124 |
|
- |
if ( isPortalDebugMode() ) { |
125 |
|
- |
zHeight = "300"; |
126 |
|
- |
zDebugDiv = "<div id='dbg'></div>"; |
127 |
|
- |
zOverflow = ""; |
128 |
|
- |
} |
129 |
|
- |
return new TemplateControl( PORTAL_PAGE, // |
130 |
|
- |
"InitScript", "portalsupport/PortalFrameScript.js", // |
131 |
|
- |
"CSSfileRef", cachedCSSfileRef(), // |
132 |
|
- |
"CSSclass", cachedCSSclass(), // |
133 |
|
- |
"BodyStyle", BODY_STYLE_LESS_OVERFLOW + zOverflow, // |
134 |
|
- |
"Version", getApplicationVersion(), // |
135 |
|
- |
"Height", zHeight, // |
136 |
|
- |
"DebugDiv", zDebugDiv, // |
137 |
|
- |
KEY_SERVLET_RELATIVE_REFERENCE, mServletRelativeReference ); |
138 |
|
- |
} |
139 |
|
- |
if ( pQuery.startsWith( QUERY_SW_LOGIN_PAGE_REQUEST ) ) { |
140 |
|
- |
String zMessage = Strings.noEmpty( ServerEventBusSessionMapper.getLogoutMessage( pRequest, this ) ); |
141 |
|
- |
return createLoginPage( (zMessage != null) ? zMessage : " " ); |
142 |
|
- |
} |
143 |
|
- |
if ( pQuery.startsWith( QUERY_SW_LOGOUT_PAGE_REQUEST ) ) { |
144 |
|
- |
return new TemplateControl( getLogoutReader(), // |
145 |
|
- |
"InitScript", "portalsupport/LogoutScript.js", // |
146 |
|
- |
"CSSfileRef", cachedCSSfileRef(), // |
147 |
|
- |
"CSSclass", cachedCSSclass(), // |
148 |
|
- |
"BodyStyle", FULL_BODY_STYLE, // |
149 |
|
- |
"Version", getApplicationVersion(), // |
150 |
|
- |
"SubmitAction", mServletRelativeReference + "?Logout" ); |
151 |
|
- |
} |
152 |
|
- |
if ( pQuery.startsWith( QUERY_SW_STATUS ) ) { |
153 |
|
- |
int at = pQuery.indexOf( ')' ); |
154 |
|
- |
if ( at != -1 ) { |
155 |
|
- |
return getStatus( pRequest, pQuery.substring( QUERY_SW_STATUS.length(), at ).trim() ); |
156 |
|
- |
} |
157 |
|
- |
} |
158 |
|
- |
return null; |
159 |
|
- |
} |
160 |
|
- |
|
161 |
|
- |
private TemplateControl createLoginPage( String pMessage ) |
162 |
|
- |
throws IOException { |
163 |
|
- |
return new TemplateControl( getLoginReader(), "InitScript", "portalsupport/LoginScript.js", // |
164 |
|
- |
"CSSfileRef", cachedCSSfileRef(), // |
165 |
|
- |
"CSSclass", cachedCSSclass(), // |
166 |
|
- |
"BodyStyle", FULL_BODY_STYLE, // |
167 |
|
- |
"Version", getApplicationVersion(), // |
168 |
|
- |
"SubmitAction", mServletRelativeReference + "?Login", // |
169 |
|
- |
"LoginName", "LoginName", // |
170 |
|
- |
"Password", "Passwd", // |
171 |
|
- |
"Message", (pMessage != null) ? pMessage : " " ); |
172 |
|
- |
} |
173 |
|
- |
|
174 |
|
- |
private TemplateControl loginRequest( HttpServletRequest pRequest, String pLoginName, String pPassword ) |
175 |
|
- |
throws IOException { |
176 |
|
- |
pLoginName = Strings.noEmpty( pLoginName ); |
177 |
|
- |
|
178 |
|
- |
String zError = null; |
179 |
|
- |
ClientWindowInstanceDataManager zDataManager = null; |
180 |
|
- |
try { |
181 |
|
- |
ISystemUser zSystemUser = authenticate( pLoginName, pPassword ); |
182 |
|
- |
if ( zSystemUser == null ) { |
183 |
|
- |
zError = "Invalid User"; |
184 |
|
- |
} else { |
185 |
|
- |
zDataManager = getAuthenticationService().createNewClientWindowInstanceData( zSystemUser ); |
186 |
|
- |
} |
187 |
|
- |
} |
188 |
|
- |
catch ( AuthenticationException e ) { |
189 |
|
- |
zError = e.getMessage(); |
190 |
|
- |
} |
191 |
|
- |
catch ( RuntimeException e ) { |
192 |
|
- |
getLogger().error.log( e ); |
193 |
|
- |
zError = "Authentication Issue"; |
194 |
|
- |
} |
195 |
|
- |
|
196 |
|
- |
if ( zError != null ) { |
197 |
|
- |
return createLoginPage( zError ); |
198 |
|
- |
} |
199 |
|
- |
|
200 |
|
- |
ServerEventBus zTempSEB = createTemporarySEB( "portal LoginRequest", pRequest, zDataManager ); |
201 |
|
- |
|
202 |
|
- |
int zClientIdNumber = zTempSEB.getClientIdNumber(); |
203 |
|
- |
String zNewEncodedClientId = ClientIdCodec.encode( zClientIdNumber ); |
204 |
|
- |
String windowName = mWindowNameClientIdCodec.createWindowName( zNewEncodedClientId ); |
205 |
|
- |
|
206 |
|
- |
return new TemplateControl( LA_PAGE, // |
207 |
|
- |
"CSSfileRef", cachedCSSfileRef(), // |
208 |
|
- |
"CSSclass", cachedCSSclass(), // |
209 |
|
- |
"BodyStyle", FULL_BODY_STYLE, // |
210 |
|
- |
"Version", getApplicationVersion(), // |
211 |
|
- |
"URL", mAppPageURL, // |
212 |
|
- |
"WinName", windowName, // |
213 |
|
- |
"LaunchAppParams", "directories=0," + // |
214 |
|
- |
"location=0," + // |
215 |
|
- |
"menubar=0," + // |
216 |
|
- |
"scrollbars=0," + // |
217 |
|
- |
"status=1," + // |
218 |
|
- |
"toolbar=0," + // |
219 |
|
- |
// "hotkeys=0" + // Netscape!, FireFox?, IE? |
220 |
|
- |
// "screenX=nnnn,screenY=nnnn," + // Netscape!, FireFox?, |
221 |
|
- |
// IE? |
222 |
|
- |
// width=100,height=100," + |
223 |
|
- |
"resizable=1" ); |
224 |
|
- |
} |
225 |
|
- |
|
226 |
|
- |
// Login (from HTML page): |
227 |
|
- |
// Client: |
228 |
|
- |
// launchApp |
229 |
|
- |
// shouldShow:Logout | was:Login |
230 |
|
- |
// requesting:ServerApp?LogoutPageRequest-0.08359760784499176 |
231 |
|
- |
// showing:Logout |
232 |
|
- |
// ClientOpen:1 |
233 |
|
- |
// requesting:ServerApp?ClientOpen:1-0.8351432026643422 |
234 |
|
- |
// shouldShow:Login | was:Logout |
235 |
|
- |
// requesting:ServerApp?LoginPageRequest-0.530483180532334 |
236 |
|
- |
// showing:Login |
237 |
|
- |
// |
238 |
|
- |
// Server: |
239 |
|
- |
// service: Login |
240 |
|
- |
// service: LogoutPageRequest-0.08359760784499176 |
241 |
|
- |
// 2008-02-22 12:56:11.265 | Application Client Start Up |
242 |
|
- |
// [INFO] org.litesoft.GWT.eventbus.server.AbstractServerApp - initialize Page Request, existing: 1 -> 1 |
243 |
|
- |
// 2008-02-22 12:56:28.562 | Client AppInitialization |
244 |
|
- |
// service: ClientOpen:1-0.8351432026643422 |
245 |
|
- |
// 2008-02-22 12:56:28.750 | Client AppReady |
246 |
|
- |
|
247 |
|
- |
// App Window Close: |
248 |
|
- |
// Client: |
249 |
|
- |
// ClientClose:1 |
250 |
|
- |
// requesting:ServerApp?ClientClose:1-0.49865901930227324 |
251 |
|
- |
// shouldShow:Login |
252 |
|
- |
// |
253 |
|
- |
// Server: |
254 |
|
- |
// service: ClientClose:1-0.49865901930227324 |
255 |
|
- |
// [INFO] org.litesoft.GWT.eventbus.server.AbstractServerApp - ClientDead: 1 |
256 |
|
- |
|
257 |
|
- |
/** |
258 |
|
- |
* Logout the current user! Should NOT Error |
259 |
|
- |
*/ |
260 |
|
- |
protected void logout( HttpServletRequest pRequest ) { |
261 |
|
- |
ServerEventBusSessionMapper.dropAllServerEventBusesFor( pRequest, this, "HtmlLauncher-Logout" ); |
262 |
|
- |
} |
263 |
|
- |
|
264 |
|
- |
protected boolean isLoggedIn( HttpServletRequest pRequest ) { |
265 |
|
- |
return ServerEventBusSessionMapper.anyServerEventBusesFor( pRequest, this ); |
266 |
|
- |
} |
267 |
|
- |
|
268 |
|
- |
private TemplateControl getStatus( HttpServletRequest pRequest, String pParameters ) { |
269 |
|
- |
boolean noPopup = false; |
270 |
|
- |
if ( pParameters.length() != 0 ) { |
271 |
|
- |
List<Integer> zAdds = new ArrayList<Integer>(); |
272 |
|
- |
List<Integer> zDrops = new ArrayList<Integer>(); |
273 |
|
- |
|
274 |
|
- |
String s = pParameters + ","; |
275 |
|
- |
for ( int at; -1 != (at = s.indexOf( ',' )); s = s.substring( at + 1 ) ) { |
276 |
|
- |
if ( at > 0 ) { |
277 |
|
- |
String zParam = s.substring( 0, at ); |
278 |
|
- |
if ( NO_POPUP.equals( zParam ) ) { |
279 |
|
- |
noPopup = true; |
280 |
|
- |
continue; |
281 |
|
- |
} |
282 |
|
- |
if ( at > 1 ) { |
283 |
|
- |
Integer zClientID = ClientIdCodec.decode( zParam.substring( 1 ) ); |
284 |
|
- |
if ( zClientID != null ) { |
285 |
|
- |
if ( s.charAt( 0 ) == '+' ) { |
286 |
|
- |
zAdds.add( zClientID ); |
287 |
|
- |
continue; |
288 |
|
- |
} |
289 |
|
- |
if ( s.charAt( 0 ) == '-' ) { |
290 |
|
- |
zDrops.add( zClientID ); |
291 |
|
- |
continue; |
292 |
|
- |
} |
293 |
|
- |
} |
294 |
|
- |
} |
295 |
|
- |
} |
296 |
|
- |
return null; |
297 |
|
- |
} |
298 |
|
- |
|
299 |
|
- |
if ( !zDrops.isEmpty() ) { |
300 |
|
- |
getLogger().debug.log( "Status Drops: ", zDrops ); |
301 |
|
- |
} |
302 |
|
- |
if ( !zAdds.isEmpty() ) { |
303 |
|
- |
getLogger().debug.log( "Status Adds: ", zAdds ); |
304 |
|
- |
} |
305 |
|
- |
} |
306 |
|
- |
if ( noPopup ) { |
307 |
|
- |
logout( pRequest ); |
308 |
|
- |
ServerEventBusSessionMapper.setLogoutMessage( pRequest, this, "Pop-up Blocked!" ); |
309 |
|
- |
} |
310 |
|
- |
boolean zLoggedIn = isLoggedIn( pRequest ); |
311 |
|
- |
String zLL = zLoggedIn ? QUERY_EQ_LOGOUT : QUERY_EQ_LOGIN; |
312 |
|
- |
return new TemplateControl( new StringReader( "shouldShow" + zLL + "();" ), new String[0] ); |
313 |
|
- |
} |
314 |
|
- |
|
315 |
|
- |
private static final String LA_PAGE = |
316 |
|
- |
"<html><head><title>Launch App</title>%.CSSfileRef.%</head>" + "<body class='%.CSSclass.%' style='%.BodyStyle.%'>Launch App...<script>\n" + |
317 |
|
- |
"try{window.parent.launchApp( '%.URL.%', '%.WinName.%', '%.LaunchAppParams.%' );}\n" + |
318 |
|
- |
"catch ( e ){alert( 'Unable to Launch App:\\nvs\\n%.Version.%\\n\\n' + e );}\n" + "</script></body></html>"; |
319 |
|
- |
|
320 |
|
- |
private static final String PORTAL_PAGE = |
321 |
|
- |
"<html><head><title>Portal Frame</title>%.CSSfileRef.%</head><body class='%.CSSclass.%' style='%.BodyStyle.%'>\n" + |
322 |
|
- |
"<iframe id='LLframe' src='portalsupport/EmptyPage.html' style='%.BodyStyle.%' width='100%' height='%.Height.%' allowTransparency='true'></iframe>" + |
323 |
|
- |
"<div id='Version'>%.Version.%</div>%.DebugDiv.%<script type='text/javascript' src='%.InitScript.%'></script>\n" + |
324 |
|
- |
"<script>initPage( '%.ServletRelativeReference.%' );</script></body></html>"; |
325 |
|
- |
} |
|
1 |
+ |
// This Source Code is in the Public Domain per: http://unlicense.org |
|
2 |
+ |
package org.litesoft.GWT.eventbus.server; |
|
3 |
+ |
|
|
4 |
+ |
import org.litesoft.GWT.client.*; |
|
5 |
+ |
import org.litesoft.GWT.eventbus.client.*; |
|
6 |
+ |
import org.litesoft.GWT.eventbus.client.eventpackages.*; |
|
7 |
+ |
import org.litesoft.GWT.eventbus.client.nonpublic.*; |
|
8 |
+ |
import org.litesoft.GWT.eventbus.server.nonpublic.*; |
|
9 |
+ |
import org.litesoft.*; |
|
10 |
+ |
import org.litesoft.commonfoundation.base.*; |
|
11 |
+ |
import org.litesoft.configuration.*; |
|
12 |
+ |
import org.litesoft.util.template.*; |
|
13 |
+ |
|
|
14 |
+ |
import javax.servlet.http.*; |
|
15 |
+ |
import java.io.*; |
|
16 |
+ |
import java.util.*; |
|
17 |
+ |
|
|
18 |
+ |
public abstract class AbstractAuthenticatingHtmlLauncherServerApp extends AbstractAuthenticatingServerApp { |
|
19 |
+ |
private static final String LOGOUT_TEMPLATE_HTML = "Logout.template.html"; |
|
20 |
+ |
private static final String LOGIN_TEMPLATE_HTML = "Login.template.html"; |
|
21 |
+ |
private static final String PROPERTY_APP_PAGE_URL = "appPageUrl"; |
|
22 |
+ |
|
|
23 |
+ |
private boolean isPortalDebugMode() { |
|
24 |
+ |
return Configuration.getBoolean( "PortalDebugMode", false ); |
|
25 |
+ |
} |
|
26 |
+ |
|
|
27 |
+ |
private String getCSSfileRef() { |
|
28 |
+ |
return ConstrainTo.significantOrNull( Configuration.getString( "CSSfileRef" ) ); |
|
29 |
+ |
} |
|
30 |
+ |
|
|
31 |
+ |
private String getCSSclass() { |
|
32 |
+ |
String zCSSclass = ConstrainTo.significantOrNull( Configuration.getString( "CSSclass" ) ); |
|
33 |
+ |
return (zCSSclass != null) ? zCSSclass : "Classless"; |
|
34 |
+ |
} |
|
35 |
+ |
|
|
36 |
+ |
protected String getTemplatePath() { |
|
37 |
+ |
return ServerConfiguration.getPath( "HTMLtemplatesPath", "" ); |
|
38 |
+ |
} |
|
39 |
+ |
|
|
40 |
+ |
protected Reader getLogoutReader() |
|
41 |
+ |
throws IOException { |
|
42 |
+ |
return getTemplateReader( LOGOUT_TEMPLATE_HTML ); |
|
43 |
+ |
} |
|
44 |
+ |
|
|
45 |
+ |
protected Reader getLoginReader() |
|
46 |
+ |
throws IOException { |
|
47 |
+ |
return getTemplateReader( LOGIN_TEMPLATE_HTML ); |
|
48 |
+ |
} |
|
49 |
+ |
|
|
50 |
+ |
private Reader getTemplateReader( String pTemplateID ) |
|
51 |
+ |
throws IOException { |
|
52 |
+ |
if ( Configuration.getString( pTemplateID, "" ).trim().length() == 0 ) { |
|
53 |
+ |
String zPath = getTemplatePath(); |
|
54 |
+ |
return new FileReader( new File( zPath, pTemplateID ) ); |
|
55 |
+ |
} |
|
56 |
+ |
String zPath = ServerConfiguration.getPath( pTemplateID, "Not Found: " + pTemplateID ).trim(); |
|
57 |
+ |
return new FileReader( new File( zPath ) ); |
|
58 |
+ |
} |
|
59 |
+ |
|
|
60 |
+ |
public static final String KEY_SERVLET_RELATIVE_REFERENCE = "ServletRelativeReference"; |
|
61 |
+ |
|
|
62 |
+ |
private String mServletRelativeReference; |
|
63 |
+ |
private String mAppPageURL; |
|
64 |
+ |
private WindowNameClientIdCodec mWindowNameClientIdCodec; |
|
65 |
+ |
|
|
66 |
+ |
protected AbstractAuthenticatingHtmlLauncherServerApp( String pServletRelativeReference, String pAppPageURL, IAuthenticationService pAuthenticationService, |
|
67 |
+ |
AppNames pAppNames ) { |
|
68 |
+ |
super( pAuthenticationService ); |
|
69 |
+ |
mServletRelativeReference = pServletRelativeReference; |
|
70 |
+ |
mAppPageURL = System.getProperty( PROPERTY_APP_PAGE_URL, pAppPageURL ); |
|
71 |
+ |
mWindowNameClientIdCodec = new WindowNameClientIdCodec( pAppNames ); |
|
72 |
+ |
} |
|
73 |
+ |
|
|
74 |
+ |
public void logoutRequestComplete( ServerEventBus pServerEventBus ) { |
|
75 |
+ |
pServerEventBus.publishIfNotDisposed( CloseClientEventPackage.INSTANCE ); |
|
76 |
+ |
} |
|
77 |
+ |
|
|
78 |
+ |
private String mCSSfileRef = null; |
|
79 |
+ |
|
|
80 |
+ |
private String cachedCSSfileRef() { |
|
81 |
+ |
if ( mCSSfileRef == null ) { |
|
82 |
+ |
String zRef = getCSSfileRef(); |
|
83 |
+ |
|
|
84 |
+ |
mCSSfileRef = (zRef == null) ? // |
|
85 |
+ |
"<!-- No CSSfileRef -->" : // |
|
86 |
+ |
"<link type='text/css' rel='stylesheet' href='" + zRef + "'/>"; |
|
87 |
+ |
} |
|
88 |
+ |
return mCSSfileRef; |
|
89 |
+ |
} |
|
90 |
+ |
|
|
91 |
+ |
private String mCSSclass = null; |
|
92 |
+ |
|
|
93 |
+ |
private String cachedCSSclass() { |
|
94 |
+ |
if ( mCSSclass == null ) { |
|
95 |
+ |
mCSSclass = getCSSclass(); |
|
96 |
+ |
} |
|
97 |
+ |
return mCSSclass; |
|
98 |
+ |
} |
|
99 |
+ |
|
|
100 |
+ |
private static final String QUERY_SW_STATUS = "Status("; |
|
101 |
+ |
private static final String QUERY_SW_LOGIN_PAGE_REQUEST = "LoginPageRequest-"; |
|
102 |
+ |
private static final String QUERY_SW_LOGOUT_PAGE_REQUEST = "LogoutPageRequest-"; |
|
103 |
+ |
private static final String QUERY_EQ_LOGOUT = "Logout"; |
|
104 |
+ |
private static final String QUERY_EQ_PORTAL_FRAME = "PortalFrame"; |
|
105 |
+ |
private static final String QUERY_EQ_LOGIN = "Login"; |
|
106 |
+ |
private static final String NO_POPUP = "!Popup"; |
|
107 |
+ |
|
|
108 |
+ |
protected TemplateControl resolveQuery( HttpServletRequest pRequest, String pQuery ) |
|
109 |
+ |
throws IOException { |
|
110 |
+ |
if ( QUERY_EQ_LOGOUT.equals( pQuery ) ) { |
|
111 |
+ |
ServerEventBusSessionMapper.setLogoutMessage( pRequest, this, null ); |
|
112 |
+ |
logout( pRequest ); |
|
113 |
+ |
return createLoginPage( " " ); |
|
114 |
+ |
} |
|
115 |
+ |
if ( QUERY_EQ_LOGIN.equals( pQuery ) ) { |
|
116 |
+ |
return loginRequest( pRequest, // |
|
117 |
+ |
pRequest.getParameter( "LoginName" ), // |
|
118 |
+ |
pRequest.getParameter( "Passwd" ) ); |
|
119 |
+ |
} |
|
120 |
+ |
if ( QUERY_EQ_PORTAL_FRAME.equals( pQuery ) ) { |
|
121 |
+ |
String zHeight = "100%"; |
|
122 |
+ |
String zDebugDiv = " "; |
|
123 |
+ |
String zOverflow = PLUS_OVERFLOW_HIDDEN; |
|
124 |
+ |
if ( isPortalDebugMode() ) { |
|
125 |
+ |
zHeight = "300"; |
|
126 |
+ |
zDebugDiv = "<div id='dbg'></div>"; |
|
127 |
+ |
zOverflow = ""; |
|
128 |
+ |
} |
|
129 |
+ |
return new TemplateControl( PORTAL_PAGE, // |
|
130 |
+ |
"InitScript", "portalsupport/PortalFrameScript.js", // |
|
131 |
+ |
"CSSfileRef", cachedCSSfileRef(), // |
|
132 |
+ |
"CSSclass", cachedCSSclass(), // |
|
133 |
+ |
"BodyStyle", BODY_STYLE_LESS_OVERFLOW + zOverflow, // |
|
134 |
+ |
"Version", getApplicationVersion(), // |
|
135 |
+ |
"Height", zHeight, // |
|
136 |
+ |
"DebugDiv", zDebugDiv, // |
|
137 |
+ |
KEY_SERVLET_RELATIVE_REFERENCE, mServletRelativeReference ); |
|
138 |
+ |
} |
|
139 |
+ |
if ( pQuery.startsWith( QUERY_SW_LOGIN_PAGE_REQUEST ) ) { |
|
140 |
+ |
String zMessage = ConstrainTo.significantOrNull( ServerEventBusSessionMapper.getLogoutMessage( pRequest, this ) ); |
|
141 |
+ |
return createLoginPage( (zMessage != null) ? zMessage : " " ); |
|
142 |
+ |
} |
|
143 |
+ |
if ( pQuery.startsWith( QUERY_SW_LOGOUT_PAGE_REQUEST ) ) { |
|
144 |
+ |
return new TemplateControl( getLogoutReader(), // |
|
145 |
+ |
"InitScript", "portalsupport/LogoutScript.js", // |
|
146 |
+ |
"CSSfileRef", cachedCSSfileRef(), // |
|
147 |
+ |
"CSSclass", cachedCSSclass(), // |
|
148 |
+ |
"BodyStyle", FULL_BODY_STYLE, // |
|
149 |
+ |
"Version", getApplicationVersion(), // |
|
150 |
+ |
"SubmitAction", mServletRelativeReference + "?Logout" ); |
|
151 |
+ |
} |
|
152 |
+ |
if ( pQuery.startsWith( QUERY_SW_STATUS ) ) { |
|
153 |
+ |
int at = pQuery.indexOf( ')' ); |
|
154 |
+ |
if ( at != -1 ) { |
|
155 |
+ |
return getStatus( pRequest, pQuery.substring( QUERY_SW_STATUS.length(), at ).trim() ); |
|
156 |
+ |
} |
|
157 |
+ |
} |
|
158 |
+ |
return null; |
|
159 |
+ |
} |
|
160 |
+ |
|
|
161 |
+ |
private TemplateControl createLoginPage( String pMessage ) |
|
162 |
+ |
throws IOException { |
|
163 |
+ |
return new TemplateControl( getLoginReader(), "InitScript", "portalsupport/LoginScript.js", // |
|
164 |
+ |
"CSSfileRef", cachedCSSfileRef(), // |
|
165 |
+ |
"CSSclass", cachedCSSclass(), // |
|
166 |
+ |
"BodyStyle", FULL_BODY_STYLE, // |
|
167 |
+ |
"Version", getApplicationVersion(), // |
|
168 |
+ |
"SubmitAction", mServletRelativeReference + "?Login", // |
|
169 |
+ |
"LoginName", "LoginName", // |
|
170 |
+ |
"Password", "Passwd", // |
|
171 |
+ |
"Message", (pMessage != null) ? pMessage : " " ); |
|
172 |
+ |
} |
|
173 |
+ |
|
|
174 |
+ |
private TemplateControl loginRequest( HttpServletRequest pRequest, String pLoginName, String pPassword ) |
|
175 |
+ |
throws IOException { |
|
176 |
+ |
pLoginName = ConstrainTo.significantOrNull( pLoginName ); |
|
177 |
+ |
|
|
178 |
+ |
String zError = null; |
|
179 |
+ |
ClientWindowInstanceDataManager zDataManager = null; |
|
180 |
+ |
try { |
|
181 |
+ |
ISystemUser zSystemUser = authenticate( pLoginName, pPassword ); |
|
182 |
+ |
if ( zSystemUser == null ) { |
|
183 |
+ |
zError = "Invalid User"; |
|
184 |
+ |
} else { |
|
185 |
+ |
zDataManager = getAuthenticationService().createNewClientWindowInstanceData( zSystemUser ); |
|
186 |
+ |
} |
|
187 |
+ |
} |
|
188 |
+ |
catch ( AuthenticationException e ) { |
|
189 |
+ |
zError = e.getMessage(); |
|
190 |
+ |
} |
|
191 |
+ |
catch ( RuntimeException e ) { |
|
192 |
+ |
getLogger().error.log( e ); |
|
193 |
+ |
zError = "Authentication Issue"; |
|
194 |
+ |
} |
|
195 |
+ |
|
|
196 |
+ |
if ( zError != null ) { |
|
197 |
+ |
return createLoginPage( zError ); |
|
198 |
+ |
} |
|
199 |
+ |
|
|
200 |
+ |
ServerEventBus zTempSEB = createTemporarySEB( "portal LoginRequest", pRequest, zDataManager ); |
|
201 |
+ |
|
|
202 |
+ |
int zClientIdNumber = zTempSEB.getClientIdNumber(); |
|
203 |
+ |
String zNewEncodedClientId = ClientIdCodec.encode( zClientIdNumber ); |
|
204 |
+ |
String windowName = mWindowNameClientIdCodec.createWindowName( zNewEncodedClientId ); |
|
205 |
+ |
|
|
206 |
+ |
return new TemplateControl( LA_PAGE, // |
|
207 |
+ |
"CSSfileRef", cachedCSSfileRef(), // |
|
208 |
+ |
"CSSclass", cachedCSSclass(), // |
|
209 |
+ |
"BodyStyle", FULL_BODY_STYLE, // |
|
210 |
+ |
"Version", getApplicationVersion(), // |
|
211 |
+ |
"URL", mAppPageURL, // |
|
212 |
+ |
"WinName", windowName, // |
|
213 |
+ |
"LaunchAppParams", "directories=0," + // |
|
214 |
+ |
"location=0," + // |
|
215 |
+ |
"menubar=0," + // |
|
216 |
+ |
"scrollbars=0," + // |
|
217 |
+ |
"status=1," + // |
|
218 |
+ |
"toolbar=0," + // |
|
219 |
+ |
// "hotkeys=0" + // Netscape!, FireFox?, IE? |
|
220 |
+ |
// "screenX=nnnn,screenY=nnnn," + // Netscape!, FireFox?, |
|
221 |
+ |
// IE? |
|
222 |
+ |
// width=100,height=100," + |
|
223 |
+ |
"resizable=1" ); |
|
224 |
+ |
} |
|
225 |
+ |
|
|
226 |
+ |
// Login (from HTML page): |
|
227 |
+ |
// Client: |
|
228 |
+ |
// launchApp |
|
229 |
+ |
// shouldShow:Logout | was:Login |
|
230 |
+ |
// requesting:ServerApp?LogoutPageRequest-0.08359760784499176 |
|
231 |
+ |
// showing:Logout |
|
232 |
+ |
// ClientOpen:1 |
|
233 |
+ |
// requesting:ServerApp?ClientOpen:1-0.8351432026643422 |
|
234 |
+ |
// shouldShow:Login | was:Logout |
|
235 |
+ |
// requesting:ServerApp?LoginPageRequest-0.530483180532334 |
|
236 |
+ |
// showing:Login |
|
237 |
+ |
// |
|
238 |
+ |
// Server: |
|
239 |
+ |
// service: Login |
|
240 |
+ |
// service: LogoutPageRequest-0.08359760784499176 |
|
241 |
+ |
// 2008-02-22 12:56:11.265 | Application Client Start Up |
|
242 |
+ |
// [INFO] org.litesoft.GWT.eventbus.server.AbstractServerApp - initialize Page Request, existing: 1 -> 1 |
|
243 |
+ |
// 2008-02-22 12:56:28.562 | Client AppInitialization |
|
244 |
+ |
// service: ClientOpen:1-0.8351432026643422 |
|
245 |
+ |
// 2008-02-22 12:56:28.750 | Client AppReady |
|
246 |
+ |
|
|
247 |
+ |
// App Window Close: |
|
248 |
+ |
// Client: |
|
249 |
+ |
// ClientClose:1 |
|
250 |
+ |
// requesting:ServerApp?ClientClose:1-0.49865901930227324 |
|
251 |
+ |
// shouldShow:Login |
|
252 |
+ |
// |
|
253 |
+ |
// Server: |
|
254 |
+ |
// service: ClientClose:1-0.49865901930227324 |
|
255 |
+ |
// [INFO] org.litesoft.GWT.eventbus.server.AbstractServerApp - ClientDead: 1 |
|
256 |
+ |
|
|
257 |
+ |
/** |
|
258 |
+ |
* Logout the current user! Should NOT Error |
|
259 |
+ |
*/ |
|
260 |
+ |
protected void logout( HttpServletRequest pRequest ) { |
|
261 |
+ |
ServerEventBusSessionMapper.dropAllServerEventBusesFor( pRequest, this, "HtmlLauncher-Logout" ); |
|
262 |
+ |
} |
|
263 |
+ |
|
|
264 |
+ |
protected boolean isLoggedIn( HttpServletRequest pRequest ) { |
|
265 |
+ |
return ServerEventBusSessionMapper.anyServerEventBusesFor( pRequest, this ); |
|
266 |
+ |
} |
|
267 |
+ |
|
|
268 |
+ |
private TemplateControl getStatus( HttpServletRequest pRequest, String pParameters ) { |
|
269 |
+ |
boolean noPopup = false; |
|
270 |
+ |
if ( pParameters.length() != 0 ) { |
|
271 |
+ |
List<Integer> zAdds = new ArrayList<Integer>(); |
|
272 |
+ |
List<Integer> zDrops = new ArrayList<Integer>(); |
|
273 |
+ |
|
|
274 |
+ |
String s = pParameters + ","; |
|
275 |
+ |
for ( int at; -1 != (at = s.indexOf( ',' )); s = s.substring( at + 1 ) ) { |
|
276 |
+ |
if ( at > 0 ) { |
|
277 |
+ |
String zParam = s.substring( 0, at ); |
|
278 |
+ |
if ( NO_POPUP.equals( zParam ) ) { |
|
279 |
+ |
noPopup = true; |
|
280 |
+ |
continue; |
|
281 |
+ |
} |
|
282 |
+ |
if ( at > 1 ) { |
|
283 |
+ |
Integer zClientID = ClientIdCodec.decode( zParam.substring( 1 ) ); |
|
284 |
+ |
if ( zClientID != null ) { |
|
285 |
+ |
if ( s.charAt( 0 ) == '+' ) { |
|
286 |
+ |
zAdds.add( zClientID ); |
|
287 |
+ |
continue; |
|
288 |
+ |
} |
|
289 |
+ |
if ( s.charAt( 0 ) == '-' ) { |
|
290 |
+ |
zDrops.add( zClientID ); |
|
291 |
+ |
continue; |
|
292 |
+ |
} |
|
293 |
+ |
} |
|
294 |
+ |
} |
|
295 |
+ |
} |
|
296 |
+ |
return null; |
|
297 |
+ |
} |
|
298 |
+ |
|
|
299 |
+ |
if ( !zDrops.isEmpty() ) { |
|
300 |
+ |
getLogger().debug.log( "Status Drops: ", zDrops ); |
|
301 |
+ |
} |
|
302 |
+ |
if ( !zAdds.isEmpty() ) { |
|
303 |
+ |
getLogger().debug.log( "Status Adds: ", zAdds ); |
|
304 |
+ |
} |
|
305 |
+ |
} |
|
306 |
+ |
if ( noPopup ) { |
|
307 |
+ |
logout( pRequest ); |
|
308 |
+ |
ServerEventBusSessionMapper.setLogoutMessage( pRequest, this, "Pop-up Blocked!" ); |
|
309 |
+ |
} |
|
310 |
+ |
boolean zLoggedIn = isLoggedIn( pRequest ); |
|
311 |
+ |
String zLL = zLoggedIn ? QUERY_EQ_LOGOUT : QUERY_EQ_LOGIN; |
|
312 |
+ |
return new TemplateControl( new StringReader( "shouldShow" + zLL + "();" ), new String[0] ); |
|
313 |
+ |
} |
|
314 |
+ |
|
|
315 |
+ |
private static final String LA_PAGE = |
|
316 |
+ |
"<html><head><title>Launch App</title>%.CSSfileRef.%</head>" + "<body class='%.CSSclass.%' style='%.BodyStyle.%'>Launch App...<script>\n" + |
|
317 |
+ |
"try{window.parent.launchApp( '%.URL.%', '%.WinName.%', '%.LaunchAppParams.%' );}\n" + |
|
318 |
+ |
"catch ( e ){alert( 'Unable to Launch App:\\nvs\\n%.Version.%\\n\\n' + e );}\n" + "</script></body></html>"; |
|
319 |
+ |
|
|
320 |
+ |
private static final String PORTAL_PAGE = |
|
321 |
+ |
"<html><head><title>Portal Frame</title>%.CSSfileRef.%</head><body class='%.CSSclass.%' style='%.BodyStyle.%'>\n" + |
|
322 |
+ |
"<iframe id='LLframe' src='portalsupport/EmptyPage.html' style='%.BodyStyle.%' width='100%' height='%.Height.%' allowTransparency='true'></iframe>" + |
|
323 |
+ |
"<div id='Version'>%.Version.%</div>%.DebugDiv.%<script type='text/javascript' src='%.InitScript.%'></script>\n" + |
|
324 |
+ |
"<script>initPage( '%.ServletRelativeReference.%' );</script></body></html>"; |
|
325 |
+ |
} |