}
public Object execute(ExecutionEvent event) throws ExecutionException {
+ String commandId = event.getCommand().getId();
+ String bundleSymbolicName = commandId.substring(0,
+ commandId.lastIndexOf('.'));
try {
- if (log.isDebugEnabled())
- log.debug("Execute " + event + " via spring command handler "
+ if (log.isTraceEnabled())
+ log.trace("Execute " + event + " via spring command handler "
+ this);
-
- // Find the application context of the bundle defining the command
- // extension
- // ICommandService commandService =
- // (ICommandService)ArgeoUiPlugin.getDefault().getWorkbench().getService(ICommandService.class);
- //
- // Command command =
- // commandService.getCommand(event.getCommand().getId());
- // log.debug("command=" + command);
- // log.debug("Command id " + command.getId());
- //
- // Platform.getExtensionRegistry().getE
- //
- // IExtension extension =
- // Platform.getExtensionRegistry().getExtension(
- // "org.eclipse.ui.commands", command.getId());
- // log.debug("extension=" + extension);
- // String bundleSymbolicName = extension.getContributor().getName();
-
- // Assume that the defining bundle name is the first part of the
- // command
- // id
// TODO: make it more flexible and robust
- String commandId = event.getCommand().getId();
- String bundleSymbolicName = commandId.substring(0, commandId
- .lastIndexOf('.'));
ApplicationContext applicationContext = ApplicationContextTracker
.getApplicationContext(bundleSymbolicName);
return handler.execute(event);
} catch (Exception e) {
// TODO: use eclipse error management
- log.error(e);
- return null;
+// log.error(e);
+ throw new ExecutionException("Cannot execute Spring command "
+ + commandId + " in bundle " + bundleSymbolicName, e);
}
}
<plugin id="org.eclipse.swt.gtk.linux.x86_64" fragment="true"/>
<plugin id="org.eclipse.swt.win32.win32.x86" fragment="true"/>
<plugin id="org.eclipse.ui"/>
+ <plugin id="org.eclipse.ui.forms"/>
<plugin id="org.eclipse.ui.workbench"/>
<plugin id="org.springframework.aop"/>
<plugin id="org.springframework.beans"/>
public void createInitialLayout(IPageLayout layout) {
String editorArea = layout.getEditorArea();
- layout.setEditorAreaVisible(false);
+ layout.setEditorAreaVisible(true);
layout.setFixed(false);
- IFolderLayout main = layout.createFolder("main", IPageLayout.RIGHT,
- 0.3f, editorArea);
IFolderLayout left = layout.createFolder("left", IPageLayout.LEFT,
0.3f, editorArea);
left.addView("org.argeo.security.ui.usersView");
- main.addView("org.argeo.security.ui.currentUserView");
+ left.addView("org.argeo.security.ui.currentUserView");
}
}
import org.argeo.ArgeoException;
import org.argeo.security.ArgeoSecurityService;
import org.argeo.security.ArgeoUser;
+import org.argeo.security.UserNature;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorSite;
protected void addPages() {
try {
- addPage(new ArgeoUserMainPage(this, user));
+ addPage(new DefaultUserMainPage(this, user));
+
} catch (PartInitException e) {
throw new ArgeoException("Not able to add page ", e);
}
+++ /dev/null
-package org.argeo.security.ui.editors;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.security.ArgeoUser;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Combo;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.forms.IManagedForm;
-import org.eclipse.ui.forms.editor.FormEditor;
-import org.eclipse.ui.forms.editor.FormPage;
-import org.eclipse.ui.forms.widgets.ColumnLayout;
-import org.eclipse.ui.forms.widgets.FormToolkit;
-import org.eclipse.ui.forms.widgets.ScrolledForm;
-
-/**
- *
- * @author bsinou
- *
- * This page display main info of a specified Ebi. Roles enable the
- */
-public class ArgeoUserMainPage extends FormPage {
- private final static Log log = LogFactory.getLog(ArgeoUserMainPage.class);
-
- private ArgeoUser user;
-
- private Text text;
- private Combo combo;
-
- public ArgeoUserMainPage(FormEditor editor, ArgeoUser user) {
- super(editor, "argeoUserEditor.mainPage", "Main");
- this.user = user;
- }
-
- protected void createFormContent(IManagedForm managedForm) {
- try {
- ScrolledForm form = managedForm.getForm();
-
- // Set the title of the current form
- form.setText(user.toString());
-
- ColumnLayout mainLayout = new ColumnLayout();
- mainLayout.minNumColumns = 1;
- mainLayout.maxNumColumns = 4;
-
- mainLayout.topMargin = 0;
- mainLayout.bottomMargin = 5;
- mainLayout.leftMargin = mainLayout.rightMargin = mainLayout.horizontalSpacing = mainLayout.verticalSpacing = 10;
- form.getBody().setLayout(mainLayout);
-
- FormToolkit toolkit = managedForm.getToolkit();
-
- Composite body = toolkit.createComposite(form.getBody());
- GridLayout layout = new GridLayout();
- layout.marginWidth = layout.marginHeight = 0;
- layout.numColumns = 2;
- body.setLayout(layout);
-
- // Comments
- toolkit.createLabel(body, "Label1");
- text = toolkit.createText(body, user.getUsername(), SWT.WRAP
- | SWT.BORDER);
-
- // Project Status
- // A combo Box
- toolkit.createLabel(body, "Statut du Projet");
- // TIP : we have to create a composite to wrap the combo box that
- // cannot be handled directly by the toolkit.
- Composite subBody = toolkit.createComposite(body);
-
- GridLayout subLayout = new GridLayout();
- subLayout.marginWidth = 3;
- layout.numColumns = 2;
- subBody.setLayout(subLayout);
-
- // The subBody fills 2 columns and a row
- GridData gd;
- gd = new GridData(GridData.FILL_BOTH);
- gd.horizontalSpan = 2;
- subBody.setLayoutData(gd);
-
- toolkit.adapt(subBody, true, true);
-
- toolkit.createLabel(body, "Some more text");
- toolkit.createLabel(body, "And Again");
-
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
-}
--- /dev/null
+package org.argeo.security.ui.editors;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.security.ArgeoUser;
+import org.argeo.security.UserNature;
+import org.argeo.security.nature.SimpleUserNature;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Combo;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.eclipse.ui.forms.IManagedForm;
+import org.eclipse.ui.forms.editor.FormEditor;
+import org.eclipse.ui.forms.editor.FormPage;
+import org.eclipse.ui.forms.widgets.ColumnLayout;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+import org.eclipse.ui.forms.widgets.ScrolledForm;
+
+/**
+ *
+ * @author bsinou
+ *
+ * This page display main info of a specified Ebi. Roles enable the
+ */
+public class DefaultUserMainPage extends FormPage {
+ private final static Log log = LogFactory.getLog(DefaultUserMainPage.class);
+
+ private ArgeoUser user;
+ private SimpleUserNature simpleNature;
+
+ private String simpleNatureType;
+
+ private Text email;
+ private Text description;
+
+ public DefaultUserMainPage(FormEditor editor, ArgeoUser user) {
+ super(editor, "argeoUserEditor.mainPage", "Main");
+ this.user = user;
+
+ if (simpleNatureType != null)
+ simpleNature = (SimpleUserNature) user.getUserNatures().get(
+ simpleNatureType);
+ else
+ for (UserNature userNature : user.getUserNatures().values())
+ if (userNature instanceof SimpleUserNature)
+ simpleNature = (SimpleUserNature) userNature;
+
+ if (simpleNature == null)
+ throw new ArgeoException("No simple user nature in user " + user);
+ }
+
+ protected void createFormContent(IManagedForm managedForm) {
+ try {
+ ScrolledForm form = managedForm.getForm();
+
+ // Set the title of the current form
+ form.setText(simpleNature.getFirstName() + " "
+ + simpleNature.getLastName());
+
+ ColumnLayout mainLayout = new ColumnLayout();
+ mainLayout.minNumColumns = 1;
+ mainLayout.maxNumColumns = 4;
+
+ mainLayout.topMargin = 0;
+ mainLayout.bottomMargin = 5;
+ mainLayout.leftMargin = mainLayout.rightMargin = mainLayout.horizontalSpacing = mainLayout.verticalSpacing = 10;
+ form.getBody().setLayout(mainLayout);
+
+ FormToolkit toolkit = managedForm.getToolkit();
+
+ Composite body = toolkit.createComposite(form.getBody());
+ GridLayout layout = new GridLayout();
+ layout.marginWidth = layout.marginHeight = 0;
+ layout.numColumns = 2;
+ body.setLayout(layout);
+
+ // Comments
+ toolkit.createLabel(body, "Username");
+ toolkit.createLabel(body, user.getUsername());
+ toolkit.createLabel(body, "Email");
+ email = toolkit.createText(body, simpleNature.getEmail(), SWT.WRAP
+ | SWT.BORDER);
+ toolkit.createLabel(body, "Description");
+ description = toolkit.createText(body,
+ simpleNature.getDescription(), SWT.MULTI | SWT.WRAP
+ | SWT.BORDER);
+
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
+ }
+
+ public void setSimpleNatureType(String simpleNatureType) {
+ this.simpleNatureType = simpleNatureType;
+ }
+
+}
<include>plugin.xml</include>
<include>META-INF/**</include>
<include>jaas/**</include>
+ <include>icons/**</include>
</includes>
</resource>
</resources>
--- /dev/null
+/*
+ * Copyright (C) 2010 Mathieu Baudier <mbaudier@argeo.org>
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.argeo.security;
+
+
+/** A set of specific data attached to a user. */
+public abstract class AbstractUserNature implements UserNature {
+ private static final long serialVersionUID = 1169323440459736478L;
+
+ private String type;
+
+ public String getType() {
+ if (type != null)
+ return type;
+ else
+ return getClass().getName();
+ }
+
+ public void setType(String type) {
+ this.type = type;
+ }
+
+}
import java.util.List;
+/**
+ * Access to the users and roles referential (dependent from the underlying
+ * storage, e.g. LDAP).
+ */
public interface ArgeoSecurityDao {
-// public ArgeoUser getCurrentUser();
+ // public ArgeoUser getCurrentUser();
public List<ArgeoUser> listUsers();
public ArgeoUser getUser(String username);
public ArgeoUser getUserWithPassword(String username);
-
+
public String getDefaultRole();
}
package org.argeo.security;
+/**
+ * High level access to the user referential (independent from the underlying
+ * storage).
+ */
public interface ArgeoSecurityService {
public ArgeoUser getCurrentUser();
import java.util.List;
import java.util.Map;
+/** Abstraction for a user. */
public interface ArgeoUser {
public String getUsername();
- public Map<String,UserNature> getUserNatures();
+ public Map<String, UserNature> getUserNatures();
/** Implementation should refuse to add new user natures via this method. */
- public void updateUserNatures(Map<String,UserNature> userNatures);
+ public void updateUserNatures(Map<String, UserNature> userNatures);
public List<String> getRoles();
import java.util.List;
import java.util.Map;
+import org.argeo.ArgeoException;
+
public class SimpleArgeoUser implements ArgeoUser, Serializable {
private static final long serialVersionUID = 1L;
}
public void updateUserNatures(Map<String, UserNature> userNaturesData) {
- UserNature.updateUserNaturesWithCheck(userNatures, userNaturesData);
+ updateUserNaturesWithCheck(userNatures, userNaturesData);
+ }
+
+ public static void updateUserNaturesWithCheck(
+ Map<String, UserNature> userNatures,
+ Map<String, UserNature> userNaturesData) {
+ // checks consistency
+ if (userNatures.size() != userNaturesData.size())
+ throw new ArgeoException(
+ "It is forbidden to add or remove user natures via this method");
+
+ for (String type : userNatures.keySet()) {
+ if (!userNaturesData.containsKey(type))
+ throw new ArgeoException(
+ "Could not find a user nature of type " + type);
+ }
+
+ // for (int i = 0; i < userNatures.size(); i++) {
+ // String type = userNatures.get(i).getType();
+ // boolean found = false;
+ // for (int j = 0; j < userNatures.size(); j++) {
+ // String newType = userNaturesData.get(j).getType();
+ // if (type.equals(newType))
+ // found = true;
+ // }
+ // if (!found)
+ // throw new ArgeoException(
+ // "Could not find a user nature of type " + type);
+ // }
+
+ for (String key : userNatures.keySet()) {
+ userNatures.put(key, userNaturesData.get(key));
+ }
+ }
+
+ @Override
+ public String toString() {
+ return username;
}
public List<String> getRoles() {
package org.argeo.security;
import java.io.Serializable;
-import java.util.List;
-import java.util.Map;
-import org.argeo.ArgeoException;
-
-public class UserNature implements Serializable {
- private static final long serialVersionUID = 1L;
-
- private String type;
-
- public String getType() {
- if (type != null)
- return type;
- else
- return getClass().getName();
- }
-
- public void setType(String type) {
- this.type = type;
- }
-
- public final static void updateUserNaturesWithCheck(
- Map<String, UserNature> userNatures,
- Map<String, UserNature> userNaturesData) {
- if (userNatures.size() != userNaturesData.size())
- throw new ArgeoException(
- "It is forbidden to add or remove user natures via this method");
- for (int i = 0; i < userNatures.size(); i++) {
- String type = userNatures.get(i).getType();
- boolean found = false;
- for (int j = 0; j < userNatures.size(); j++) {
- String newType = userNaturesData.get(j).getType();
- if (type.equals(newType))
- found = true;
- }
- if (!found)
- throw new ArgeoException(
- "Could not find a user nature of type " + type);
- }
-
- for (String key : userNatures.keySet()) {
- userNatures.put(key, userNaturesData.get(key));
- }
- }
+/**
+ * A set of specific data attached to a user. TODO: is this interface really
+ * useful?
+ */
+public interface UserNature extends Serializable {
+ @Deprecated
+ /** @deprecated will be removed soon*/
+ public String getType();
}
import org.argeo.security.ArgeoUser;
import org.argeo.security.SimpleArgeoUser;
import org.argeo.security.UserNature;
+import org.argeo.security.nature.SimpleUserNature;
import org.springframework.security.Authentication;
import org.springframework.security.GrantedAuthority;
import org.springframework.security.GrantedAuthorityImpl;
private final Map<String, UserNature> userNatures;
private final List<String> roles;
- public ArgeoUserDetails(String username, Map<String, UserNature> userNatures,
- String password, GrantedAuthority[] authorities)
- throws IllegalArgumentException {
+ public ArgeoUserDetails(String username,
+ Map<String, UserNature> userNatures, String password,
+ GrantedAuthority[] authorities) throws IllegalArgumentException {
super(username, password, true, true, true, true, authorities);
this.userNatures = Collections.unmodifiableMap(userNatures);
}
public void updateUserNatures(Map<String, UserNature> userNaturesData) {
- UserNature.updateUserNaturesWithCheck(userNatures, userNaturesData);
+ SimpleArgeoUser
+ .updateUserNaturesWithCheck(userNatures, userNaturesData);
}
public List<String> getRoles() {
public void beforeCreate(ArgeoUser user) {
SimpleUserNature simpleUserNature = new SimpleUserNature();
simpleUserNature.setLastName("empty");// to prevent issue with sn in LDAP
- user.getUserNatures().put("simple",simpleUserNature);
+ user.getUserNatures().put("simpleUserNature",simpleUserNature);
}
public String getSuperUsername() {
import org.springframework.security.userdetails.UserDetails;
import org.springframework.security.userdetails.ldap.UserDetailsContextMapper;
+/**
+ * Performs the mapping between LDAP and the user natures, using
+ * {@link UserNatureMapper}.
+ */
public class ArgeoUserDetailsContextMapper implements UserDetailsContextMapper {
// private final static Log log = LogFactory
// .getLog(ArgeoUserDetailsContextMapper.class);
import org.springframework.ldap.core.DirContextAdapter;
import org.springframework.ldap.core.DirContextOperations;
+/** Maps a user nature from LDAP. */
public interface UserNatureMapper {
public String getName();
-
+
public void mapUserInfoToContext(UserNature userInfo, DirContextAdapter ctx);
public UserNature mapUserInfoFromContext(DirContextOperations ctx);
public class SimpleUserNatureMapper implements UserNatureMapper {
public String getName() {
- return "simpleUser";
+ return SimpleUserNature.TYPE;
}
public UserNature mapUserInfoFromContext(DirContextOperations ctx) {
package org.argeo.security.nature;
-import org.argeo.security.UserNature;
+import org.argeo.security.AbstractUserNature;
-public class CoworkerNature extends UserNature {
+public class CoworkerNature extends AbstractUserNature {
private static final long serialVersionUID = 1L;
private String mobile;
private String telephoneNumber;
package org.argeo.security.nature;
-import org.argeo.security.UserNature;
+import org.argeo.security.AbstractUserNature;
+
+public class SimpleUserNature extends AbstractUserNature {
+ /**
+ * No PAI, for internal use within the Argeo Security framework. Will
+ * probably be removed.
+ */
+ public final static String TYPE = "simpleUser";
-public class SimpleUserNature extends UserNature {
private static final long serialVersionUID = 1L;
private String email;
private String firstName;