1 package org
.argeo
.security
.ui
.rap
;
3 import java
.security
.PrivilegedAction
;
4 import java
.util
.Locale
;
6 import javax
.security
.auth
.Subject
;
7 import javax
.security
.auth
.login
.CredentialNotFoundException
;
8 import javax
.security
.auth
.login
.LoginContext
;
9 import javax
.security
.auth
.login
.LoginException
;
10 import javax
.servlet
.http
.HttpServletRequest
;
12 import org
.argeo
.ArgeoException
;
13 import org
.argeo
.cms
.CmsException
;
14 import org
.argeo
.cms
.CmsImageManager
;
15 import org
.argeo
.cms
.CmsView
;
16 import org
.argeo
.cms
.auth
.AuthConstants
;
17 import org
.argeo
.cms
.auth
.CurrentUser
;
18 import org
.argeo
.cms
.auth
.HttpRequestCallbackHandler
;
19 import org
.argeo
.cms
.widgets
.auth
.CmsLogin
;
20 import org
.argeo
.cms
.widgets
.auth
.CmsLoginShell
;
21 import org
.argeo
.eclipse
.ui
.dialogs
.ErrorFeedback
;
22 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
23 import org
.eclipse
.rap
.rwt
.RWT
;
24 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
25 import org
.eclipse
.swt
.events
.SelectionListener
;
26 import org
.eclipse
.swt
.widgets
.Composite
;
27 import org
.eclipse
.swt
.widgets
.Display
;
28 import org
.eclipse
.ui
.PlatformUI
;
30 abstract class WorkbenchLogin
implements EntryPoint
, CmsView
{
31 // private final static Log log = LogFactory.getLog(WorkbenchLogin.class);
32 private final Subject subject
= new Subject();
33 private LoginContext loginContext
;
36 public int createUI() {
37 final Display display
= PlatformUI
.createDisplay();
38 UiContext
.setData(CmsView
.KEY
, this);
41 loginContext
= new LoginContext(AuthConstants
.LOGIN_CONTEXT_USER
,
42 subject
, new HttpRequestCallbackHandler(getRequest()));
44 } catch (CredentialNotFoundException e
) {
45 CmsLoginShell loginShell
= createCmsLoginShell();
47 while (!loginShell
.getShell().isDisposed()) {
49 if (!display
.readAndDispatch())
51 } catch (Exception e1
) {
54 } catch (InterruptedException e2
) {
57 ErrorFeedback
.show("Login failed", e1
);
61 } catch (LoginException e
) {
62 throw new ArgeoException("Cannot log in", e
);
67 Integer returnCode
= null;
69 returnCode
= Subject
.doAs(subject
, new PrivilegedAction
<Integer
>() {
70 public Integer
run() {
71 int result
= createAndRunWorkbench(display
,
72 CurrentUser
.getUsername(subject
));
73 return new Integer(result
);
76 // explicit workbench closing
84 protected abstract int createAndRunWorkbench(Display display
,
87 protected HttpServletRequest
getRequest() {
88 return RWT
.getRequest();
91 protected CmsLoginShell
createCmsLoginShell() {
92 return new CmsLoginShell(this) {
95 public void createContents(Composite parent
) {
96 WorkbenchLogin
.this.createLoginPage(parent
, this);
100 protected void extendsCredentialsBlock(Composite credentialsBlock
,
101 Locale selectedLocale
,
102 SelectionListener loginSelectionListener
) {
103 WorkbenchLogin
.this.extendsCredentialsBlock(credentialsBlock
,
104 selectedLocale
, loginSelectionListener
);
111 * To be overridden. CmsLogin#createCredentialsBlock() should be called at
112 * some point in order to create the credentials composite. In order to use
113 * the default layout, call CmsLogin#defaultCreateContents() but <b>not</b>
114 * CmsLogin#createContent(), since it would lead to a stack overflow.
116 protected void createLoginPage(Composite parent
, CmsLogin login
) {
117 login
.defaultCreateContents(parent
);
120 protected void extendsCredentialsBlock(Composite credentialsBlock
,
121 Locale selectedLocale
, SelectionListener loginSelectionListener
) {
126 public void navigateTo(String state
) {
127 // TODO Auto-generated method stub
132 public void authChange(LoginContext loginContext
) {
133 this.loginContext
= loginContext
;
137 public void logout() {
138 if (loginContext
== null)
139 throw new CmsException("Login context should not bet null");
141 loginContext
.logout();
142 } catch (LoginException e
) {
143 throw new CmsException("Cannot log out", e
);
148 public final Subject
getSubject() {
153 public void exception(Throwable e
) {
154 // TODO Auto-generated method stub
159 public CmsImageManager
getImageManager() {
160 // TODO Auto-generated method stub