1 package org
.argeo
.cms
.util
;
3 import java
.util
.Locale
;
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
.HttpRequestCallbackHandler
;
17 import org
.argeo
.cms
.widgets
.auth
.CmsLogin
;
18 import org
.argeo
.cms
.widgets
.auth
.CmsLoginShell
;
19 import org
.argeo
.eclipse
.ui
.dialogs
.ErrorFeedback
;
20 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
21 import org
.eclipse
.rap
.rwt
.RWT
;
22 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
23 import org
.eclipse
.swt
.events
.SelectionListener
;
24 import org
.eclipse
.swt
.widgets
.Composite
;
25 import org
.eclipse
.swt
.widgets
.Display
;
27 public class LoginEntryPoint
implements EntryPoint
, CmsView
{
28 // private final static Log log = LogFactory.getLog(WorkbenchLogin.class);
29 private final Subject subject
= new Subject();
30 private LoginContext loginContext
;
33 public int createUI() {
34 final Display display
= createDisplay();
35 UiContext
.setData(CmsView
.KEY
, this);
38 loginContext
= new LoginContext(AuthConstants
.LOGIN_CONTEXT_USER
,
39 subject
, new HttpRequestCallbackHandler(getRequest()));
41 } catch (CredentialNotFoundException e
) {
42 CmsLoginShell loginShell
= createCmsLoginShell();
44 while (!loginShell
.getShell().isDisposed()) {
46 if (!display
.readAndDispatch())
48 } catch (Exception e1
) {
51 } catch (InterruptedException e2
) {
54 ErrorFeedback
.show("Login failed", e1
);
58 } catch (LoginException e
) {
59 throw new ArgeoException("Cannot log in", e
);
64 protected Display
createDisplay() {
68 protected int postLogin() {
72 protected HttpServletRequest
getRequest() {
73 return RWT
.getRequest();
76 protected CmsLoginShell
createCmsLoginShell() {
77 return new CmsLoginShell(this) {
80 public void createContents(Composite parent
) {
81 LoginEntryPoint
.this.createLoginPage(parent
, this);
85 protected void extendsCredentialsBlock(Composite credentialsBlock
,
86 Locale selectedLocale
,
87 SelectionListener loginSelectionListener
) {
88 LoginEntryPoint
.this.extendsCredentialsBlock(credentialsBlock
,
89 selectedLocale
, loginSelectionListener
);
96 * To be overridden. CmsLogin#createCredentialsBlock() should be called at
97 * some point in order to create the credentials composite. In order to use
98 * the default layout, call CmsLogin#defaultCreateContents() but <b>not</b>
99 * CmsLogin#createContent(), since it would lead to a stack overflow.
101 protected void createLoginPage(Composite parent
, CmsLogin login
) {
102 login
.defaultCreateContents(parent
);
105 protected void extendsCredentialsBlock(Composite credentialsBlock
,
106 Locale selectedLocale
, SelectionListener loginSelectionListener
) {
111 public void navigateTo(String state
) {
112 // TODO Auto-generated method stub
117 public void authChange(LoginContext loginContext
) {
118 this.loginContext
= loginContext
;
122 public void logout() {
123 if (loginContext
== null)
124 throw new CmsException("Login context should not bet null");
126 loginContext
.logout();
127 } catch (LoginException e
) {
128 throw new CmsException("Cannot log out", e
);
133 public final Subject
getSubject() {
138 public void exception(Throwable e
) {
139 // TODO Auto-generated method stub
144 public CmsImageManager
getImageManager() {
145 // TODO Auto-generated method stub