1 package org
.argeo
.cms
.ui
.util
;
3 import java
.util
.Locale
;
5 import javax
.security
.auth
.Subject
;
6 import javax
.security
.auth
.login
.LoginContext
;
7 import javax
.security
.auth
.login
.LoginException
;
8 import javax
.servlet
.http
.HttpServletRequest
;
10 import org
.apache
.commons
.logging
.Log
;
11 import org
.apache
.commons
.logging
.LogFactory
;
12 import org
.argeo
.api
.NodeConstants
;
13 import org
.argeo
.cms
.CmsException
;
14 import org
.argeo
.cms
.auth
.CurrentUser
;
15 import org
.argeo
.cms
.ui
.CmsImageManager
;
16 import org
.argeo
.cms
.ui
.CmsView
;
17 import org
.argeo
.cms
.ui
.UxContext
;
18 import org
.argeo
.cms
.ui
.widgets
.auth
.CmsLogin
;
19 import org
.argeo
.cms
.ui
.widgets
.auth
.CmsLoginShell
;
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 protected final static String HEADER_WWW_AUTHENTICATE
= "WWW-Authenticate";
29 protected final static String HEADER_AUTHORIZATION
= "Authorization";
30 private final static Log log
= LogFactory
.getLog(LoginEntryPoint
.class);
31 private LoginContext loginContext
;
32 private UxContext uxContext
= null;
35 public int createUI() {
36 final Display display
= createDisplay();
37 // UiContext.setData(CmsView.KEY, this);
39 CmsLoginShell loginShell
= createCmsLoginShell();
40 CmsView
.registerCmsView(loginShell
.getShell(), this);
43 loginContext
= new LoginContext(NodeConstants
.LOGIN_CONTEXT_USER
, loginShell
);
45 } catch (LoginException e
) {
46 loginShell
.createUi();
49 // HttpServletRequest request = RWT.getRequest();
50 // String authorization = request.getHeader(HEADER_AUTHORIZATION);
51 // if (authorization == null ||
52 // !authorization.startsWith("Negotiate")) {
53 // HttpServletResponse response = RWT.getResponse();
54 // response.setStatus(401);
55 // response.setHeader(HEADER_WWW_AUTHENTICATE, "Negotiate");
56 // response.setDateHeader("Date", System.currentTimeMillis());
57 // response.setDateHeader("Expires", System.currentTimeMillis() +
58 // (24 * 60 * 60 * 1000));
59 // response.setHeader("Accept-Ranges", "bytes");
60 // response.setHeader("Connection", "Keep-Alive");
61 // response.setHeader("Keep-Alive", "timeout=5, max=97");
62 // // response.setContentType("text/html; charset=UTF-8");
65 while (!loginShell
.getShell().isDisposed()) {
66 if (!display
.readAndDispatch())
71 if (CurrentUser
.getUsername(getSubject()) == null)
73 uxContext
= new SimpleUxContext();
77 protected Display
createDisplay() {
81 protected int postLogin() {
85 protected HttpServletRequest
getRequest() {
86 return RWT
.getRequest();
89 protected CmsLoginShell
createCmsLoginShell() {
90 return new CmsLoginShell(this) {
93 public void createContents(Composite parent
) {
94 LoginEntryPoint
.this.createLoginPage(parent
, this);
98 protected void extendsCredentialsBlock(Composite credentialsBlock
, Locale selectedLocale
,
99 SelectionListener loginSelectionListener
) {
100 LoginEntryPoint
.this.extendsCredentialsBlock(credentialsBlock
, selectedLocale
, loginSelectionListener
);
107 * To be overridden. CmsLogin#createCredentialsBlock() should be called at
108 * some point in order to create the credentials composite. In order to use
109 * the default layout, call CmsLogin#defaultCreateContents() but <b>not</b>
110 * CmsLogin#createContent(), since it would lead to a stack overflow.
112 protected void createLoginPage(Composite parent
, CmsLogin login
) {
113 login
.defaultCreateContents(parent
);
116 protected void extendsCredentialsBlock(Composite credentialsBlock
, Locale selectedLocale
,
117 SelectionListener loginSelectionListener
) {
122 public void navigateTo(String state
) {
123 // TODO Auto-generated method stub
128 public void authChange(LoginContext loginContext
) {
129 if (loginContext
== null)
130 throw new CmsException("Login context cannot be null");
131 // logout previous login context
132 if (this.loginContext
!= null)
134 this.loginContext
.logout();
135 } catch (LoginException e1
) {
136 log
.warn("Could not log out: " + e1
);
138 this.loginContext
= loginContext
;
142 public void logout() {
143 if (loginContext
== null)
144 throw new CmsException("Login context should not bet null");
146 CurrentUser
.logoutCmsSession(loginContext
.getSubject());
147 loginContext
.logout();
148 } catch (LoginException e
) {
149 throw new CmsException("Cannot log out", e
);
154 public void exception(Throwable e
) {
155 // TODO Auto-generated method stub
160 // public LoginContext getLoginContext() {
161 // return loginContext;
164 protected Subject
getSubject() {
165 return loginContext
.getSubject();
169 public boolean isAnonymous() {
170 return CurrentUser
.isAnonymous(getSubject());
174 public CmsImageManager
getImageManager() {
175 // TODO Auto-generated method stub
180 public UxContext
getUxContext() {