]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.cms.e4.rap/src/org/argeo/cms/e4/rap/CmsE4EntryPointFactory.java
Make relativize more robust
[lgpl/argeo-commons.git] / org.argeo.cms.e4.rap / src / org / argeo / cms / e4 / rap / CmsE4EntryPointFactory.java
1 package org.argeo.cms.e4.rap;
2
3 import java.security.PrivilegedAction;
4
5 import javax.security.auth.Subject;
6
7 import org.eclipse.rap.e4.E4ApplicationConfig;
8 import org.eclipse.rap.e4.E4EntryPointFactory;
9 import org.eclipse.rap.rwt.RWT;
10 import org.eclipse.rap.rwt.application.EntryPoint;
11 import org.eclipse.rap.rwt.client.service.JavaScriptExecutor;
12
13 public class CmsE4EntryPointFactory extends E4EntryPointFactory {
14
15 public CmsE4EntryPointFactory(E4ApplicationConfig config) {
16 super(config);
17 }
18
19 @Override
20 public EntryPoint create() {
21 EntryPoint ep = createEntryPoint();
22 EntryPoint authEp = new EntryPoint() {
23
24 @Override
25 public int createUI() {
26 Subject subject = new Subject();
27 return Subject.doAs(subject, new PrivilegedAction<Integer>() {
28
29 @Override
30 public Integer run() {
31 // SPNEGO
32 // HttpServletRequest request = RWT.getRequest();
33 // String authorization = request.getHeader(HEADER_AUTHORIZATION);
34 // if (authorization == null || !authorization.startsWith("Negotiate")) {
35 // HttpServletResponse response = RWT.getResponse();
36 // response.setStatus(401);
37 // response.setHeader(HEADER_WWW_AUTHENTICATE, "Negotiate");
38 // response.setDateHeader("Date", System.currentTimeMillis());
39 // response.setDateHeader("Expires", System.currentTimeMillis() + (24 * 60 * 60
40 // * 1000));
41 // response.setHeader("Accept-Ranges", "bytes");
42 // response.setHeader("Connection", "Keep-Alive");
43 // response.setHeader("Keep-Alive", "timeout=5, max=97");
44 // // response.setContentType("text/html; charset=UTF-8");
45 // }
46
47 JavaScriptExecutor jsExecutor = RWT.getClient().getService(JavaScriptExecutor.class);
48 Integer exitCode = ep.createUI();
49 jsExecutor.execute("location.reload()");
50 return exitCode;
51 }
52
53 });
54 }
55 };
56 return authEp;
57 }
58
59 protected EntryPoint createEntryPoint() {
60 return super.create();
61 }
62
63 // private boolean login(Subject subject) {
64 // Display display = new Display();
65 // CmsView cmsView = new E4CmsView(subject);
66 // CmsLoginShell loginShell = new CmsLoginShell(cmsView);
67 // loginShell.setSubject(subject);
68 // try {
69 // // try pre-auth
70 // LoginContext loginContext = new
71 // LoginContext(NodeConstants.LOGIN_CONTEXT_USER, subject, loginShell);
72 // loginContext.login();
73 // } catch (LoginException e) {
74 // loginShell.createUi();
75 // loginShell.open();
76 //
77 // while (!loginShell.getShell().isDisposed()) {
78 // if (!display.readAndDispatch())
79 // display.sleep();
80 // }
81 // } finally {
82 // display.dispose();
83 // }
84 // if (CurrentUser.getUsername(subject) == null)
85 // return false;
86 // return true;
87 // }
88 //
89 // private class E4CmsView implements CmsView {
90 // private LoginContext loginContext;
91 // private UxContext uxContext;
92 // private Subject subject;
93 //
94 // public E4CmsView(Subject subject) {
95 // this.subject = subject;
96 // uxContext = new SimpleUxContext();
97 // }
98 //
99 // @Override
100 // public UxContext getUxContext() {
101 // return uxContext;
102 // }
103 //
104 // @Override
105 // public void navigateTo(String state) {
106 // // TODO Auto-generated method stub
107 //
108 // }
109 //
110 // @Override
111 // public void authChange(LoginContext loginContext) {
112 // if (loginContext == null)
113 // throw new CmsException("Login context cannot be null");
114 // // logout previous login context
115 // // if (this.loginContext != null)
116 // // try {
117 // // this.loginContext.logout();
118 // // } catch (LoginException e1) {
119 // // System.err.println("Could not log out: " + e1);
120 // // }
121 // this.loginContext = loginContext;
122 // }
123 //
124 // @Override
125 // public void logout() {
126 // if (loginContext == null)
127 // throw new CmsException("Login context should not bet null");
128 // try {
129 // CurrentUser.logoutCmsSession(loginContext.getSubject());
130 // loginContext.logout();
131 // } catch (LoginException e) {
132 // throw new CmsException("Cannot log out", e);
133 // }
134 // }
135 //
136 // @Override
137 // public void exception(Throwable e) {
138 // log.error("Unexpected exception in Eclipse 4 RAP", e);
139 // }
140 //
141 // @Override
142 // public CmsImageManager getImageManager() {
143 // // TODO Auto-generated method stub
144 // return null;
145 // }
146 //
147 // protected Subject getSubject() {
148 // return subject;
149 // }
150 //
151 // @Override
152 // public boolean isAnonymous() {
153 // return CurrentUser.isAnonymous(getSubject());
154 // }
155 // }
156 }