1 package org
.argeo
.security
.ui
.login
;
3 import java
.security
.PrivilegedAction
;
5 import javax
.security
.auth
.Subject
;
6 import javax
.security
.auth
.login
.CredentialNotFoundException
;
7 import javax
.security
.auth
.login
.LoginContext
;
8 import javax
.security
.auth
.login
.LoginException
;
9 import javax
.servlet
.http
.HttpServletRequest
;
11 import org
.argeo
.ArgeoException
;
12 import org
.argeo
.cms
.CmsException
;
13 import org
.argeo
.cms
.CmsImageManager
;
14 import org
.argeo
.cms
.CmsView
;
15 import org
.argeo
.cms
.auth
.AuthConstants
;
16 import org
.argeo
.cms
.auth
.CurrentUser
;
17 import org
.argeo
.cms
.auth
.HttpRequestCallbackHandler
;
18 import org
.argeo
.cms
.util
.UserMenu
;
19 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
20 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
21 import org
.eclipse
.swt
.SWT
;
22 import org
.eclipse
.swt
.widgets
.Display
;
23 import org
.eclipse
.swt
.widgets
.Shell
;
24 import org
.eclipse
.ui
.PlatformUI
;
26 public abstract class WorkbenchLogin
implements EntryPoint
, CmsView
{
27 // private final static Log log = LogFactory.getLog(WorkbenchLogin.class);
28 private final Subject subject
= new Subject();
29 private LoginContext loginContext
;
32 public int createUI() {
33 final Display display
= PlatformUI
.createDisplay();
34 UiContext
.setData(CmsView
.KEY
, this);
36 loginContext
= new LoginContext(AuthConstants
.LOGIN_CONTEXT_USER
,
37 subject
, new HttpRequestCallbackHandler(getRequest()));
39 } catch (CredentialNotFoundException e
) {
40 Shell shell
= new Shell(display
, SWT
.NO_TRIM
);
41 shell
.setMaximized(true);
42 //shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
43 UserMenu userMenu
= new UserMenu(shell
, false);
45 while (!userMenu
.getShell().isDisposed()) {
46 if (!display
.readAndDispatch()) {
50 } catch (LoginException e
) {
51 throw new ArgeoException("Cannot log in", e
);
56 Integer returnCode
= null;
58 returnCode
= Subject
.doAs(subject
, new PrivilegedAction
<Integer
>() {
59 public Integer
run() {
60 int result
= createAndRunWorkbench(display
,
61 CurrentUser
.getUsername(subject
));
62 return new Integer(result
);
68 // explicit workbench closing
73 protected abstract int createAndRunWorkbench(Display display
,
76 // private void fullLogout() {
77 // String username = CurrentUser.getUsername(subject);
79 // LoginContext loginContext = new LoginContext(
80 // AuthConstants.LOGIN_CONTEXT_USER, subject);
81 // loginContext.logout();
82 // HttpServletRequest httpRequest = getRequest();
83 // httpRequest.setAttribute(HttpContext.AUTHORIZATION, null);
84 // HttpSession httpSession = httpRequest.getSession();
85 // httpSession.setAttribute(HttpContext.AUTHORIZATION, null);
86 // httpSession.setMaxInactiveInterval(1);
87 // log.info("Logged out " + (username != null ? username : "")
88 // + " (THREAD=" + Thread.currentThread().getId() + ")");
89 // } catch (LoginException e) {
90 // log.error("Error when logging out", e);
94 protected HttpServletRequest
getRequest() {
95 return UiContext
.getHttpRequest();
99 public void navigateTo(String state
) {
100 // TODO Auto-generated method stub
105 public void authChange(LoginContext loginContext
) {
106 this.loginContext
= loginContext
;
110 public void logout() {
111 if (loginContext
== null)
112 throw new CmsException("Login context should not bet null");
114 loginContext
.logout();
115 } catch (LoginException e
) {
116 throw new CmsException("Cannot log out", e
);
121 public final Subject
getSubject() {
126 public void exception(Throwable e
) {
127 // TODO Auto-generated method stub
132 public CmsImageManager
getImageManager() {
133 // TODO Auto-generated method stub