protected abstract WorkbenchAdvisor createWorkbenchAdvisor();
+ @SuppressWarnings("unchecked")
public Object start(IApplicationContext context) throws Exception {
Integer returnCode = null;
log.debug("Logged in as " + username);
returnCode = (Integer) Subject.doAs(CurrentUser.getSubject(),
getRunAction(display));
- if (log.isDebugEnabled())
- log.debug("secure action completed");
CurrentUser.logout();
return processReturnCode(returnCode);
} catch (Exception e) {
package org.argeo.security.ui.application;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
public class RapSecureWorkbenchWindowAdvisor extends
SecureWorkbenchWindowAdvisor {
- private final static Log log = LogFactory
- .getLog(RapSecureWorkbenchWindowAdvisor.class);
-
public RapSecureWorkbenchWindowAdvisor(IWorkbenchWindowConfigurer configurer) {
super(configurer);
}
public void preWindowOpen() {
IWorkbenchWindowConfigurer configurer = getWindowConfigurer();
- // configurer.setInitialSize(new Point(800, 600));
-
-// if (log.isDebugEnabled())
-// log.debug("CHAR ENCODING"
-// + System.getProperty("file.encoding"));
configurer.setShowCoolBar(true);
configurer.setShowMenuBar(true);
configurer.setShowStatusLine(false);
private IWorkbenchAction openPerspectiveDialogAction;
private IWorkbenchAction showViewMenuAction;
private IWorkbenchAction preferences;
- private IWorkbenchAction helpContentAction;
private IWorkbenchAction saveAction;
private IWorkbenchAction saveAllAction;
private IWorkbenchAction closeAllAction;
register(openPerspectiveDialogAction);
showViewMenuAction = ActionFactory.SHOW_VIEW_MENU.create(window);
register(showViewMenuAction);
- helpContentAction = ActionFactory.HELP_CONTENTS.create(window);
- register(helpContentAction);
exitAction = ActionFactory.QUIT.create(window);
register(exitAction);
IWorkbenchActionConstants.M_EDIT);
MenuManager windowMenu = new MenuManager("&Window",
IWorkbenchActionConstants.M_WINDOW);
- MenuManager helpMenu = new MenuManager("&Help",
- IWorkbenchActionConstants.M_HELP);
menuBar.add(fileMenu);
menuBar.add(editMenu);
menuBar.add(windowMenu);
// Add a group marker indicating where action set menus will appear.
menuBar.add(new GroupMarker(IWorkbenchActionConstants.MB_ADDITIONS));
- menuBar.add(helpMenu);
// File
fileMenu.add(saveAction);
// Window
windowMenu.add(openPerspectiveDialogAction);
windowMenu.add(showViewMenuAction);
-
- // Help
- helpMenu.add(helpContentAction);
- // helpMenu.add(aboutAction);
}
@Override
if (securityService.getSecurityDao().userExists(user.getUsername()))
securityService.updateUser(user);
else {
- try {
- // FIXME: make it cleaner
- ((SimpleArgeoUser)user).setPassword(user.getUsername());
- securityService.newUser(user);
- setPartName(user.getUsername());
- } catch (Exception e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
+ securityService.newUser(user);
+ setPartName(user.getUsername());
}
firePropertyChange(PROP_DIRTY);
}
createGeneralPart(form.getBody());
createRolesPart(form.getBody());
+ createPassworPart(form.getBody());
}
/** Creates the general section */
log.trace("General part committed");
}
};
+ if (username != null)
+ username.addModifyListener(new FormPartML(part));
firstName.addModifyListener(new FormPartML(part));
lastName.addModifyListener(new FormPartML(part));
email.addModifyListener(new FormPartML(part));
getManagedForm().addPart(part);
}
+ /** Creates the password section */
+ protected void createPassworPart(Composite parent) {
+ FormToolkit tk = getManagedForm().getToolkit();
+ Section section = tk.createSection(parent, Section.TITLE_BAR);
+ section.setText("Password");
+
+ Composite body = tk.createComposite(section, SWT.WRAP);
+ section.setClient(body);
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = layout.marginHeight = 0;
+ layout.numColumns = 2;
+ body.setLayout(layout);
+
+ // add widgets (view)
+ final Text password1 = createLP(body, "New password", "");
+ final Text password2 = createLP(body, "Repeat password", "");
+ // create form part (controller)
+ AbstractFormPart part = new SectionPart(section) {
+ public void commit(boolean onSave) {
+ if (!password1.getText().equals("")
+ && password1.getText().equals(password2.getText())) {
+ ((SimpleArgeoUser) user).setPassword(password1.getText());
+ }
+ super.commit(onSave);
+ if (log.isTraceEnabled())
+ log.trace("Password part committed");
+ }
+ };
+ password1.addModifyListener(new FormPartML(part));
+ password2.addModifyListener(new FormPartML(part));
+ getManagedForm().addPart(part);
+ }
+
/** Creates the role section */
protected void createRolesPart(Composite parent) {
FormToolkit tk = getManagedForm().getToolkit();
return text;
}
+ /** Creates label and password. */
+ protected Text createLP(Composite body, String label, String value) {
+ FormToolkit toolkit = getManagedForm().getToolkit();
+ toolkit.createLabel(body, label);
+ Text text = toolkit.createText(body, value, SWT.BORDER | SWT.PASSWORD);
+ text.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+ return text;
+ }
+
public void setSimpleNatureType(String simpleNatureType) {
this.simpleNatureType = simpleNatureType;
}
public void updateUserPassword(String username, String password) {
SimpleArgeoUser user = new SimpleArgeoUser(
securityDao.getUser(username));
- user.setPassword(password);
+ user.setPassword(securityDao.encodePassword(password));
securityDao.update(user);
}
}
public void newUser(ArgeoUser user) {
-// user.getUserNatures().clear();
argeoSecurity.beforeCreate(user);
+ // normalize password
+ if (user instanceof SimpleArgeoUser) {
+ if (user.getPassword() == null || user.getPassword().equals(""))
+ ((SimpleArgeoUser) user).setPassword(securityDao
+ .encodePassword(user.getUsername()));
+ else if (!user.getPassword().startsWith("{"))
+ ((SimpleArgeoUser) user).setPassword(securityDao
+ .encodePassword(user.getPassword()));
+ }
securityDao.create(user);
}
public void updateUser(ArgeoUser user) {
- String password = securityDao.getUserWithPassword(user.getUsername())
- .getPassword();
+ String password = user.getPassword();
+ if (password == null)
+ password = securityDao.getUserWithPassword(user.getUsername())
+ .getPassword();
+ if (!password.startsWith("{"))
+ password = securityDao.encodePassword(user.getPassword());
SimpleArgeoUser simpleArgeoUser = new SimpleArgeoUser(user);
simpleArgeoUser.setPassword(password);
securityDao.update(simpleArgeoUser);
ctx.setAttributeValue("sn", nature.getLastName());
ctx.setAttributeValue("givenName", nature.getFirstName());
ctx.setAttributeValue("mail", nature.getEmail());
- if (nature.getDescription() != null) {
+ if (nature.getDescription() != null
+ && !nature.getDescription().equals("")) {
ctx.setAttributeValue("description", nature.getDescription());
}
}