1 package org
.argeo
.cms
.ui
.workbench
.rap
;
3 import java
.security
.PrivilegedAction
;
5 import javax
.security
.auth
.Subject
;
6 import javax
.security
.auth
.login
.LoginContext
;
7 import javax
.security
.auth
.login
.LoginException
;
9 import org
.apache
.commons
.logging
.Log
;
10 import org
.apache
.commons
.logging
.LogFactory
;
11 import org
.argeo
.api
.NodeConstants
;
12 import org
.argeo
.cms
.CmsException
;
13 import org
.eclipse
.rap
.rwt
.RWT
;
14 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
15 import org
.eclipse
.swt
.widgets
.Display
;
16 import org
.eclipse
.ui
.PlatformUI
;
19 * RAP entry point which authenticates the subject as anonymous, for public
20 * unauthenticated access.
22 public class AnonymousEntryPoint
implements EntryPoint
{
23 private final static Log log
= LogFactory
.getLog(AnonymousEntryPoint
.class);
26 * How many seconds to wait before invalidating the session if the user has
29 private Integer sessionTimeout
= 5 * 60;
32 public int createUI() {
33 RWT
.getRequest().getSession().setMaxInactiveInterval(sessionTimeout
);
35 // if (log.isDebugEnabled())
36 // log.debug("Anonymous THREAD=" + Thread.currentThread().getId()
37 // + ", sessionStore=" + RWT.getSessionStore().getId());
39 final Display display
= PlatformUI
.createDisplay();
40 Subject subject
= new Subject();
42 final LoginContext loginContext
;
44 loginContext
= new LoginContext(NodeConstants
.LOGIN_CONTEXT_ANONYMOUS
,
47 } catch (LoginException e1
) {
48 throw new CmsException("Cannot initialize login context", e1
);
51 // identify after successful login
52 if (log
.isDebugEnabled())
53 log
.debug("Authenticated " + subject
);
54 final String username
= subject
.getPrincipals().iterator().next()
57 // Logout callback when the display is disposed
58 display
.disposeExec(new Runnable() {
60 log
.debug("Display disposed");
61 logout(loginContext
, username
);
68 Integer returnCode
= null;
70 returnCode
= Subject
.doAs(subject
, new PrivilegedAction
<Integer
>() {
71 public Integer
run() {
72 RapWorkbenchAdvisor workbenchAdvisor
= new RapWorkbenchAdvisor(
74 int result
= PlatformUI
.createAndRunWorkbench(display
,
76 return new Integer(result
);
79 logout(loginContext
, username
);
80 if (log
.isTraceEnabled())
81 log
.trace("Return code " + returnCode
);
88 private void logout(LoginContext loginContext
, String username
) {
90 loginContext
.logout();
91 log
.info("Logged out " + (username
!= null ? username
: "")
92 + " (THREAD=" + Thread
.currentThread().getId() + ")");
93 } catch (LoginException e
) {
94 log
.error("Erorr when logging out", e
);