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
.cms
.widgets
.auth
.CmsLogin
;
20 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
21 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
22 import org
.eclipse
.swt
.SWT
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Display
;
25 import org
.eclipse
.swt
.widgets
.Shell
;
26 import org
.eclipse
.ui
.PlatformUI
;
28 public abstract class WorkbenchLogin
implements EntryPoint
, CmsView
{
29 // private final static Log log = LogFactory.getLog(WorkbenchLogin.class);
30 private final Subject subject
= new Subject();
31 private LoginContext loginContext
;
34 public int createUI() {
35 final Display display
= PlatformUI
.createDisplay();
36 UiContext
.setData(CmsView
.KEY
, this);
38 loginContext
= new LoginContext(AuthConstants
.LOGIN_CONTEXT_USER
,
39 subject
, new HttpRequestCallbackHandler(getRequest()));
41 } catch (CredentialNotFoundException e
) {
42 // Shell shell = new Shell(display, SWT.NO_TRIM);
43 // shell.setMaximized(true);
44 // shell.setBackground(display.getSystemColor(SWT.COLOR_CYAN));
45 UserMenu userMenu
= new UserMenu(null, false);
47 while (!userMenu
.getShell().isDisposed()) {
48 if (!display
.readAndDispatch()) {
52 } catch (LoginException e
) {
53 throw new ArgeoException("Cannot log in", e
);
58 Integer returnCode
= null;
60 returnCode
= Subject
.doAs(subject
, new PrivilegedAction
<Integer
>() {
61 public Integer
run() {
62 int result
= createAndRunWorkbench(display
,
63 CurrentUser
.getUsername(subject
));
64 return new Integer(result
);
67 // explicit workbench closing
75 protected abstract int createAndRunWorkbench(Display display
,
78 protected HttpServletRequest
getRequest() {
79 return UiContext
.getHttpRequest();
83 public void navigateTo(String state
) {
84 // TODO Auto-generated method stub
89 public void authChange(LoginContext loginContext
) {
90 this.loginContext
= loginContext
;
94 public void logout() {
95 if (loginContext
== null)
96 throw new CmsException("Login context should not bet null");
98 loginContext
.logout();
99 } catch (LoginException e
) {
100 throw new CmsException("Cannot log out", e
);
105 public final Subject
getSubject() {
110 public void exception(Throwable e
) {
111 // TODO Auto-generated method stub
116 public CmsImageManager
getImageManager() {
117 // TODO Auto-generated method stub
121 // private class WorbenchCmsLogin extends CmsLogin {
122 // private final Shell shell;
124 // public WorbenchCmsLogin(CmsView cmsView, Shell shell) {
126 // this.shell = shell;
128 // Composite parent = new Composite(shell, SWT.NONE);
129 // anonymousUi(parent);