package org.argeo.security.ui.rap;
-import java.security.Principal;
+import java.security.AccessController;
import javax.security.auth.Subject;
-import javax.security.auth.login.LoginException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.GroupMarker;
import org.eclipse.jface.action.IAction;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.jface.action.Separator;
import org.eclipse.jface.action.ToolBarManager;
-import org.eclipse.rwt.RWT;
import org.eclipse.swt.SWT;
import org.eclipse.ui.IWorkbenchActionConstants;
import org.eclipse.ui.IWorkbenchWindow;
-import org.eclipse.ui.PlatformUI;
import org.eclipse.ui.actions.ActionFactory;
import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
import org.eclipse.ui.application.ActionBarAdvisor;
import org.eclipse.ui.application.IActionBarConfigurer;
public class SecureActionBarAdvisor extends ActionBarAdvisor {
- private final static Log log = LogFactory
- .getLog(SecureActionBarAdvisor.class);
+// private final static Log log = LogFactory
+// .getLog(SecureActionBarAdvisor.class);
private IAction logoutAction;
private IWorkbenchAction openPerspectiveDialogAction;
showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
register(showViewMenuAction);
- // logoutAction = ActionFactory.QUIT.create(window);
+ // logout
+ logoutAction = ActionFactory.QUIT.create(window);
+ //logoutAction = createLogoutAction();
+ register(logoutAction);
+
+ // Save semantics
+ saveAction = ActionFactory.SAVE.create(window);
+ register(saveAction);
+ saveAllAction = ActionFactory.SAVE_ALL.create(window);
+ register(saveAllAction);
+ closeAllAction = ActionFactory.CLOSE_ALL.create(window);
+ register(closeAllAction);
+
+ }
- Subject subject = null;
- try {
- subject = SecureRapActivator.getLoginContext().getSubject();
- } catch (LoginException e1) {
- throw new ArgeoException("Cannot retrieve subject", e1);
- }
- final Principal principal = subject.getPrincipals().iterator().next();
+ protected IAction createLogoutAction() {
+ Subject subject = Subject.getSubject(AccessController.getContext());
+ final String username = subject.getPrincipals().iterator().next()
+ .getName();
- logoutAction = new Action() {
+ IAction logoutAction = new Action() {
public String getId() {
return SecureRapActivator.ID + ".logoutAction";
}
public String getText() {
- return "Logout " + principal.getName();
+ return "Logout " + username;
}
public void run() {
- try {
- Subject subject = SecureRapActivator.getLoginContext()
- .getSubject();
- String subjectStr = subject.toString();
- SecureRapActivator.getLoginContext().logout();
- log.info(subjectStr + " logged out");
- } catch (LoginException e) {
- log.error("Error when logging out", e);
- }
- try {
- RWT.getRequest().getSession().setMaxInactiveInterval(1);
- PlatformUI.getWorkbench().close();
- } catch (Exception e) {
- if (log.isTraceEnabled())
- log.trace("Error when invalidating session", e);
- }
+ // try {
+ // Subject subject = SecureRapActivator.getLoginContext()
+ // .getSubject();
+ // String subjectStr = subject.toString();
+ // subject.getPrincipals().clear();
+ // SecureRapActivator.getLoginContext().logout();
+ // log.info(subjectStr + " logged out");
+ // } catch (LoginException e) {
+ // log.error("Error when logging out", e);
+ // }
+// SecureEntryPoint.logout(username);
+// PlatformUI.getWorkbench().close();
+ // try {
+ // RWT.getRequest().getSession().setMaxInactiveInterval(1);
+ // } catch (Exception e) {
+ // if (log.isTraceEnabled())
+ // log.trace("Error when invalidating session", e);
+ // }
}
};
- register(logoutAction);
-
- // Save semantics
- saveAction = ActionFactory.SAVE.create(window);
- register(saveAction);
- saveAllAction = ActionFactory.SAVE_ALL.create(window);
- register(saveAllAction);
- closeAllAction = ActionFactory.CLOSE_ALL.create(window);
- register(closeAllAction);
-
+ return logoutAction;
}
protected void fillMenuBar(IMenuManager menuBar) {