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
.ui
.UxContext
;
18 import org
.argeo
.cms
.widgets
.auth
.CmsLogin
;
19 import org
.argeo
.cms
.widgets
.auth
.CmsLoginShell
;
20 import org
.argeo
.eclipse
.ui
.dialogs
.ErrorFeedback
;
21 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
22 import org
.eclipse
.rap
.rwt
.RWT
;
23 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
24 import org
.eclipse
.swt
.events
.SelectionListener
;
25 import org
.eclipse
.swt
.widgets
.Composite
;
26 import org
.eclipse
.swt
.widgets
.Display
;
28 public class LoginEntryPoint
implements EntryPoint
, CmsView
{
29 // private final static Log log = LogFactory.getLog(WorkbenchLogin.class);
30 private final Subject subject
= new Subject();
31 private LoginContext loginContext
;
32 private UxContext uxContext
= null;
35 public int createUI() {
36 final Display display
= createDisplay();
37 UiContext
.setData(CmsView
.KEY
, this);
40 loginContext
= new LoginContext(AuthConstants
.LOGIN_CONTEXT_USER
,
41 subject
, new HttpRequestCallbackHandler(getRequest()));
43 } catch (CredentialNotFoundException e
) {
44 CmsLoginShell loginShell
= createCmsLoginShell();
46 while (!loginShell
.getShell().isDisposed()) {
48 if (!display
.readAndDispatch())
50 } catch (Exception e1
) {
53 } catch (InterruptedException e2
) {
56 ErrorFeedback
.show("Login failed", e1
);
60 } catch (LoginException e
) {
61 throw new ArgeoException("Cannot log in", e
);
63 uxContext
= new SimpleUxContext();
67 protected Display
createDisplay() {
71 protected int postLogin() {
75 protected HttpServletRequest
getRequest() {
76 return RWT
.getRequest();
79 protected CmsLoginShell
createCmsLoginShell() {
80 return new CmsLoginShell(this) {
83 public void createContents(Composite parent
) {
84 LoginEntryPoint
.this.createLoginPage(parent
, this);
88 protected void extendsCredentialsBlock(Composite credentialsBlock
,
89 Locale selectedLocale
,
90 SelectionListener loginSelectionListener
) {
91 LoginEntryPoint
.this.extendsCredentialsBlock(credentialsBlock
,
92 selectedLocale
, loginSelectionListener
);
99 * To be overridden. CmsLogin#createCredentialsBlock() should be called at
100 * some point in order to create the credentials composite. In order to use
101 * the default layout, call CmsLogin#defaultCreateContents() but <b>not</b>
102 * CmsLogin#createContent(), since it would lead to a stack overflow.
104 protected void createLoginPage(Composite parent
, CmsLogin login
) {
105 login
.defaultCreateContents(parent
);
108 protected void extendsCredentialsBlock(Composite credentialsBlock
,
109 Locale selectedLocale
, SelectionListener loginSelectionListener
) {
114 public void navigateTo(String state
) {
115 // TODO Auto-generated method stub
120 public void authChange(LoginContext loginContext
) {
121 this.loginContext
= loginContext
;
125 public void logout() {
126 if (loginContext
== null)
127 throw new CmsException("Login context should not bet null");
129 loginContext
.logout();
130 } catch (LoginException e
) {
131 throw new CmsException("Cannot log out", e
);
136 public final Subject
getSubject() {
141 public void exception(Throwable e
) {
142 // TODO Auto-generated method stub
147 public CmsImageManager
getImageManager() {
148 // TODO Auto-generated method stub
153 public UxContext
getUxContext() {