Subversion Repository Public Repository

litesoft

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
// This Source Code is in the Public Domain per: http://unlicense.org
package org.litesoft.GWT.eventbus.server;

import org.litesoft.GWT.client.*;
import org.litesoft.GWT.eventbus.client.*;
import org.litesoft.GWT.eventbus.client.eventpackages.*;
import org.litesoft.GWT.eventbus.client.nonpublic.*;
import org.litesoft.GWT.eventbus.server.nonpublic.*;
import org.litesoft.*;
import org.litesoft.commonfoundation.base.*;
import org.litesoft.configuration.*;
import org.litesoft.util.template.*;

import javax.servlet.http.*;
import java.io.*;
import java.util.*;

public abstract class AbstractAuthenticatingHtmlLauncherServerApp extends AbstractAuthenticatingServerApp {
    private static final String LOGOUT_TEMPLATE_HTML = "Logout.template.html";
    private static final String LOGIN_TEMPLATE_HTML = "Login.template.html";
    private static final String PROPERTY_APP_PAGE_URL = "appPageUrl";

    private boolean isPortalDebugMode() {
        return Configuration.getBoolean( "PortalDebugMode", false );
    }

    private String getCSSfileRef() {
        return ConstrainTo.significantOrNull( Configuration.getString( "CSSfileRef" ) );
    }

    private String getCSSclass() {
        String zCSSclass = ConstrainTo.significantOrNull( Configuration.getString( "CSSclass" ) );
        return (zCSSclass != null) ? zCSSclass : "Classless";
    }

    protected String getTemplatePath() {
        return ServerConfiguration.getPath( "HTMLtemplatesPath", "" );
    }

    protected Reader getLogoutReader()
            throws IOException {
        return getTemplateReader( LOGOUT_TEMPLATE_HTML );
    }

    protected Reader getLoginReader()
            throws IOException {
        return getTemplateReader( LOGIN_TEMPLATE_HTML );
    }

    private Reader getTemplateReader( String pTemplateID )
            throws IOException {
        if ( Configuration.getString( pTemplateID, "" ).trim().length() == 0 ) {
            String zPath = getTemplatePath();
            return new FileReader( new File( zPath, pTemplateID ) );
        }
        String zPath = ServerConfiguration.getPath( pTemplateID, "Not Found: " + pTemplateID ).trim();
        return new FileReader( new File( zPath ) );
    }

    public static final String KEY_SERVLET_RELATIVE_REFERENCE = "ServletRelativeReference";

    private String mServletRelativeReference;
    private String mAppPageURL;
    private WindowNameClientIdCodec mWindowNameClientIdCodec;

    protected AbstractAuthenticatingHtmlLauncherServerApp( String pServletRelativeReference, String pAppPageURL, IAuthenticationService pAuthenticationService,
                                                           AppNames pAppNames ) {
        super( pAuthenticationService );
        mServletRelativeReference = pServletRelativeReference;
        mAppPageURL = System.getProperty( PROPERTY_APP_PAGE_URL, pAppPageURL );
        mWindowNameClientIdCodec = new WindowNameClientIdCodec( pAppNames );
    }

    public void logoutRequestComplete( ServerEventBus pServerEventBus ) {
        pServerEventBus.publishIfNotDisposed( CloseClientEventPackage.INSTANCE );
    }

    private String mCSSfileRef = null;

    private String cachedCSSfileRef() {
        if ( mCSSfileRef == null ) {
            String zRef = getCSSfileRef();

            mCSSfileRef = (zRef == null) ? //
                          "<!-- No CSSfileRef -->" : //
                          "<link type='text/css' rel='stylesheet' href='" + zRef + "'/>";
        }
        return mCSSfileRef;
    }

    private String mCSSclass = null;

    private String cachedCSSclass() {
        if ( mCSSclass == null ) {
            mCSSclass = getCSSclass();
        }
        return mCSSclass;
    }

    private static final String QUERY_SW_STATUS = "Status(";
    private static final String QUERY_SW_LOGIN_PAGE_REQUEST = "LoginPageRequest-";
    private static final String QUERY_SW_LOGOUT_PAGE_REQUEST = "LogoutPageRequest-";
    private static final String QUERY_EQ_LOGOUT = "Logout";
    private static final String QUERY_EQ_PORTAL_FRAME = "PortalFrame";
    private static final String QUERY_EQ_LOGIN = "Login";
    private static final String NO_POPUP = "!Popup";

    protected TemplateControl resolveQuery( HttpServletRequest pRequest, String pQuery )
            throws IOException {
        if ( QUERY_EQ_LOGOUT.equals( pQuery ) ) {
            ServerEventBusSessionMapper.setLogoutMessage( pRequest, this, null );
            logout( pRequest );
            return createLoginPage( "&nbsp;" );
        }
        if ( QUERY_EQ_LOGIN.equals( pQuery ) ) {
            return loginRequest( pRequest, //
                                 pRequest.getParameter( "LoginName" ), //
                                 pRequest.getParameter( "Passwd" ) );
        }
        if ( QUERY_EQ_PORTAL_FRAME.equals( pQuery ) ) {
            String zHeight = "100%";
            String zDebugDiv = "&nbsp;";
            String zOverflow = PLUS_OVERFLOW_HIDDEN;
            if ( isPortalDebugMode() ) {
                zHeight = "300";
                zDebugDiv = "<div id='dbg'></div>";
                zOverflow = "";
            }
            return new TemplateControl( PORTAL_PAGE, //
                                        "InitScript", "portalsupport/PortalFrameScript.js", //
                                        "CSSfileRef", cachedCSSfileRef(), //
                                        "CSSclass", cachedCSSclass(), //
                                        "BodyStyle", BODY_STYLE_LESS_OVERFLOW + zOverflow, //
                                        "Version", getApplicationVersion(), //
                                        "Height", zHeight, //
                                        "DebugDiv", zDebugDiv, //
                                        KEY_SERVLET_RELATIVE_REFERENCE, mServletRelativeReference );
        }
        if ( pQuery.startsWith( QUERY_SW_LOGIN_PAGE_REQUEST ) ) {
            String zMessage = ConstrainTo.significantOrNull( ServerEventBusSessionMapper.getLogoutMessage( pRequest, this ) );
            return createLoginPage( (zMessage != null) ? zMessage : "&nbsp;" );
        }
        if ( pQuery.startsWith( QUERY_SW_LOGOUT_PAGE_REQUEST ) ) {
            return new TemplateControl( getLogoutReader(), //
                                        "InitScript", "portalsupport/LogoutScript.js", //
                                        "CSSfileRef", cachedCSSfileRef(), //
                                        "CSSclass", cachedCSSclass(), //
                                        "BodyStyle", FULL_BODY_STYLE, //
                                        "Version", getApplicationVersion(), //
                                        "SubmitAction", mServletRelativeReference + "?Logout" );
        }
        if ( pQuery.startsWith( QUERY_SW_STATUS ) ) {
            int at = pQuery.indexOf( ')' );
            if ( at != -1 ) {
                return getStatus( pRequest, pQuery.substring( QUERY_SW_STATUS.length(), at ).trim() );
            }
        }
        return null;
    }

    private TemplateControl createLoginPage( String pMessage )
            throws IOException {
        return new TemplateControl( getLoginReader(), "InitScript", "portalsupport/LoginScript.js", //
                                    "CSSfileRef", cachedCSSfileRef(), //
                                    "CSSclass", cachedCSSclass(), //
                                    "BodyStyle", FULL_BODY_STYLE, //
                                    "Version", getApplicationVersion(), //
                                    "SubmitAction", mServletRelativeReference + "?Login", //
                                    "LoginName", "LoginName", //
                                    "Password", "Passwd", //
                                    "Message", (pMessage != null) ? pMessage : "&nbsp;" );
    }

    private TemplateControl loginRequest( HttpServletRequest pRequest, String pLoginName, String pPassword )
            throws IOException {
        pLoginName = ConstrainTo.significantOrNull( pLoginName );

        String zError = null;
        ClientWindowInstanceDataManager zDataManager = null;
        try {
            ISystemUser zSystemUser = authenticate( pLoginName, pPassword );
            if ( zSystemUser == null ) {
                zError = "Invalid User";
            } else {
                zDataManager = getAuthenticationService().createNewClientWindowInstanceData( zSystemUser );
            }
        }
        catch ( AuthenticationException e ) {
            zError = e.getMessage();
        }
        catch ( RuntimeException e ) {
            getLogger().error.log( e );
            zError = "Authentication Issue";
        }

        if ( zError != null ) {
            return createLoginPage( zError );
        }

        ServerEventBus zTempSEB = createTemporarySEB( "portal LoginRequest", pRequest, zDataManager );

        int zClientIdNumber = zTempSEB.getClientIdNumber();
        String zNewEncodedClientId = ClientIdCodec.encode( zClientIdNumber );
        String windowName = mWindowNameClientIdCodec.createWindowName( zNewEncodedClientId );

        return new TemplateControl( LA_PAGE, //
                                    "CSSfileRef", cachedCSSfileRef(), //
                                    "CSSclass", cachedCSSclass(), //
                                    "BodyStyle", FULL_BODY_STYLE, //
                                    "Version", getApplicationVersion(), //
                                    "URL", mAppPageURL, //
                                    "WinName", windowName, //
                                    "LaunchAppParams", "directories=0," + //
                                                       "location=0," + //
                                                       "menubar=0," + //
                                                       "scrollbars=0," + //
                                                       "status=1," + //
                                                       "toolbar=0," + //
                                                       // "hotkeys=0" + // Netscape!, FireFox?, IE?
                                                       // "screenX=nnnn,screenY=nnnn," + // Netscape!, FireFox?,
                                                       // IE?
                                                       // width=100,height=100," +
                                                       "resizable=1" );
    }

    // Login (from HTML page):
    //         Client:
    //            launchApp
    //            shouldShow:Logout | was:Login
    //            requesting:ServerApp?LogoutPageRequest-0.08359760784499176
    //            showing:Logout
    //            ClientOpen:1
    //            requesting:ServerApp?ClientOpen:1-0.8351432026643422
    //            shouldShow:Login | was:Logout
    //            requesting:ServerApp?LoginPageRequest-0.530483180532334
    //            showing:Login
    //
    //         Server:
    //            service: Login
    //            service: LogoutPageRequest-0.08359760784499176
    //            2008-02-22 12:56:11.265 | Application Client Start Up
    //            [INFO] org.litesoft.GWT.eventbus.server.AbstractServerApp - initialize Page Request, existing: 1 -> 1
    //            2008-02-22 12:56:28.562 | Client AppInitialization
    //            service: ClientOpen:1-0.8351432026643422
    //            2008-02-22 12:56:28.750 | Client AppReady

    // App Window Close:
    //         Client:
    //            ClientClose:1
    //            requesting:ServerApp?ClientClose:1-0.49865901930227324
    //            shouldShow:Login
    //
    //         Server:
    //            service: ClientClose:1-0.49865901930227324
    //            [INFO] org.litesoft.GWT.eventbus.server.AbstractServerApp - ClientDead: 1

    /**
     * Logout the current user!  Should NOT Error
     */
    protected void logout( HttpServletRequest pRequest ) {
        ServerEventBusSessionMapper.dropAllServerEventBusesFor( pRequest, this, "HtmlLauncher-Logout" );
    }

    protected boolean isLoggedIn( HttpServletRequest pRequest ) {
        return ServerEventBusSessionMapper.anyServerEventBusesFor( pRequest, this );
    }

    private TemplateControl getStatus( HttpServletRequest pRequest, String pParameters ) {
        boolean noPopup = false;
        if ( pParameters.length() != 0 ) {
            List<Integer> zAdds = new ArrayList<Integer>();
            List<Integer> zDrops = new ArrayList<Integer>();

            String s = pParameters + ",";
            for ( int at; -1 != (at = s.indexOf( ',' )); s = s.substring( at + 1 ) ) {
                if ( at > 0 ) {
                    String zParam = s.substring( 0, at );
                    if ( NO_POPUP.equals( zParam ) ) {
                        noPopup = true;
                        continue;
                    }
                    if ( at > 1 ) {
                        Integer zClientID = ClientIdCodec.decode( zParam.substring( 1 ) );
                        if ( zClientID != null ) {
                            if ( s.charAt( 0 ) == '+' ) {
                                zAdds.add( zClientID );
                                continue;
                            }
                            if ( s.charAt( 0 ) == '-' ) {
                                zDrops.add( zClientID );
                                continue;
                            }
                        }
                    }
                }
                return null;
            }

            if ( !zDrops.isEmpty() ) {
                getLogger().debug.log( "Status Drops: ", zDrops );
            }
            if ( !zAdds.isEmpty() ) {
                getLogger().debug.log( "Status  Adds: ", zAdds );
            }
        }
        if ( noPopup ) {
            logout( pRequest );
            ServerEventBusSessionMapper.setLogoutMessage( pRequest, this, "Pop-up Blocked!" );
        }
        boolean zLoggedIn = isLoggedIn( pRequest );
        String zLL = zLoggedIn ? QUERY_EQ_LOGOUT : QUERY_EQ_LOGIN;
        return new TemplateControl( new StringReader( "shouldShow" + zLL + "();" ), new String[0] );
    }

    private static final String LA_PAGE =
            "<html><head><title>Launch App</title>%.CSSfileRef.%</head>" + "<body class='%.CSSclass.%' style='%.BodyStyle.%'>Launch App...<script>\n" +
            "try{window.parent.launchApp( '%.URL.%', '%.WinName.%', '%.LaunchAppParams.%' );}\n" +
            "catch ( e ){alert( 'Unable to Launch App:\\nvs\\n%.Version.%\\n\\n' + e );}\n" + "</script></body></html>";

    private static final String PORTAL_PAGE =
            "<html><head><title>Portal Frame</title>%.CSSfileRef.%</head><body class='%.CSSclass.%' style='%.BodyStyle.%'>\n" +
            "<iframe id='LLframe' src='portalsupport/EmptyPage.html' style='%.BodyStyle.%' width='100%' height='%.Height.%' allowTransparency='true'></iframe>" +
            "<div id='Version'>%.Version.%</div>%.DebugDiv.%<script type='text/javascript' src='%.InitScript.%'></script>\n" +
            "<script>initPage( '%.ServletRelativeReference.%' );</script></body></html>";
}

Commits for litesoft/trunk/Java/GWT/OldServer/src/org/litesoft/GWT/eventbus/server/AbstractAuthenticatingHtmlLauncherServerApp.java

Diff revisions: vs.
Revision Author Commited Message
950 Diff Diff GeorgeS picture GeorgeS Thu 19 Jun, 2014 17:57:04 +0000

New Lines

948 Diff Diff GeorgeS picture GeorgeS Sat 07 Jun, 2014 23:42:39 +0000

Jusefuls Formatter Updated to New Code Format

947 Diff Diff GeorgeS picture GeorgeS Fri 06 Jun, 2014 23:36:56 +0000

Correct Spelling of package!

939 Diff Diff GeorgeS picture GeorgeS Mon 02 Jun, 2014 21:30:31 +0000

Extracting commonfoundation

801 Diff Diff GeorgeS picture GeorgeS Wed 15 Aug, 2012 03:59:02 +0000
49 Diff Diff GeorgeS picture GeorgeS Mon 12 Apr, 2010 02:59:10 +0000

License Text

2 GeorgeS picture GeorgeS Sun 07 Feb, 2010 12:50:58 +0000