1 package org
.argeo
.security
.ui
.rap
;
3 import java
.security
.PrivilegedAction
;
5 import javax
.security
.auth
.Subject
;
6 import javax
.security
.auth
.login
.LoginException
;
8 import org
.apache
.commons
.logging
.Log
;
9 import org
.apache
.commons
.logging
.LogFactory
;
10 import org
.argeo
.ArgeoException
;
11 import org
.eclipse
.equinox
.security
.auth
.ILoginContext
;
12 import org
.eclipse
.rwt
.RWT
;
13 import org
.eclipse
.rwt
.lifecycle
.IEntryPoint
;
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 IEntryPoint
{
22 private final static Log log
= LogFactory
.getLog(AnonymousEntryPoint
.class);
25 * How many seconds to wait before invalidating the session if the user has
28 private Integer loginTimeout
= 1 * 60;
29 private Integer sessionTimeout
= 15 * 60;
32 public int createUI() {
33 // Short login timeout so that the modal dialog login doesn't hang
35 RWT
.getRequest().getSession().setMaxInactiveInterval(loginTimeout
);
37 if (log
.isDebugEnabled())
38 log
.debug("Anonymous THREAD=" + Thread
.currentThread().getId()
39 + ", sessionStore=" + RWT
.getSessionStore().getId());
42 final Display display
= PlatformUI
.createDisplay();
45 final ILoginContext loginContext
= SecureRapActivator
46 .createLoginContext(SecureRapActivator
.CONTEXT_SPRING_ANONYMOUS
);
47 Subject subject
= null;
50 subject
= loginContext
.getSubject();
51 } catch (LoginException e
) {
52 throw new ArgeoException(
53 "Unexpected exception during authentication", e
);
56 // identify after successful login
57 if (log
.isDebugEnabled())
58 log
.debug("Authenticated " + subject
);
59 final String username
= subject
.getPrincipals().iterator().next()
62 // Once the user is logged in, she can have a longer session timeout
63 RWT
.getRequest().getSession().setMaxInactiveInterval(sessionTimeout
);
65 // Logout callback when the display is disposed
66 display
.disposeExec(new Runnable() {
68 log
.debug("Display disposed");
69 logout(loginContext
, username
);
76 Integer returnCode
= null;
78 returnCode
= Subject
.doAs(subject
, new PrivilegedAction
<Integer
>() {
79 public Integer
run() {
80 RapWorkbenchAdvisor workbenchAdvisor
= new RapWorkbenchAdvisor(
82 int result
= PlatformUI
.createAndRunWorkbench(display
,
84 return new Integer(result
);
87 logout(loginContext
, username
);
94 private void logout(ILoginContext secureContext
, String username
) {
96 secureContext
.logout();
97 log
.info("Logged out " + (username
!= null ? username
: "")
98 + " (THREAD=" + Thread
.currentThread().getId() + ")");
99 } catch (LoginException e
) {
100 log
.error("Erorr when logging out", e
);