1 package org
.argeo
.cms
.e4
.rap
;
3 import java
.security
.PrivilegedAction
;
5 import javax
.security
.auth
.Subject
;
6 import javax
.security
.auth
.login
.LoginContext
;
7 import javax
.security
.auth
.login
.LoginException
;
9 import org
.argeo
.cms
.CmsException
;
10 import org
.argeo
.cms
.auth
.CurrentUser
;
11 import org
.argeo
.cms
.ui
.CmsImageManager
;
12 import org
.argeo
.cms
.ui
.CmsView
;
13 import org
.argeo
.cms
.ui
.UxContext
;
14 import org
.argeo
.cms
.util
.SimpleUxContext
;
15 import org
.argeo
.cms
.widgets
.auth
.CmsLoginShell
;
16 import org
.argeo
.node
.NodeConstants
;
17 import org
.eclipse
.rap
.e4
.E4ApplicationConfig
;
18 import org
.eclipse
.rap
.e4
.E4EntryPointFactory
;
19 import org
.eclipse
.rap
.rwt
.application
.EntryPoint
;
20 import org
.eclipse
.swt
.widgets
.Display
;
22 public class CmsE4EntryPointFactory
extends E4EntryPointFactory
{
24 public CmsE4EntryPointFactory(E4ApplicationConfig config
) {
29 public EntryPoint
create() {
30 // Subject subject = new Subject();
31 EntryPoint ep
= createEntryPoint();
32 EntryPoint authEp
= new EntryPoint() {
35 public int createUI() {
36 Subject subject
= new Subject();
37 // boolean success = login(subject);
39 return Subject
.doAs(subject
, new PrivilegedAction
<Integer
>() {
42 public Integer
run() {
43 // RWT.setLocale(Locale.FRENCH);
44 System
.out
.println("createUI");
56 protected EntryPoint
createEntryPoint() {
57 return super.create();
60 boolean login(Subject subject
) {
61 // Subject subject = Subject.getSubject(AccessController.getContext());
62 Display display
= new Display();
63 CmsView cmsView
= new E4CmsView(subject
);
64 CmsLoginShell loginShell
= new CmsLoginShell(cmsView
);
65 loginShell
.setSubject(subject
);
68 LoginContext loginContext
= new LoginContext(NodeConstants
.LOGIN_CONTEXT_USER
, subject
, loginShell
);
70 } catch (LoginException e
) {
71 loginShell
.createUi();
74 while (!loginShell
.getShell().isDisposed()) {
75 if (!display
.readAndDispatch())
81 if (CurrentUser
.getUsername(subject
) == null)
86 class E4CmsView
implements CmsView
{
87 private LoginContext loginContext
;
88 private UxContext uxContext
;
89 private Subject subject
;
91 public E4CmsView(Subject subject
) {
92 this.subject
= subject
;
93 uxContext
= new SimpleUxContext();
97 public UxContext
getUxContext() {
102 public void navigateTo(String state
) {
103 // TODO Auto-generated method stub
108 public void authChange(LoginContext loginContext
) {
109 if (loginContext
== null)
110 throw new CmsException("Login context cannot be null");
111 // logout previous login context
112 // if (this.loginContext != null)
114 // this.loginContext.logout();
115 // } catch (LoginException e1) {
116 // System.err.println("Could not log out: " + e1);
118 this.loginContext
= loginContext
;
122 public void logout() {
123 if (loginContext
== null)
124 throw new CmsException("Login context should not bet null");
126 CurrentUser
.logoutCmsSession(loginContext
.getSubject());
127 loginContext
.logout();
128 } catch (LoginException e
) {
129 throw new CmsException("Cannot log out", e
);
134 public void exception(Throwable e
) {
135 // TODO Auto-generated method stub
140 public CmsImageManager
getImageManager() {
141 // TODO Auto-generated method stub
145 protected Subject
getSubject() {
150 public boolean isAnonymous() {
151 return CurrentUser
.isAnonymous(getSubject());