1 package org
.argeo
.cms
.util
;
3 import java
.util
.Locale
;
5 import javax
.security
.auth
.login
.LoginContext
;
6 import javax
.security
.auth
.login
.LoginException
;
7 import javax
.servlet
.http
.HttpServletRequest
;
8 import javax
.servlet
.http
.HttpServletResponse
;
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 protected final static String HEADER_WWW_AUTHENTICATE
= "WWW-Authenticate";
28 protected final static String HEADER_AUTHORIZATION
= "Authorization";
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(NodeAuthenticated
.KEY
, this);
38 CmsLoginShell loginShell
= createCmsLoginShell();
41 loginContext
= new LoginContext(NodeConstants
.LOGIN_CONTEXT_USER
, loginShell
);
43 } catch (LoginException e
) {
44 loginShell
.createUi();
47 // HttpServletRequest request = RWT.getRequest();
48 // String authorization = request.getHeader(HEADER_AUTHORIZATION);
49 // if (authorization == null || !authorization.startsWith("Negotiate")) {
50 // HttpServletResponse response = RWT.getResponse();
51 // response.setStatus(401);
52 // response.setHeader(HEADER_WWW_AUTHENTICATE, "Negotiate");
53 // response.setDateHeader("Date", System.currentTimeMillis());
54 // response.setDateHeader("Expires", System.currentTimeMillis() + (24 * 60 * 60 * 1000));
55 // response.setHeader("Accept-Ranges", "bytes");
56 // response.setHeader("Connection", "Keep-Alive");
57 // response.setHeader("Keep-Alive", "timeout=5, max=97");
58 // // response.setContentType("text/html; charset=UTF-8");
61 while (!loginShell
.getShell().isDisposed()) {
62 if (!display
.readAndDispatch())
67 if (CurrentUser
.getUsername() == null)
69 uxContext
= new SimpleUxContext();
73 protected Display
createDisplay() {
77 protected int postLogin() {
81 protected HttpServletRequest
getRequest() {
82 return RWT
.getRequest();
85 protected CmsLoginShell
createCmsLoginShell() {
86 return new CmsLoginShell(this) {
89 public void createContents(Composite parent
) {
90 LoginEntryPoint
.this.createLoginPage(parent
, this);
94 protected void extendsCredentialsBlock(Composite credentialsBlock
, Locale selectedLocale
,
95 SelectionListener loginSelectionListener
) {
96 LoginEntryPoint
.this.extendsCredentialsBlock(credentialsBlock
, selectedLocale
, loginSelectionListener
);
103 * To be overridden. CmsLogin#createCredentialsBlock() should be called at
104 * some point in order to create the credentials composite. In order to use
105 * the default layout, call CmsLogin#defaultCreateContents() but <b>not</b>
106 * CmsLogin#createContent(), since it would lead to a stack overflow.
108 protected void createLoginPage(Composite parent
, CmsLogin login
) {
109 login
.defaultCreateContents(parent
);
112 protected void extendsCredentialsBlock(Composite credentialsBlock
, Locale selectedLocale
,
113 SelectionListener loginSelectionListener
) {
118 public void navigateTo(String state
) {
119 // TODO Auto-generated method stub
124 public void authChange(LoginContext loginContext
) {
125 this.loginContext
= loginContext
;
129 public void logout() {
130 if (loginContext
== null)
131 throw new CmsException("Login context should not bet null");
133 loginContext
.logout();
134 } catch (LoginException e
) {
135 throw new CmsException("Cannot log out", e
);
140 public void exception(Throwable e
) {
141 // TODO Auto-generated method stub
146 public LoginContext
getLoginContext() {
151 public CmsImageManager
getImageManager() {
152 // TODO Auto-generated method stub
157 public UxContext
getUxContext() {