Import-Package: org.argeo.node,\
org.eclipse.swt,\
+org.eclipse.swt.graphics,\
org.eclipse.rap.rwt.client,\
*
import java.util.HashMap;
import java.util.Map;
-import javax.security.auth.Subject;
-
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.argeo.cms.ui.dialogs.CmsFeedback;
Map<String, String> properties = new HashMap<String, String>();
properties.put(WebClient.PAGE_TITLE, pageTitle);
E4ApplicationConfig config = new E4ApplicationConfig(e4Xmi, lifeCycleUri, null, false, true, true);
- Subject subject = new Subject();
- addEntryPoint(application, subject, config, properties);
+ addEntryPoint(application, config, properties);
// config.isClearPersistedState();
// E4EntryPointFactory entryPointFactory = new E4EntryPointFactory(config) {
//
// };
}
- protected void addEntryPoint(Application application, Subject subject, E4ApplicationConfig config,
- Map<String, String> properties) {
- CmsE4EntryPointFactory entryPointFactory = new CmsE4EntryPointFactory(subject, config);
+ protected void addEntryPoint(Application application, E4ApplicationConfig config, Map<String, String> properties) {
+ CmsE4EntryPointFactory entryPointFactory = new CmsE4EntryPointFactory(config);
application.addEntryPoint(path, entryPointFactory, properties);
application.setOperationMode(OperationMode.SWT_COMPATIBILITY);
}
import java.security.PrivilegedAction;
import javax.security.auth.Subject;
+import javax.security.auth.login.LoginContext;
+import javax.security.auth.login.LoginException;
+import org.argeo.cms.CmsException;
+import org.argeo.cms.auth.CurrentUser;
+import org.argeo.cms.ui.CmsImageManager;
+import org.argeo.cms.ui.CmsView;
+import org.argeo.cms.ui.UxContext;
+import org.argeo.cms.util.SimpleUxContext;
+import org.argeo.cms.widgets.auth.CmsLoginShell;
+import org.argeo.node.NodeConstants;
import org.eclipse.rap.e4.E4ApplicationConfig;
import org.eclipse.rap.e4.E4EntryPointFactory;
import org.eclipse.rap.rwt.application.EntryPoint;
+import org.eclipse.swt.widgets.Display;
public class CmsE4EntryPointFactory extends E4EntryPointFactory {
- private Subject subject;
- public CmsE4EntryPointFactory(Subject subject, E4ApplicationConfig config) {
+ public CmsE4EntryPointFactory(E4ApplicationConfig config) {
super(config);
- this.subject = subject;
}
@Override
@Override
public int createUI() {
- return Subject.doAs(subject, new PrivilegedAction<Integer>() {
+ Subject subject = new Subject();
+// boolean success = login(subject);
+// if (success)
+ return Subject.doAs(subject, new PrivilegedAction<Integer>() {
- @Override
- public Integer run() {
- return ep.createUI();
- }
+ @Override
+ public Integer run() {
+// RWT.setLocale(Locale.FRENCH);
+ System.out.println("createUI");
+ return ep.createUI();
+ }
- });
+ });
+// else
+// return 1;
}
};
return authEp;
return super.create();
}
+ boolean login(Subject subject) {
+ // Subject subject = Subject.getSubject(AccessController.getContext());
+ Display display = new Display();
+ CmsView cmsView = new E4CmsView(subject);
+ CmsLoginShell loginShell = new CmsLoginShell(cmsView);
+ loginShell.setSubject(subject);
+ try {
+ // try pre-auth
+ LoginContext loginContext = new LoginContext(NodeConstants.LOGIN_CONTEXT_USER, subject, loginShell);
+ loginContext.login();
+ } catch (LoginException e) {
+ loginShell.createUi();
+ loginShell.open();
+
+ while (!loginShell.getShell().isDisposed()) {
+ if (!display.readAndDispatch())
+ display.sleep();
+ }
+ } finally {
+ display.dispose();
+ }
+ if (CurrentUser.getUsername(subject) == null)
+ return false;
+ return true;
+ }
+
+ class E4CmsView implements CmsView {
+ private LoginContext loginContext;
+ private UxContext uxContext;
+ private Subject subject;
+
+ public E4CmsView(Subject subject) {
+ this.subject = subject;
+ uxContext = new SimpleUxContext();
+ }
+
+ @Override
+ public UxContext getUxContext() {
+ return uxContext;
+ }
+
+ @Override
+ public void navigateTo(String state) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public void authChange(LoginContext loginContext) {
+ if (loginContext == null)
+ throw new CmsException("Login context cannot be null");
+ // logout previous login context
+ // if (this.loginContext != null)
+ // try {
+ // this.loginContext.logout();
+ // } catch (LoginException e1) {
+ // System.err.println("Could not log out: " + e1);
+ // }
+ this.loginContext = loginContext;
+ }
+
+ @Override
+ public void logout() {
+ if (loginContext == null)
+ throw new CmsException("Login context should not bet null");
+ try {
+ CurrentUser.logoutCmsSession(loginContext.getSubject());
+ loginContext.logout();
+ } catch (LoginException e) {
+ throw new CmsException("Cannot log out", e);
+ }
+ }
+
+ @Override
+ public void exception(Throwable e) {
+ // TODO Auto-generated method stub
+
+ }
+
+ @Override
+ public CmsImageManager getImageManager() {
+ // TODO Auto-generated method stub
+ return null;
+ }
+
+ protected Subject getSubject() {
+ return subject;
+ }
+
+ @Override
+ public boolean isAnonymous() {
+ return CurrentUser.isAnonymous(getSubject());
+ }
+ }
}
private LoginContext loginContext;
@PostContextCreate
- boolean login(Display d) {// , IEclipseContext eclipseContext) {
- // RepositoryFactory repositoryFactory =
- // eclipseContext.get(RepositoryFactory.class);
- // Map<String, String> params = new HashMap<>();
- // params.put("cn", "home");
- // Repository homeRepository;
- // try {
- // homeRepository = repositoryFactory.getRepository(params);
- // } catch (RepositoryException e1) {
- // throw new CmsException("Cannot get home repository", e1);
- // }
- // eclipseContext.set("(cn=home)", homeRepository);
-
+ boolean login() {
Subject subject = Subject.getSubject(AccessController.getContext());
Display display = Display.getCurrent();
CmsLoginShell loginShell = new CmsLoginShell(this);
if (CurrentUser.getUsername(getSubject()) == null)
return false;
uxContext = new SimpleUxContext();
+
+ //lcs.changeApplicationLocale(Locale.FRENCH);
return true;
}
--- /dev/null
+package org.argeo.cms.e4.handlers;
+
+import java.util.Locale;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.core.services.nls.ILocaleChangeService;
+
+public class ChangeLanguage {
+ @Execute
+ public void execute(ILocaleChangeService localeChangeService) {
+ localeChangeService.changeApplicationLocale(Locale.FRENCH);
+ }
+}
--- /dev/null
+package org.argeo.cms.e4.handlers;
+
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+
+public class CloseAllParts {
+
+ @Execute
+ void execute(EPartService partService) {
+ for (MPart part : partService.getParts()) {
+ if (part.isCloseable()) {
+ if (part.isDirty()) {
+ if (partService.savePart(part, true)) {
+ partService.hidePart(part);
+ }
+ } else {
+ partService.hidePart(part);
+ }
+ }
+ }
+ }
+
+ @CanExecute
+ boolean canExecute(EPartService partService) {
+ boolean atLeastOnePart = false;
+ for (MPart part : partService.getParts()) {
+ if (part.isVisible()) {
+ atLeastOnePart = true;
+ break;
+ }
+ }
+ return atLeastOnePart;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.cms.e4.handlers;
+
+import org.eclipse.e4.core.di.annotations.Execute;
+
+public class DoNothing {
+ @Execute
+ public void execute() {
+
+ }
+}
--- /dev/null
+package org.argeo.cms.e4.handlers;
+
+import java.security.AccessController;
+import java.util.Locale;
+
+import javax.annotation.PostConstruct;
+import javax.security.auth.Subject;
+
+import org.eclipse.e4.core.services.nls.ILocaleChangeService;
+
+public class LocaleAddon {
+ @PostConstruct
+ public void init(ILocaleChangeService localeChangeService) {
+ Subject subject = Subject.getSubject(AccessController.getContext());
+ Locale locale = subject.getPublicCredentials(Locale.class).iterator().next();
+ localeChangeService.changeApplicationLocale(locale);
+ }
+}
--- /dev/null
+package org.argeo.cms.e4.handlers;
+
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+
+public class SaveAllParts {
+
+ @Execute
+ void execute(EPartService partService) {
+ partService.saveAll(false);
+ }
+
+ @CanExecute
+ boolean canExecute(EPartService partService) {
+ return partService.getDirtyParts().size() > 0;
+ }
+
+}
\ No newline at end of file
--- /dev/null
+package org.argeo.cms.e4.handlers;
+
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.workbench.modeling.EPartService;
+
+public class SavePart {
+ @Execute
+ void execute(EPartService partService, MPart part) {
+ partService.savePart(part, false);
+ }
+
+ @CanExecute
+ boolean canExecute(MPart part) {
+ return part.isDirty();
+ }
+}
\ No newline at end of file
@Override
public boolean commit() throws LoginException {
+ subject.getPublicCredentials().add(locale);
+
if (singleUser) {
OsUserUtils.loginAsSystemUser(subject);
}
});
}
}
-
+
// Register CmsSession with initial subject
CmsAuthUtils.registerSessionAuthorization(request, subject, authorization, locale);