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
.argeo
.api
.cms
.CmsAuth
;
10 import org
.argeo
.api
.cms
.CmsLog
;
11 import org
.argeo
.cms
.CmsException
;
12 import org
.eclipse
.rap
.rwt
.RWT
;
13 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
14 import org
.eclipse
.swt
.widgets
.Display
;
15 import org
.eclipse
.ui
.PlatformUI
;
18 * RAP entry point which authenticates the subject as anonymous, for public
19 * unauthenticated access.
21 public class AnonymousEntryPoint
implements EntryPoint
{
22 private final static CmsLog log
= CmsLog
.getLog(AnonymousEntryPoint
.class);
25 * How many seconds to wait before invalidating the session if the user has
28 private Integer sessionTimeout
= 5 * 60;
31 public int createUI() {
32 RWT
.getRequest().getSession().setMaxInactiveInterval(sessionTimeout
);
34 // if (log.isDebugEnabled())
35 // log.debug("Anonymous THREAD=" + Thread.currentThread().getId()
36 // + ", sessionStore=" + RWT.getSessionStore().getId());
38 final Display display
= PlatformUI
.createDisplay();
39 Subject subject
= new Subject();
41 final LoginContext loginContext
;
43 loginContext
= new LoginContext(CmsAuth
.LOGIN_CONTEXT_ANONYMOUS
,
46 } catch (LoginException e1
) {
47 throw new CmsException("Cannot initialize login context", e1
);
50 // identify after successful login
51 if (log
.isDebugEnabled())
52 log
.debug("Authenticated " + subject
);
53 final String username
= subject
.getPrincipals().iterator().next()
56 // Logout callback when the display is disposed
57 display
.disposeExec(new Runnable() {
59 log
.debug("Display disposed");
60 logout(loginContext
, username
);
67 Integer returnCode
= null;
69 returnCode
= Subject
.doAs(subject
, new PrivilegedAction
<Integer
>() {
70 public Integer
run() {
71 RapWorkbenchAdvisor workbenchAdvisor
= new RapWorkbenchAdvisor(
73 int result
= PlatformUI
.createAndRunWorkbench(display
,
75 return new Integer(result
);
78 logout(loginContext
, username
);
79 if (log
.isTraceEnabled())
80 log
.trace("Return code " + returnCode
);
87 private void logout(LoginContext loginContext
, String username
) {
89 loginContext
.logout();
90 log
.info("Logged out " + (username
!= null ? username
: "")
91 + " (THREAD=" + Thread
.currentThread().getId() + ")");
92 } catch (LoginException e
) {
93 log
.error("Erorr when logging out", e
);