1 package org
.argeo
.cms
.util
;
3 import java
.util
.Locale
;
5 import javax
.security
.auth
.login
.CredentialNotFoundException
;
6 import javax
.security
.auth
.login
.LoginContext
;
7 import javax
.security
.auth
.login
.LoginException
;
8 import javax
.servlet
.http
.HttpServletRequest
;
10 import org
.argeo
.cms
.CmsException
;
11 import org
.argeo
.cms
.auth
.CurrentUser
;
12 import org
.argeo
.cms
.ui
.CmsImageManager
;
13 import org
.argeo
.cms
.ui
.CmsView
;
14 import org
.argeo
.cms
.ui
.UxContext
;
15 import org
.argeo
.cms
.widgets
.auth
.CmsLogin
;
16 import org
.argeo
.cms
.widgets
.auth
.CmsLoginShell
;
17 import org
.argeo
.eclipse
.ui
.specific
.UiContext
;
18 import org
.argeo
.node
.NodeConstants
;
19 import org
.argeo
.node
.security
.NodeAuthenticated
;
20 import org
.eclipse
.rap
.rwt
.RWT
;
21 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
22 import org
.eclipse
.swt
.events
.SelectionListener
;
23 import org
.eclipse
.swt
.widgets
.Composite
;
24 import org
.eclipse
.swt
.widgets
.Display
;
26 public class LoginEntryPoint
implements EntryPoint
, CmsView
{
27 // private final static Log log = LogFactory.getLog(WorkbenchLogin.class);
28 // private final Subject subject = new Subject();
29 private LoginContext loginContext
;
30 private UxContext uxContext
= null;
33 public int createUI() {
34 final Display display
= createDisplay();
35 UiContext
.setData(NodeAuthenticated
.KEY
, this);
36 CmsLoginShell loginShell
= createCmsLoginShell();
39 loginContext
= new LoginContext(NodeConstants
.LOGIN_CONTEXT_USER
, loginShell
);
41 } catch (CredentialNotFoundException e
) {
42 loginShell
.createUi();
44 while (!loginShell
.getShell().isDisposed()) {
46 if (!display
.readAndDispatch())
48 // } catch (Exception e1) {
50 // Thread.sleep(3000);
51 // } catch (InterruptedException e2) {
54 // ErrorFeedback.show("Login failed", e1);
58 } catch (LoginException e
) {
59 throw new CmsException("Cannot log in", e
);
62 if (CurrentUser
.getUsername() == null)
64 uxContext
= new SimpleUxContext();
68 protected Display
createDisplay() {
72 protected int postLogin() {
76 protected HttpServletRequest
getRequest() {
77 return RWT
.getRequest();
82 protected CmsLoginShell
createCmsLoginShell() {
83 return new CmsLoginShell(this) {
86 public void createContents(Composite parent
) {
87 LoginEntryPoint
.this.createLoginPage(parent
, this);
91 protected void extendsCredentialsBlock(Composite credentialsBlock
, Locale selectedLocale
,
92 SelectionListener loginSelectionListener
) {
93 LoginEntryPoint
.this.extendsCredentialsBlock(credentialsBlock
, selectedLocale
, loginSelectionListener
);
100 * To be overridden. CmsLogin#createCredentialsBlock() should be called at
101 * some point in order to create the credentials composite. In order to use
102 * the default layout, call CmsLogin#defaultCreateContents() but <b>not</b>
103 * CmsLogin#createContent(), since it would lead to a stack overflow.
105 protected void createLoginPage(Composite parent
, CmsLogin login
) {
106 login
.defaultCreateContents(parent
);
109 protected void extendsCredentialsBlock(Composite credentialsBlock
, Locale selectedLocale
,
110 SelectionListener loginSelectionListener
) {
115 public void navigateTo(String state
) {
116 // TODO Auto-generated method stub
121 public void authChange(LoginContext loginContext
) {
122 this.loginContext
= loginContext
;
126 public void logout() {
127 if (loginContext
== null)
128 throw new CmsException("Login context should not bet null");
130 loginContext
.logout();
131 } catch (LoginException e
) {
132 throw new CmsException("Cannot log out", e
);
139 // public final Subject getSubject() {
144 // public void registerCallbackHandler(CallbackHandler callbackHandler) {
145 // throw new UnsupportedOperationException();
150 public void exception(Throwable e
) {
151 // TODO Auto-generated method stub
156 public LoginContext
getLoginContext() {
161 public CmsImageManager
getImageManager() {
162 // TODO Auto-generated method stub
167 public UxContext
getUxContext() {