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
.widgets
.auth
.CmsLoginShell
;
19 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
20 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
21 import org
.eclipse
.swt
.widgets
.Display
;
22 import org
.eclipse
.ui
.PlatformUI
;
24 public abstract class WorkbenchLogin
implements EntryPoint
, CmsView
{
25 // private final static Log log = LogFactory.getLog(WorkbenchLogin.class);
26 private final Subject subject
= new Subject();
27 private LoginContext loginContext
;
30 public int createUI() {
31 final Display display
= PlatformUI
.createDisplay();
32 UiContext
.setData(CmsView
.KEY
, this);
35 loginContext
= new LoginContext(AuthConstants
.LOGIN_CONTEXT_USER
,
36 subject
, new HttpRequestCallbackHandler(getRequest()));
38 } catch (CredentialNotFoundException e
) {
39 CmsLoginShell loginShell
= createCmsLoginShell();
41 while (!loginShell
.getShell().isDisposed()) {
42 if (!display
.readAndDispatch()) {
46 } catch (LoginException e
) {
47 throw new ArgeoException("Cannot log in", e
);
52 Integer returnCode
= null;
54 returnCode
= Subject
.doAs(subject
, new PrivilegedAction
<Integer
>() {
55 public Integer
run() {
56 int result
= createAndRunWorkbench(display
,
57 CurrentUser
.getUsername(subject
));
58 return new Integer(result
);
61 // explicit workbench closing
69 protected abstract int createAndRunWorkbench(Display display
,
72 protected HttpServletRequest
getRequest() {
73 return UiContext
.getHttpRequest();
76 protected CmsLoginShell
createCmsLoginShell() {
77 return new CmsLoginShell(this);
81 public void navigateTo(String state
) {
82 // TODO Auto-generated method stub
87 public void authChange(LoginContext loginContext
) {
88 this.loginContext
= loginContext
;
92 public void logout() {
93 if (loginContext
== null)
94 throw new CmsException("Login context should not bet null");
96 loginContext
.logout();
97 } catch (LoginException e
) {
98 throw new CmsException("Cannot log out", e
);
103 public final Subject
getSubject() {
108 public void exception(Throwable e
) {
109 // TODO Auto-generated method stub
114 public CmsImageManager
getImageManager() {
115 // TODO Auto-generated method stub