Remove JcrSecurityModel from supported APIs
authorMathieu Baudier <mbaudier@argeo.org>
Sat, 14 Feb 2015 16:14:17 +0000 (16:14 +0000)
committerMathieu Baudier <mbaudier@argeo.org>
Sat, 14 Feb 2015 16:14:17 +0000 (16:14 +0000)
git-svn-id: https://svn.argeo.org/commons/trunk@7869 4cfe0d0a-d680-48aa-b62c-e0a02a3f76cc

44 files changed:
org.argeo.cms/src/org/argeo/cms/internal/auth/JcrSecurityModel.java [new file with mode: 0644]
org.argeo.cms/src/org/argeo/cms/internal/auth/OsJcrAuthenticationProvider.java
org.argeo.cms/src/org/argeo/cms/internal/kernel/NodeSecurity.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/AbstractJcrUser.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/JcrAuthorization.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/JcrEndUser.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/JcrGroup.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/JcrRole.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/JcrUserAdmin.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/SimpleJcrSecurityModel.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/jackrabbit/JackrabbitUserAdminService.java
org.argeo.cms/src/org/argeo/cms/internal/useradmin/ldap/JcrLdapSynchronizer.java
org.argeo.cms/src/org/argeo/cms/users/MainUserInfoWizardPage.java [new file with mode: 0644]
org.argeo.cms/src/org/argeo/cms/users/NewUserWizard.java [new file with mode: 0644]
org.argeo.cms/src/org/argeo/cms/users/UserCreationWizard.java [new file with mode: 0644]
org.argeo.cms/src/org/argeo/cms/users/UserRolesPart.java
org.argeo.cms/src/org/argeo/cms/users/Users.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/ErrorFeedback.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddFolderNode.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddPrivileges.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/AddRemoteRepository.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/CreateWorkspace.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/DeleteNodes.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/EditNode.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/GetNodeSize.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/commands/ImportFileSystem.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/model/RepositoriesElem.java
org.argeo.eclipse.ui.workbench/src/org/argeo/eclipse/ui/workbench/jcr/internal/parts/ImportFileSystemWizard.java
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/ErrorFeedback.java [new file with mode: 0644]
org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/UserCreationWizard.java [deleted file]
org.argeo.security.core/src/org/argeo/security/jcr/JcrSecurityModel.java [deleted file]
org.argeo.security.core/src/org/argeo/security/jcr/NewUserDetails.java [new file with mode: 0644]
org.argeo.security.ui.admin/META-INF/spring/commands.xml
org.argeo.security.ui.admin/META-INF/spring/common.xml
org.argeo.security.ui.admin/META-INF/spring/views.xml
org.argeo.security.ui.admin/bnd.bnd
org.argeo.security.ui.admin/pom.xml
org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/NewUser.java
org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/commands/UserBatchUpdate.java
org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/MainUserInfoWizardPage.java [deleted file]
org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/NewUserWizard.java [deleted file]
org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/UserBatchUpdateWizard.java
org.argeo.security.ui.rap/src/org/argeo/security/ui/rap/SecureEntryPoint.java
org.argeo.security.ui/src/org/argeo/security/ui/commands/OpenHomePerspective.java

diff --git a/org.argeo.cms/src/org/argeo/cms/internal/auth/JcrSecurityModel.java b/org.argeo.cms/src/org/argeo/cms/internal/auth/JcrSecurityModel.java
new file mode 100644 (file)
index 0000000..2cf1e24
--- /dev/null
@@ -0,0 +1,36 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.cms.internal.auth;
+
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.Session;
+
+/**
+ * Manages data expected by the Argeo security model, such as user home and
+ * profile.
+ */
+public interface JcrSecurityModel {
+       /**
+        * To be called before user details are loaded. Make sure than any logged in
+        * user has a home directory with full access and a profile with information
+        * about him (read access)
+        * 
+        * @return the user profile, never null
+        */
+       public Node sync(Session session, String username, List<String> roles);
+}
index 61ed7ba35f33747c03119ecd8379190cb3f5428f..a394baf1e598c5a9ee44e35dfad024b90bfd3dff 100644 (file)
@@ -28,7 +28,6 @@ import org.argeo.jcr.JcrUtils;
 import org.argeo.security.OsAuthenticationToken;
 import org.argeo.security.SecurityUtils;
 import org.argeo.security.core.OsAuthenticationProvider;
-import org.argeo.security.jcr.JcrSecurityModel;
 import org.argeo.security.jcr.JcrUserDetails;
 import org.springframework.security.authentication.BadCredentialsException;
 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
index 13f48f369438f1b6191b29a5e83639e7a60b4550..e841bfc3db187cb8c2f896ea66e511758d72047a 100644 (file)
@@ -85,6 +85,8 @@ class NodeSecurity implements AuthenticationManager {
                userDetailsManagerReg.unregister();
                userAdminServiceReg.unregister();
                authenticationManagerReg.unregister();
+
+               userAdmin.destroy();
                userAdminReg.unregister();
        }
 
index f13da0128e112713cd571d1578fa57365247550d..7d63b8693f78c8d404cea04b4147418ff0bd5523 100644 (file)
@@ -2,11 +2,12 @@ package org.argeo.cms.internal.useradmin;
 
 import java.util.Dictionary;
 
+import org.argeo.cms.CmsException;
 import org.osgi.service.useradmin.Role;
 import org.osgi.service.useradmin.User;
 
 abstract class AbstractJcrUser extends JcrRole implements User {
-       public AbstractJcrUser(String name) {
+       public AbstractJcrUser(String name) {
                super(name);
        }
 
@@ -17,14 +18,12 @@ abstract class AbstractJcrUser extends JcrRole implements User {
 
        @Override
        public Dictionary<String, Object> getCredentials() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new CmsException("Not implemented yet");
        }
 
        @Override
        public boolean hasCredential(String key, Object value) {
-               // TODO Auto-generated method stub
-               return false;
+               throw new CmsException("Not implemented yet");
        }
 
 }
index 76f67ce71671b2a4dfcd9720f3a90073e39a698d..3832a15685867d5d2213733ad1201faec9fd7ccd 100644 (file)
@@ -4,15 +4,15 @@ import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
 
-import org.argeo.security.jcr.JcrUserDetails;
 import org.osgi.service.useradmin.Authorization;
 import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
 
 class JcrAuthorization implements Authorization {
        private final String name;
        private final List<String> roles;
 
-       public JcrAuthorization(JcrUserDetails userDetails) {
+       public JcrAuthorization(UserDetails userDetails) {
                this.name = userDetails.getUsername();
                List<String> t = new ArrayList<String>();
                for (GrantedAuthority ga : userDetails.getAuthorities()) {
index fbbbdd01fffe2a3f4bc5a4f0020be445ecd38ca3..0fd5086d530424cf11bdfd041370320174095cf5 100644 (file)
@@ -1,6 +1,7 @@
 package org.argeo.cms.internal.useradmin;
 
 import org.argeo.security.jcr.JcrUserDetails;
+import org.springframework.security.core.userdetails.UserDetails;
 
 class JcrEndUser extends AbstractJcrUser {
        private final JcrUserDetails userDetails;
@@ -10,7 +11,7 @@ class JcrEndUser extends AbstractJcrUser {
                this.userDetails = userDetails;
        }
 
-       JcrUserDetails getUserDetails() {
+       public UserDetails getUserDetails() {
                return userDetails;
        }
 
index 93f7587589169101188a5e2e90eea887573cedd6..56ddf0b42eba31edb95160fb323a3b2b688e3af7 100644 (file)
@@ -1,5 +1,6 @@
 package org.argeo.cms.internal.useradmin;
 
+import org.argeo.cms.CmsException;
 import org.osgi.service.useradmin.Group;
 import org.osgi.service.useradmin.Role;
 
@@ -18,32 +19,27 @@ class JcrGroup extends AbstractJcrUser implements Group {
 
        @Override
        public boolean addMember(Role role) {
-               // TODO Auto-generated method stub
-               return false;
+               throw new CmsException("Not implemented yet");
        }
 
        @Override
        public boolean addRequiredMember(Role role) {
-               // TODO Auto-generated method stub
-               return false;
+               throw new CmsException("Not implemented yet");
        }
 
        @Override
        public boolean removeMember(Role role) {
-               // TODO Auto-generated method stub
-               return false;
+               throw new CmsException("Not implemented yet");
        }
 
        @Override
        public Role[] getMembers() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new CmsException("Not implemented yet");
        }
 
        @Override
        public Role[] getRequiredMembers() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new CmsException("Not implemented yet");
        }
 
        public String toString() {
index 43ded9e5957c9d5fd569fb753ad79e80d15dfcd9..3b3320ab5613a70cac6218c06e554d478c8bbc2f 100644 (file)
@@ -2,6 +2,7 @@ package org.argeo.cms.internal.useradmin;
 
 import java.util.Dictionary;
 
+import org.argeo.cms.CmsException;
 import org.osgi.service.useradmin.Role;
 
 abstract class JcrRole implements Role {
@@ -23,8 +24,7 @@ abstract class JcrRole implements Role {
 
        @Override
        public Dictionary<String, Object> getProperties() {
-               // TODO Auto-generated method stub
-               return null;
+               throw new CmsException("Not implemented yet");
        }
 
 }
index ecaf5e0aff2e64d9253ebee55a032f96c2eb136e..f36a0714f0cfdf52b7df5f72959c36016a62075c 100644 (file)
@@ -5,16 +5,16 @@ import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 
-import javax.jcr.Node;
 import javax.jcr.Repository;
-import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
 import org.argeo.ArgeoException;
+import org.argeo.cms.CmsException;
+import org.argeo.cms.internal.useradmin.jackrabbit.JackrabbitUserAdminService;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrSecurityModel;
 import org.argeo.security.jcr.JcrUserDetails;
+import org.argeo.security.jcr.NewUserDetails;
 import org.osgi.framework.BundleContext;
 import org.osgi.framework.InvalidSyntaxException;
 import org.osgi.framework.ServiceReference;
@@ -24,14 +24,16 @@ import org.osgi.service.useradmin.User;
 import org.osgi.service.useradmin.UserAdmin;
 import org.osgi.service.useradmin.UserAdminEvent;
 import org.osgi.service.useradmin.UserAdminListener;
-import org.springframework.security.core.GrantedAuthority;
 import org.springframework.security.core.userdetails.UsernameNotFoundException;
 
+/**
+ * Incomplete implementation of {@link UserAdmin} wrapping the supported
+ * {@link UserAdminService} for the time being.
+ */
 public class JcrUserAdmin implements UserAdmin {
        private final BundleContext bundleContext;
-       private UserAdminService userAdminService;
+       private JackrabbitUserAdminService userAdminService;
 
-       private final JcrSecurityModel jcrSecurityModel = new SimpleJcrSecurityModel();
        private final Session session;
 
        public JcrUserAdmin(BundleContext bundleContext, Repository node) {
@@ -49,28 +51,16 @@ public class JcrUserAdmin implements UserAdmin {
 
        @Override
        public Role createRole(String name, int type) {
-               try {
-                       if (Role.USER == type) {
-                               Node userProfile = jcrSecurityModel.sync(session, name, null);
-                               session.getWorkspace().getVersionManager()
-                                               .checkout(userProfile.getPath());
-                               String password = "";
-                               // TODO add roles
-                               JcrUserDetails userDetails = new JcrUserDetails(userProfile,
-                                               password, new ArrayList<GrantedAuthority>());
-                               session.save();
-                               session.getWorkspace().getVersionManager()
-                                               .checkin(userProfile.getPath());
-                               userAdminService().createUser(userDetails);
-                               return new JcrEndUser(userDetails);
-                       } else if (Role.GROUP == type) {
-                               userAdminService().newRole(name);
-                               return new JcrGroup(name);
-                       } else {
-                               throw new ArgeoException("Unsupported role type " + type);
-                       }
-               } catch (RepositoryException e) {
-                       throw new ArgeoException("Cannot create role " + name);
+               if (Role.USER == type) {
+                       NewUserDetails userDetails = new NewUserDetails(name, null);
+                       userAdminService().createUser(userDetails);
+                       return new JcrEndUser((JcrUserDetails) userAdminService()
+                                       .loadUserByUsername(name));
+               } else if (Role.GROUP == type) {
+                       userAdminService().newRole(name);
+                       return new JcrGroup(name);
+               } else {
+                       throw new ArgeoException("Unsupported role type " + type);
                }
        }
 
@@ -122,7 +112,7 @@ public class JcrUserAdmin implements UserAdmin {
 
        @Override
        public User getUser(String key, String value) {
-               throw new ArgeoException("Property based search not yet implemented");
+               throw new CmsException("Property based search not yet implemented");
        }
 
        @Override
@@ -134,7 +124,7 @@ public class JcrUserAdmin implements UserAdmin {
                return userAdminService;
        }
 
-       public void setUserAdminService(UserAdminService userAdminService) {
+       public void setUserAdminService(JackrabbitUserAdminService userAdminService) {
                this.userAdminService = userAdminService;
        }
 
index 029719c3a858f2236a79a4db819f4a106389da47..c39f9e56d105c9b15b249eb02b24ba0eb8a5d5bc 100644 (file)
@@ -22,17 +22,16 @@ import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.Value;
 import javax.jcr.security.Privilege;
-import javax.jcr.version.VersionManager;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
+import org.argeo.cms.internal.auth.JcrSecurityModel;
 import org.argeo.jcr.ArgeoJcrConstants;
 import org.argeo.jcr.ArgeoNames;
 import org.argeo.jcr.ArgeoTypes;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.jcr.UserJcrUtils;
-import org.argeo.security.jcr.JcrSecurityModel;
 
 /**
  * Manages data expected by the Argeo security model, such as user home and
@@ -78,6 +77,7 @@ public class SimpleJcrSecurityModel implements JcrSecurityModel {
                        }
 
                        Node userProfile = UserJcrUtils.getUserProfile(session, username);
+                       // new user
                        if (userProfile == null) {
                                String personPath = generateUserPath(
                                                ArgeoJcrConstants.PEOPLE_BASE_PATH, username);
@@ -98,12 +98,6 @@ public class SimpleJcrSecurityModel implements JcrSecurityModel {
                                                username);
                                JcrUtils.addPrivilege(session, userProfile.getPath(), username,
                                                Privilege.JCR_READ);
-
-                               VersionManager versionManager = session.getWorkspace()
-                                               .getVersionManager();
-                               if (versionManager.isCheckedOut(userProfile.getPath()))
-                                       versionManager.checkin(userProfile.getPath());
-
                        }
 
                        // Remote roles
index f846e1c7450223e259c9aaba62dead1da37661be..e7f44943b08501bb43b5daab506c8ea3a01859af 100644 (file)
@@ -12,6 +12,7 @@ import javax.jcr.Repository;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
+import javax.jcr.version.VersionManager;
 
 import org.apache.jackrabbit.api.JackrabbitSession;
 import org.apache.jackrabbit.api.security.user.Authorizable;
@@ -20,13 +21,14 @@ import org.apache.jackrabbit.api.security.user.User;
 import org.apache.jackrabbit.api.security.user.UserManager;
 import org.apache.jackrabbit.core.security.authentication.CryptedSimpleCredentials;
 import org.argeo.ArgeoException;
+import org.argeo.cms.internal.auth.GrantedAuthorityPrincipal;
+import org.argeo.cms.internal.auth.JcrSecurityModel;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.jcr.UserJcrUtils;
 import org.argeo.security.NodeAuthenticationToken;
 import org.argeo.security.UserAdminService;
-import org.argeo.cms.internal.auth.GrantedAuthorityPrincipal;
-import org.argeo.security.jcr.JcrSecurityModel;
 import org.argeo.security.jcr.JcrUserDetails;
+import org.argeo.security.jcr.NewUserDetails;
 import org.springframework.dao.DataAccessException;
 import org.springframework.security.authentication.AuthenticationProvider;
 import org.springframework.security.authentication.BadCredentialsException;
@@ -87,13 +89,21 @@ public class JackrabbitUserAdminService implements UserAdminService,
        @Override
        public void createUser(UserDetails user) {
                try {
-                       // FIXME workaround for issue in new user wizard where
-                       // security model is hardcoded and it already exists
-                       if (getUserManager().getAuthorizable(user.getUsername()) == null) {
-                               getUserManager().createUser(user.getUsername(),
-                                               user.getPassword());
-                               securityModel.sync(adminSession, user.getUsername(), null);
-                       }
+                       // if (getUserManager().getAuthorizable(user.getUsername()) == null)
+                       // {
+                       getUserManager().createUser(user.getUsername(), user.getPassword());
+                       Node userProfile = securityModel.sync(adminSession,
+                                       user.getUsername(), null);
+                       if (user instanceof NewUserDetails)
+                               ((NewUserDetails) user).mapToProfileNode(userProfile);
+                       userProfile.getSession().save();
+
+                       // check in node
+                       VersionManager versionManager = userProfile.getSession()
+                                       .getWorkspace().getVersionManager();
+                       if (versionManager.isCheckedOut(userProfile.getPath()))
+                               versionManager.checkin(userProfile.getPath());
+                       // }
                        updateUser(user);
                } catch (RepositoryException e) {
                        throw new ArgeoException("Cannot create user " + user, e);
index de28c7f496f81582793ba5fed973c439c3876f1c..ce8b37337be0b0782689c554f72967461440ad4d 100644 (file)
@@ -41,12 +41,12 @@ import javax.naming.directory.ModificationItem;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
+import org.argeo.cms.internal.auth.JcrSecurityModel;
 import org.argeo.cms.internal.useradmin.SimpleJcrSecurityModel;
 import org.argeo.jcr.ArgeoNames;
 import org.argeo.jcr.ArgeoTypes;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.security.SecurityUtils;
-import org.argeo.security.jcr.JcrSecurityModel;
 import org.argeo.security.jcr.JcrUserDetails;
 import org.springframework.ldap.core.ContextMapper;
 import org.springframework.ldap.core.DirContextAdapter;
diff --git a/org.argeo.cms/src/org/argeo/cms/users/MainUserInfoWizardPage.java b/org.argeo.cms/src/org/argeo/cms/users/MainUserInfoWizardPage.java
new file mode 100644 (file)
index 0000000..fc127ad
--- /dev/null
@@ -0,0 +1,134 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.cms.users;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+
+import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.jcr.ArgeoNames;
+import org.argeo.security.UserAdminService;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+
+public class MainUserInfoWizardPage extends WizardPage implements
+               ModifyListener, ArgeoNames {
+       private static final long serialVersionUID = -3367329974808698649L;
+       private Text username, firstName, lastName, primaryEmail, password1,
+                       password2;
+       private UserAdminService userAdminService;
+
+       public MainUserInfoWizardPage(UserAdminService userAdminService) {
+               super("Main");
+               this.userAdminService = userAdminService;
+               setTitle("Required Information");
+       }
+
+       @Override
+       public void createControl(Composite parent) {
+               Composite composite = new Composite(parent, SWT.NONE);
+               composite.setLayout(new GridLayout(2, false));
+               username = EclipseUiUtils.createGridLT(composite, "Username", this);
+               primaryEmail = EclipseUiUtils.createGridLT(composite, "Email", this);
+               firstName = EclipseUiUtils.createGridLT(composite, "First name", this);
+               lastName = EclipseUiUtils.createGridLT(composite, "Last name", this);
+               password1 = EclipseUiUtils.createGridLP(composite, "Password", this);
+               password2 = EclipseUiUtils.createGridLP(composite, "Repeat password",
+                               this);
+               setControl(composite);
+
+               // Initialize buttons
+               setPageComplete(false);
+               getContainer().updateButtons();
+       }
+
+       @Override
+       public void modifyText(ModifyEvent event) {
+               String message = checkComplete();
+               if (message != null) {
+                       setMessage(message, WizardPage.ERROR);
+                       setPageComplete(false);
+               } else {
+                       setMessage("Complete", WizardPage.INFORMATION);
+                       setPageComplete(true);
+               }
+               getContainer().updateButtons();
+       }
+
+       /** @return error message or null if complete */
+       protected String checkComplete() {
+               // if (!username.getText().matches(UserAdminService.USERNAME_PATTERN))
+               // return
+               // "Wrong user name format, should be lower case, between 3 and 64 characters with only '_' an '@' as acceptable special character.";
+
+               if (username.getText().trim().equals(""))
+                       return "User name must not be empty";
+
+               try {
+                       UserDetails userDetails = userAdminService
+                                       .loadUserByUsername(username.getText());
+                       return "User " + userDetails.getUsername() + " already exists";
+               } catch (UsernameNotFoundException e) {
+                       // silent
+               }
+               if (!primaryEmail.getText().matches(UserAdminService.EMAIL_PATTERN))
+                       return "Not a valid email address";
+               if (firstName.getText().trim().equals(""))
+                       return "Specify a first name";
+               if (lastName.getText().trim().equals(""))
+                       return "Specify a last name";
+               if (password1.getText().trim().equals(""))
+                       return "Specify a password";
+               if (password2.getText().trim().equals(""))
+                       return "Repeat the password";
+               if (!password2.getText().equals(password1.getText()))
+                       return "Passwords are different";
+               return null;
+       }
+
+       public String getUsername() {
+               return username.getText();
+       }
+
+       public char[] getPassword() {
+               return password1.getTextChars();
+       }
+
+       public void mapToProfileNode(Node up) {
+               try {
+                       up.setProperty(ARGEO_PRIMARY_EMAIL, primaryEmail.getText());
+                       up.setProperty(ARGEO_FIRST_NAME, firstName.getText());
+                       up.setProperty(ARGEO_LAST_NAME, lastName.getText());
+
+                       // derived values
+                       // TODO add wizard pages to do it
+                       up.setProperty(Property.JCR_TITLE, firstName.getText() + " "
+                                       + lastName.getText());
+                       up.setProperty(Property.JCR_DESCRIPTION, "");
+               } catch (RepositoryException e) {
+                       throw new ArgeoException("Cannot map to " + up, e);
+               }
+       }
+}
diff --git a/org.argeo.cms/src/org/argeo/cms/users/NewUserWizard.java b/org.argeo.cms/src/org/argeo/cms/users/NewUserWizard.java
new file mode 100644 (file)
index 0000000..ca81749
--- /dev/null
@@ -0,0 +1,106 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.cms.users;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.UserJcrUtils;
+import org.argeo.security.UserAdminService;
+import org.argeo.security.jcr.NewUserDetails;
+import org.eclipse.jface.wizard.Wizard;
+
+/** Wizard to create a new user */
+public class NewUserWizard extends Wizard {
+       private final static Log log = LogFactory.getLog(NewUserWizard.class);
+       private Session session;
+       private UserAdminService userAdminService;
+       // private JcrSecurityModel jcrSecurityModel;
+
+       // pages
+       private MainUserInfoWizardPage mainUserInfo;
+
+       public NewUserWizard(Session session, UserAdminService userAdminService) {
+               this.session = session;
+               this.userAdminService = userAdminService;
+               // this.jcrSecurityModel = jcrSecurityModel;
+       }
+
+       @Override
+       public void addPages() {
+               mainUserInfo = new MainUserInfoWizardPage(userAdminService);
+               addPage(mainUserInfo);
+       }
+
+       @Override
+       public boolean performFinish() {
+               if (!canFinish())
+                       return false;
+
+               String username = mainUserInfo.getUsername();
+               try {
+                       // Node userProfile = SecurityJcrUtils.createUserProfile(session,
+                       // username);
+                       // Node userProfile = jcrSecurityModel.sync(session, username,
+                       // null);
+                       // session.getWorkspace().getVersionManager()
+                       // .checkout(userProfile.getPath());
+                       // mainUserInfo.mapToProfileNode(userProfile);
+                       char[] password = mainUserInfo.getPassword();
+                       // TODO add roles
+                       NewUserDetails jcrUserDetails = new NewUserDetails(username,
+                                       password) {
+                               private static final long serialVersionUID = 7480071525603380742L;
+
+                               @Override
+                               public void mapToProfileNode(Node userProfile)
+                                               throws RepositoryException {
+                                       mainUserInfo.mapToProfileNode(userProfile);
+                               }
+                       };
+                       // session.save();
+                       // session.getWorkspace().getVersionManager()
+                       // .checkin(userProfile.getPath());
+                       userAdminService.createUser(jcrUserDetails);
+                       return true;
+               } catch (Exception e) {
+                       JcrUtils.discardQuietly(session);
+                       Node userHome = UserJcrUtils.getUserHome(session, username);
+                       if (userHome != null) {
+                               try {
+                                       userHome.remove();
+                                       session.save();
+                               } catch (RepositoryException e1) {
+                                       JcrUtils.discardQuietly(session);
+                                       log.warn("Error when trying to clean up failed new user "
+                                                       + username, e1);
+                               }
+                       }
+                       ErrorFeedback.show("Cannot create new user " + username, e);
+                       return false;
+               }
+       }
+
+       public void setSession(Session session) {
+               this.session = session;
+       }
+
+}
diff --git a/org.argeo.cms/src/org/argeo/cms/users/UserCreationWizard.java b/org.argeo.cms/src/org/argeo/cms/users/UserCreationWizard.java
new file mode 100644 (file)
index 0000000..6ffd224
--- /dev/null
@@ -0,0 +1,220 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.cms.users;
+
+import java.util.ArrayList;
+
+import javax.jcr.Node;
+import javax.jcr.Property;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.argeo.ArgeoException;
+import org.argeo.cms.internal.auth.JcrSecurityModel;
+import org.argeo.eclipse.ui.EclipseUiUtils;
+import org.argeo.jcr.ArgeoNames;
+import org.argeo.jcr.JcrUtils;
+import org.argeo.jcr.UserJcrUtils;
+import org.argeo.security.UserAdminService;
+import org.argeo.security.jcr.JcrUserDetails;
+import org.eclipse.jface.dialogs.MessageDialog;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.jface.wizard.WizardPage;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.events.ModifyEvent;
+import org.eclipse.swt.events.ModifyListener;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Text;
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.userdetails.UserDetails;
+import org.springframework.security.core.userdetails.UsernameNotFoundException;
+
+/** Wizard to create a new user */
+@Deprecated
+class UserCreationWizard extends Wizard {
+       private final static Log log = LogFactory.getLog(UserCreationWizard.class);
+       private Session session;
+       private UserAdminService userAdminService;
+       private JcrSecurityModel jcrSecurityModel;
+
+       // pages
+       private MainUserInfoWizardPage mainUserInfo;
+
+       public UserCreationWizard(Session session,
+                       UserAdminService userAdminService, JcrSecurityModel jcrSecurityModel) {
+               this.session = session;
+               this.userAdminService = userAdminService;
+               this.jcrSecurityModel = jcrSecurityModel;
+       }
+
+       @Override
+       public void addPages() {
+               mainUserInfo = new MainUserInfoWizardPage(userAdminService);
+               addPage(mainUserInfo);
+       }
+
+       @Override
+       public boolean performFinish() {
+               if (!canFinish())
+                       return false;
+
+               String username = mainUserInfo.getUsername();
+               try {
+                       Node userProfile = jcrSecurityModel.sync(session, username, null);
+                       session.getWorkspace().getVersionManager()
+                                       .checkout(userProfile.getPath());
+                       mainUserInfo.mapToProfileNode(userProfile);
+                       String password = mainUserInfo.getPassword();
+                       // TODO add roles
+                       JcrUserDetails jcrUserDetails = new JcrUserDetails(userProfile,
+                                       password, new ArrayList<GrantedAuthority>());
+                       session.save();
+                       session.getWorkspace().getVersionManager()
+                                       .checkin(userProfile.getPath());
+                       userAdminService.createUser(jcrUserDetails);
+                       return true;
+               } catch (Exception e) {
+                       JcrUtils.discardQuietly(session);
+                       Node userHome = UserJcrUtils.getUserHome(session, username);
+                       if (userHome != null) {
+                               try {
+                                       userHome.remove();
+                                       session.save();
+                               } catch (RepositoryException e1) {
+                                       JcrUtils.discardQuietly(session);
+                                       log.warn("Error when trying to clean up failed new user "
+                                                       + username, e1);
+                               }
+                       }
+                       // FIXME re-get ErrorFeedback dialog after single sourcing
+                       // refactoring
+                       MessageDialog.openError(getShell(), "Error",
+                                       "Cannot create new user " + username);
+                       log.error("Cannot create new user " + username);
+                       e.printStackTrace();
+                       return false;
+               }
+       }
+
+       /** First page, collect all main info and check their validity */
+       protected class MainUserInfoWizardPage extends WizardPage implements
+                       ModifyListener, ArgeoNames {
+               private static final long serialVersionUID = -3367329974808698649L;
+               private Text username, firstName, lastName, primaryEmail, password1,
+                               password2;
+               private UserAdminService userAdminService;
+
+               public MainUserInfoWizardPage(UserAdminService userAdminService) {
+                       super("Main");
+                       this.userAdminService = userAdminService;
+                       setTitle("Required Information");
+               }
+
+               @Override
+               public void createControl(Composite parent) {
+                       Composite composite = new Composite(parent, SWT.NONE);
+                       composite.setLayout(new GridLayout(2, false));
+                       username = EclipseUiUtils.createGridLT(composite, "Username", this);
+                       primaryEmail = EclipseUiUtils
+                                       .createGridLT(composite, "Email", this);
+                       firstName = EclipseUiUtils.createGridLT(composite, "First name",
+                                       this);
+                       lastName = EclipseUiUtils
+                                       .createGridLT(composite, "Last name", this);
+                       password1 = EclipseUiUtils
+                                       .createGridLP(composite, "Password", this);
+                       password2 = EclipseUiUtils.createGridLP(composite,
+                                       "Repeat password", this);
+                       setControl(composite);
+
+                       // Initialize buttons
+                       setPageComplete(false);
+                       getContainer().updateButtons();
+               }
+
+               @Override
+               public void modifyText(ModifyEvent event) {
+                       String message = checkComplete();
+                       if (message != null) {
+                               setMessage(message, WizardPage.ERROR);
+                               setPageComplete(false);
+                       } else {
+                               setMessage("Complete", WizardPage.INFORMATION);
+                               setPageComplete(true);
+                       }
+                       getContainer().updateButtons();
+               }
+
+               /** @return error message or null if complete */
+               protected String checkComplete() {
+                       // if
+                       // (!username.getText().matches(UserAdminService.USERNAME_PATTERN))
+                       // return
+                       // "Wrong user name format, should be lower case, between 3 and 64 characters with only '_' an '@' as acceptable special character.";
+
+                       if (username.getText().trim().equals(""))
+                               return "User name must not be empty";
+
+                       try {
+                               UserDetails userDetails = userAdminService
+                                               .loadUserByUsername(username.getText());
+                               return "User " + userDetails.getUsername() + " already exists";
+                       } catch (UsernameNotFoundException e) {
+                               // silent
+                       }
+                       if (!primaryEmail.getText().matches(UserAdminService.EMAIL_PATTERN))
+                               return "Not a valid email address";
+                       if (firstName.getText().trim().equals(""))
+                               return "Specify a first name";
+                       if (lastName.getText().trim().equals(""))
+                               return "Specify a last name";
+                       if (password1.getText().trim().equals(""))
+                               return "Specify a password";
+                       if (password2.getText().trim().equals(""))
+                               return "Repeat the password";
+                       if (!password2.getText().equals(password1.getText()))
+                               return "Passwords are different";
+                       return null;
+               }
+
+               public String getUsername() {
+                       return username.getText();
+               }
+
+               public String getPassword() {
+                       return password1.getText();
+               }
+
+               public void mapToProfileNode(Node up) {
+                       try {
+                               up.setProperty(ARGEO_PRIMARY_EMAIL, primaryEmail.getText());
+                               up.setProperty(ARGEO_FIRST_NAME, firstName.getText());
+                               up.setProperty(ARGEO_LAST_NAME, lastName.getText());
+
+                               // derived values
+                               // TODO add wizard pages to do it
+                               up.setProperty(Property.JCR_TITLE, firstName.getText() + " "
+                                               + lastName.getText());
+                               up.setProperty(Property.JCR_DESCRIPTION, "");
+                       } catch (RepositoryException e) {
+                               throw new ArgeoException("Cannot map to " + up, e);
+                       }
+               }
+       }
+}
\ No newline at end of file
index f4acb8a9d410b23566e3a5e642711c3b3f9c61af..2da98a38d67eee4e4761a7ee6991c5152fa0da81 100644 (file)
@@ -7,13 +7,13 @@ import javax.jcr.Item;
 import javax.jcr.RepositoryException;
 
 import org.argeo.ArgeoException;
+import org.argeo.cms.internal.auth.JcrSecurityModel;
 import org.argeo.cms.util.CmsUtils;
 import org.argeo.cms.viewers.EditablePart;
 import org.argeo.cms.viewers.NodePart;
 import org.argeo.cms.widgets.StyledControl;
 import org.argeo.jcr.ArgeoNames;
 import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrSecurityModel;
 import org.argeo.security.jcr.JcrUserDetails;
 import org.eclipse.jface.viewers.CheckStateChangedEvent;
 import org.eclipse.jface.viewers.CheckboxTableViewer;
index c5f0c7ee5045dea682b700cea14540b0e9fe802c..2637ed4d9afeeb923af00e3a6bb3a829805c0071 100644 (file)
@@ -16,12 +16,10 @@ import org.argeo.ArgeoException;
 import org.argeo.cms.CmsUiProvider;
 import org.argeo.cms.maintenance.NonAdminPage;
 import org.argeo.cms.util.CmsUtils;
-import org.argeo.eclipse.ui.dialogs.UserCreationWizard;
 import org.argeo.eclipse.ui.parts.UsersTable;
 import org.argeo.jcr.ArgeoNames;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrSecurityModel;
 import org.eclipse.jface.dialogs.Dialog;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.viewers.ISelection;
@@ -52,7 +50,6 @@ public class Users implements CmsUiProvider {
 
        // Enable user CRUD // INJECTED
        private UserAdminService userAdminService;
-       private JcrSecurityModel jcrSecurityModel;
        // private UserDetailsManager userDetailsManager;
        private String userWkspName;
 
@@ -216,8 +213,8 @@ public class Users implements CmsUiProvider {
 
                        @Override
                        public void widgetSelected(SelectionEvent e) {
-                               UserCreationWizard newUserWizard = new UserCreationWizard(
-                                               session, userAdminService, jcrSecurityModel);
+                               NewUserWizard newUserWizard = new NewUserWizard(session,
+                                               userAdminService);
                                WizardDialog dialog = new WizardDialog(addBtn.getShell(),
                                                newUserWizard);
                                if (dialog.open() == Dialog.OK)
@@ -340,11 +337,6 @@ public class Users implements CmsUiProvider {
                userPage.setUserAdminService(userAdminService);
        }
 
-       public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
-               this.jcrSecurityModel = jcrSecurityModel;
-               // userPage.setJcrSecurityModel(jcrSecurityModel);
-       }
-
        public void setUserDetailsManager(UserDetailsManager userDetailsManager) {
                // this.userDetailsManager = userDetailsManager;
                // userPage.setUserDetailsManager(userDetailsManager);
index 9a5482584b5e7576f37adbac5e3470da59f3ed74..e7e9c3bd8d5e3ad391721af01cdb87cc5db7ded6 100644 (file)
  */
 package org.argeo.eclipse.ui.workbench;
 
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.eclipse.jface.dialogs.IMessageProvider;
-import org.eclipse.jface.dialogs.TitleAreaDialog;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.graphics.Point;
-import org.eclipse.swt.layout.GridData;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Control;
-import org.eclipse.swt.widgets.Display;
 import org.eclipse.swt.widgets.Shell;
-import org.eclipse.swt.widgets.Text;
-import org.eclipse.ui.PlatformUI;
-
-/** Generic error dialog to be used in try/catch blocks */
-public class ErrorFeedback extends TitleAreaDialog {
-       private static final long serialVersionUID = -8918084784628179044L;
-
-       private final static Log log = LogFactory.getLog(ErrorFeedback.class);
-
-       private final String message;
-       private final Throwable exception;
-
-       public static void show(String message, Throwable e) {
-               // rethrow ThreaDeath in order to make sure that RAP will properly clean
-               // up the UI thread
-               if (e instanceof ThreadDeath)
-                       throw (ThreadDeath) e;
-
-               new ErrorFeedback(getDisplay().getActiveShell(), message, e).open();
-       }
-
-       public static void show(String message) {
-               new ErrorFeedback(getDisplay().getActiveShell(), message, null).open();
-       }
 
-       /** Tries to find a display */
-       private static Display getDisplay() {
-               try {
-                       Display display = PlatformUI.getWorkbench().getDisplay();
-                       if (display != null)
-                               return display;
-                       else
-                               return Display.getDefault();
-               } catch (Exception e) {
-                       return Display.getCurrent();
-               }
-       }
+/** @deprecated Use {@link org.argeo.eclipse.ui.dialogs.ErrorFeedback} instead. */
+@Deprecated
+public class ErrorFeedback extends org.argeo.eclipse.ui.dialogs.ErrorFeedback {
+       private static final long serialVersionUID = 5346084648745909554L;
 
        public ErrorFeedback(Shell parentShell, String message, Throwable e) {
-               super(parentShell);
-               this.message = message;
-               this.exception = e;
-               log.error(message, e);
-       }
-
-       protected Point getInitialSize() {
-               if (exception != null)
-                       return new Point(800, 600);
-               else
-                       return new Point(400, 300);
+               super(parentShell, message, e);
        }
 
-       @Override
-       protected Control createDialogArea(Composite parent) {
-               Composite dialogarea = (Composite) super.createDialogArea(parent);
-               dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-               Composite composite = new Composite(dialogarea, SWT.NONE);
-               composite.setLayout(new GridLayout(2, false));
-               composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-
-               setMessage(message != null ? message
-                               + (exception != null ? ": " + exception.getMessage() : "")
-                               : exception != null ? exception.getMessage() : "Unkown Error",
-                               IMessageProvider.ERROR);
-
-               if (exception != null) {
-                       Text stack = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER
-                                       | SWT.V_SCROLL | SWT.H_SCROLL);
-                       stack.setEditable(false);
-                       stack.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
-                       StringWriter sw = new StringWriter();
-                       exception.printStackTrace(new PrintWriter(sw));
-                       stack.setText(sw.toString());
-               }
-
-               parent.pack();
-               return composite;
-       }
-
-       protected void configureShell(Shell shell) {
-               super.configureShell(shell);
-               shell.setText("Error");
-       }
 }
\ No newline at end of file
index 291df2ccc40cf56ca72c20d4877a5e6f289f0ed8..c396b72155e11ab91d23756085f38933152cc2de 100644 (file)
@@ -20,8 +20,8 @@ import javax.jcr.RepositoryException;
 import javax.jcr.nodetype.NodeType;
 
 import org.argeo.eclipse.ui.TreeParent;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.dialogs.SingleValue;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
 import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
 import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
index 7100d8f1850e4d293ccc3b3eaa1a547b21892884..684fea65539981c2e2e20d25a7a248c813707c45 100644 (file)
@@ -20,7 +20,7 @@ import javax.jcr.RepositoryException;
 
 import org.argeo.ArgeoException;
 import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
 import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
 import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
index 50e28617924eb7651781cde5cc1da77e925d9e09..6ed419f0436372deaf4d8e8363fc152c5871f012 100644 (file)
@@ -25,8 +25,8 @@ import javax.jcr.Session;
 import javax.jcr.SimpleCredentials;
 
 import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.CommandUtils;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.WorkbenchConstants;
 import org.argeo.jcr.ArgeoJcrConstants;
 import org.argeo.jcr.ArgeoNames;
index 82db513219baa561859cabcef51c08619f1d2b08..cd9e402eee97fc8f2c68fa5540bf65541f30add5 100644 (file)
@@ -17,8 +17,8 @@ package org.argeo.eclipse.ui.workbench.commands;
 
 import java.util.Arrays;
 
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.dialogs.SingleValue;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
 import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
 import org.argeo.eclipse.ui.workbench.jcr.internal.model.RepositoryElem;
index ff05c631f3eb8dccf9f92bf342492e5a87da5934..8a5b9d6e4062a862596bd5a9942f26f3da94dd6f 100644 (file)
@@ -22,7 +22,7 @@ import javax.jcr.RepositoryException;
 
 import org.argeo.ArgeoException;
 import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
 import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
 import org.argeo.eclipse.ui.workbench.jcr.internal.model.WorkspaceElem;
index 4c9553484401fb6cde919fbbfc260dd460453209..12a582291895689c8cb03268e472047e1c795fe9 100644 (file)
@@ -21,7 +21,7 @@ import java.util.Map;
 import javax.jcr.Property;
 import javax.jcr.nodetype.NodeType;
 
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.jcr.internal.parts.NodeEditorInput;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
index 1caf114823dbb528c5b42fb3238c7a3c06b63c9f..2269644055dc023f96944b118311237717369108 100644 (file)
@@ -21,7 +21,7 @@ import java.util.List;
 
 import javax.jcr.Node;
 
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
index fa2da1dc535310e80f87f827da39a7f80351aad0..7b3be896592abbe6fe22ec42aae7257adc38ac72 100644 (file)
@@ -18,7 +18,7 @@ package org.argeo.eclipse.ui.workbench.commands;
 import javax.jcr.Node;
 
 import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.workbench.WorkbenchUiPlugin;
 import org.argeo.eclipse.ui.workbench.jcr.JcrBrowserView;
 import org.argeo.eclipse.ui.workbench.jcr.internal.model.SingleJcrNodeElem;
index c0fc0c5e4bc98379016ba134742ef0662ffc4e8f..1e1469bb809000b8ad8a61728ffeb1bde706757f 100644 (file)
@@ -26,7 +26,7 @@ import javax.jcr.Session;
 
 import org.argeo.ArgeoException;
 import org.argeo.eclipse.ui.TreeParent;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.jcr.ArgeoNames;
 import org.argeo.jcr.MaintainedRepository;
 import org.argeo.jcr.RepositoryRegister;
index eea9f72c3ffc9ec5abd3690f691aab0d9ffad8be..871b73ad69f69b77ee9c8e412fd475242d8e19fb 100644 (file)
@@ -29,8 +29,8 @@ import org.apache.commons.io.IOUtils;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.eclipse.ui.specific.UploadFileWizardPage;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
 import org.eclipse.core.runtime.IProgressMonitor;
 import org.eclipse.jface.dialogs.MessageDialog;
 import org.eclipse.jface.operation.IRunnableWithProgress;
diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/ErrorFeedback.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/ErrorFeedback.java
new file mode 100644 (file)
index 0000000..1834684
--- /dev/null
@@ -0,0 +1,115 @@
+/*
+ * Copyright (C) 2007-2012 Argeo GmbH
+ *
+ * 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.eclipse.ui.dialogs;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.eclipse.jface.dialogs.IMessageProvider;
+import org.eclipse.jface.dialogs.TitleAreaDialog;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Point;
+import org.eclipse.swt.layout.GridData;
+import org.eclipse.swt.layout.GridLayout;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Control;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+
+/** Generic error dialog to be used in try/catch blocks */
+public class ErrorFeedback extends TitleAreaDialog {
+       private static final long serialVersionUID = -8918084784628179044L;
+
+       private final static Log log = LogFactory.getLog(ErrorFeedback.class);
+
+       private final String message;
+       private final Throwable exception;
+
+       public static void show(String message, Throwable e) {
+               // rethrow ThreaDeath in order to make sure that RAP will properly clean
+               // up the UI thread
+               if (e instanceof ThreadDeath)
+                       throw (ThreadDeath) e;
+
+               new ErrorFeedback(getDisplay().getActiveShell(), message, e).open();
+       }
+
+       public static void show(String message) {
+               new ErrorFeedback(getDisplay().getActiveShell(), message, null).open();
+       }
+
+       /** Tries to find a display */
+       private static Display getDisplay() {
+               try {
+                       Display display = Display.getCurrent();
+                       if (display != null)
+                               return display;
+                       else
+                               return Display.getDefault();
+               } catch (Exception e) {
+                       return Display.getCurrent();
+               }
+       }
+
+       public ErrorFeedback(Shell parentShell, String message, Throwable e) {
+               super(parentShell);
+               this.message = message;
+               this.exception = e;
+               log.error(message, e);
+       }
+
+       protected Point getInitialSize() {
+               if (exception != null)
+                       return new Point(800, 600);
+               else
+                       return new Point(400, 300);
+       }
+
+       @Override
+       protected Control createDialogArea(Composite parent) {
+               Composite dialogarea = (Composite) super.createDialogArea(parent);
+               dialogarea.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+               Composite composite = new Composite(dialogarea, SWT.NONE);
+               composite.setLayout(new GridLayout(2, false));
+               composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+
+               setMessage(message != null ? message
+                               + (exception != null ? ": " + exception.getMessage() : "")
+                               : exception != null ? exception.getMessage() : "Unkown Error",
+                               IMessageProvider.ERROR);
+
+               if (exception != null) {
+                       Text stack = new Text(composite, SWT.MULTI | SWT.LEAD | SWT.BORDER
+                                       | SWT.V_SCROLL | SWT.H_SCROLL);
+                       stack.setEditable(false);
+                       stack.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
+                       StringWriter sw = new StringWriter();
+                       exception.printStackTrace(new PrintWriter(sw));
+                       stack.setText(sw.toString());
+               }
+
+               parent.pack();
+               return composite;
+       }
+
+       protected void configureShell(Shell shell) {
+               super.configureShell(shell);
+               shell.setText("Error");
+       }
+}
\ No newline at end of file
diff --git a/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/UserCreationWizard.java b/org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/dialogs/UserCreationWizard.java
deleted file mode 100644 (file)
index ac7f0ce..0000000
+++ /dev/null
@@ -1,219 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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.eclipse.ui.dialogs;
-
-import java.util.ArrayList;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.EclipseUiUtils;
-import org.argeo.jcr.ArgeoNames;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.jcr.UserJcrUtils;
-import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrSecurityModel;
-import org.argeo.security.jcr.JcrUserDetails;
-import org.eclipse.jface.dialogs.MessageDialog;
-import org.eclipse.jface.wizard.Wizard;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
-import org.springframework.security.core.GrantedAuthority;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UsernameNotFoundException;
-
-/** Wizard to create a new user */
-public class UserCreationWizard extends Wizard {
-       private final static Log log = LogFactory.getLog(UserCreationWizard.class);
-       private Session session;
-       private UserAdminService userAdminService;
-       private JcrSecurityModel jcrSecurityModel;
-
-       // pages
-       private MainUserInfoWizardPage mainUserInfo;
-
-       public UserCreationWizard(Session session,
-                       UserAdminService userAdminService, JcrSecurityModel jcrSecurityModel) {
-               this.session = session;
-               this.userAdminService = userAdminService;
-               this.jcrSecurityModel = jcrSecurityModel;
-       }
-
-       @Override
-       public void addPages() {
-               mainUserInfo = new MainUserInfoWizardPage(userAdminService);
-               addPage(mainUserInfo);
-       }
-
-       @Override
-       public boolean performFinish() {
-               if (!canFinish())
-                       return false;
-
-               String username = mainUserInfo.getUsername();
-               try {
-                       Node userProfile = jcrSecurityModel.sync(session, username, null);
-                       session.getWorkspace().getVersionManager()
-                                       .checkout(userProfile.getPath());
-                       mainUserInfo.mapToProfileNode(userProfile);
-                       String password = mainUserInfo.getPassword();
-                       // TODO add roles
-                       JcrUserDetails jcrUserDetails = new JcrUserDetails(userProfile,
-                                       password, new ArrayList<GrantedAuthority>());
-                       session.save();
-                       session.getWorkspace().getVersionManager()
-                                       .checkin(userProfile.getPath());
-                       userAdminService.createUser(jcrUserDetails);
-                       return true;
-               } catch (Exception e) {
-                       JcrUtils.discardQuietly(session);
-                       Node userHome = UserJcrUtils.getUserHome(session, username);
-                       if (userHome != null) {
-                               try {
-                                       userHome.remove();
-                                       session.save();
-                               } catch (RepositoryException e1) {
-                                       JcrUtils.discardQuietly(session);
-                                       log.warn("Error when trying to clean up failed new user "
-                                                       + username, e1);
-                               }
-                       }
-                       // FIXME re-get ErrorFeedback dialog after single sourcing
-                       // refactoring
-                       MessageDialog.openError(getShell(), "Error",
-                                       "Cannot create new user " + username);
-                       log.error("Cannot create new user " + username);
-                       e.printStackTrace();
-                       return false;
-               }
-       }
-
-       /** First page, collect all main info and check their validity */
-       protected class MainUserInfoWizardPage extends WizardPage implements
-                       ModifyListener, ArgeoNames {
-               private static final long serialVersionUID = -3367329974808698649L;
-               private Text username, firstName, lastName, primaryEmail, password1,
-                               password2;
-               private UserAdminService userAdminService;
-
-               public MainUserInfoWizardPage(UserAdminService userAdminService) {
-                       super("Main");
-                       this.userAdminService = userAdminService;
-                       setTitle("Required Information");
-               }
-
-               @Override
-               public void createControl(Composite parent) {
-                       Composite composite = new Composite(parent, SWT.NONE);
-                       composite.setLayout(new GridLayout(2, false));
-                       username = EclipseUiUtils.createGridLT(composite, "Username", this);
-                       primaryEmail = EclipseUiUtils
-                                       .createGridLT(composite, "Email", this);
-                       firstName = EclipseUiUtils.createGridLT(composite, "First name",
-                                       this);
-                       lastName = EclipseUiUtils
-                                       .createGridLT(composite, "Last name", this);
-                       password1 = EclipseUiUtils
-                                       .createGridLP(composite, "Password", this);
-                       password2 = EclipseUiUtils.createGridLP(composite,
-                                       "Repeat password", this);
-                       setControl(composite);
-
-                       // Initialize buttons
-                       setPageComplete(false);
-                       getContainer().updateButtons();
-               }
-
-               @Override
-               public void modifyText(ModifyEvent event) {
-                       String message = checkComplete();
-                       if (message != null) {
-                               setMessage(message, WizardPage.ERROR);
-                               setPageComplete(false);
-                       } else {
-                               setMessage("Complete", WizardPage.INFORMATION);
-                               setPageComplete(true);
-                       }
-                       getContainer().updateButtons();
-               }
-
-               /** @return error message or null if complete */
-               protected String checkComplete() {
-                       // if
-                       // (!username.getText().matches(UserAdminService.USERNAME_PATTERN))
-                       // return
-                       // "Wrong user name format, should be lower case, between 3 and 64 characters with only '_' an '@' as acceptable special character.";
-
-                       if (username.getText().trim().equals(""))
-                               return "User name must not be empty";
-
-                       try {
-                               UserDetails userDetails = userAdminService
-                                               .loadUserByUsername(username.getText());
-                               return "User " + userDetails.getUsername() + " already exists";
-                       } catch (UsernameNotFoundException e) {
-                               // silent
-                       }
-                       if (!primaryEmail.getText().matches(UserAdminService.EMAIL_PATTERN))
-                               return "Not a valid email address";
-                       if (firstName.getText().trim().equals(""))
-                               return "Specify a first name";
-                       if (lastName.getText().trim().equals(""))
-                               return "Specify a last name";
-                       if (password1.getText().trim().equals(""))
-                               return "Specify a password";
-                       if (password2.getText().trim().equals(""))
-                               return "Repeat the password";
-                       if (!password2.getText().equals(password1.getText()))
-                               return "Passwords are different";
-                       return null;
-               }
-
-               public String getUsername() {
-                       return username.getText();
-               }
-
-               public String getPassword() {
-                       return password1.getText();
-               }
-
-               public void mapToProfileNode(Node up) {
-                       try {
-                               up.setProperty(ARGEO_PRIMARY_EMAIL, primaryEmail.getText());
-                               up.setProperty(ARGEO_FIRST_NAME, firstName.getText());
-                               up.setProperty(ARGEO_LAST_NAME, lastName.getText());
-
-                               // derived values
-                               // TODO add wizard pages to do it
-                               up.setProperty(Property.JCR_TITLE, firstName.getText() + " "
-                                               + lastName.getText());
-                               up.setProperty(Property.JCR_DESCRIPTION, "");
-                       } catch (RepositoryException e) {
-                               throw new ArgeoException("Cannot map to " + up, e);
-                       }
-               }
-       }
-}
\ No newline at end of file
diff --git a/org.argeo.security.core/src/org/argeo/security/jcr/JcrSecurityModel.java b/org.argeo.security.core/src/org/argeo/security/jcr/JcrSecurityModel.java
deleted file mode 100644 (file)
index a151c7f..0000000
+++ /dev/null
@@ -1,36 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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.jcr;
-
-import java.util.List;
-
-import javax.jcr.Node;
-import javax.jcr.Session;
-
-/**
- * Manages data expected by the Argeo security model, such as user home and
- * profile.
- */
-public interface JcrSecurityModel {
-       /**
-        * To be called before user details are loaded. Make sure than any logged in
-        * user has a home directory with full access and a profile with information
-        * about him (read access)
-        * 
-        * @return the user profile, never null
-        */
-       public Node sync(Session session, String username, List<String> roles);
-}
diff --git a/org.argeo.security.core/src/org/argeo/security/jcr/NewUserDetails.java b/org.argeo.security.core/src/org/argeo/security/jcr/NewUserDetails.java
new file mode 100644 (file)
index 0000000..2257e26
--- /dev/null
@@ -0,0 +1,41 @@
+package org.argeo.security.jcr;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.RepositoryException;
+
+import org.springframework.security.core.GrantedAuthority;
+import org.springframework.security.core.authority.SimpleGrantedAuthority;
+import org.springframework.security.core.userdetails.User;
+
+/** Used to create a new user */
+public class NewUserDetails extends User {
+       private static final long serialVersionUID = -8331941336984083297L;
+
+       public NewUserDetails(String username, char[] password) {
+               this(username, password, null);
+       }
+
+       public NewUserDetails(String username, char[] password, String[] roles) {
+               super(username, new String(password), false, false, false, false,
+                               rolesToAuthorities(roles));
+       }
+
+       /** To be overriden */
+       public void mapToProfileNode(Node userProfile) throws RepositoryException {
+               // does nothing by default
+       }
+
+       private static Collection<GrantedAuthority> rolesToAuthorities(
+                       String[] roles) {
+               List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
+               if (roles != null)
+                       for (String role : roles) {
+                               authorities.add(new SimpleGrantedAuthority(role));
+                       }
+               return authorities;
+       }
+}
index e0a435e07a11dda1b65ca8640be9685dd9a97610..f7a483f4c2f0927648bfbd780e3768c632803270 100644 (file)
@@ -13,7 +13,7 @@
                scope="prototype">
                <property name="repository" ref="nodeRepository" />
                <property name="userAdminService" ref="userAdminService" />
-               <property name="jcrSecurityModel" ref="jcrSecurityModel" />
+               <!-- <property name="jcrSecurityModel" ref="jcrSecurityModel" /> -->
        </bean>
 
        <bean id="refreshUsersList" class="org.argeo.security.ui.admin.commands.RefreshUsersList"
                scope="prototype">
                <property name="userAdminService" ref="userAdminService" />
        </bean>
-       
+
        <bean id="userBatchUpdate" class="org.argeo.security.ui.admin.commands.UserBatchUpdate"
                scope="prototype">
                <property name="repository" ref="nodeRepository" />
                <property name="userAdminService" ref="userAdminService" />
-               <property name="jcrSecurityModel" ref="jcrSecurityModel" />
        </bean>
-       
+
 
        <!-- ROLES -->
        <bean id="refreshRoles" class="org.argeo.security.ui.admin.commands.RefreshRoles"
index 737f30430f1de0eb82592c291808f9d754fd163f..1f6b56e3a918445eb8375ac250f413d6e9683c69 100644 (file)
                </property>\r
        </bean>\r
 \r
-       <!-- FIXME Hard-coded dependency to Jackrabbit for user management -->\r
-       <bean name="jcrSecurityModel" class="org.argeo.security.jackrabbit.JackrabbitSecurityModel" />\r
-\r
-       <!-- Old deprecated way. -->\r
-       <!-- <bean id="session" class="org.argeo.security.jcr.SecureThreadBoundSession"> \r
-               <property name="repository" ref="nodeRepository" /> </bean> -->\r
+       <!-- <bean name="jcrSecurityModel" class="org.argeo.security.jackrabbit.JackrabbitSecurityModel" \r
+               /> -->\r
 </beans>
\ No newline at end of file
index 2ddb05f60131011892f04cc286fddf5381ebb673..655b0c8e34468cf2c8ea58cd7b00b0993bf32bb1 100644 (file)
@@ -7,7 +7,6 @@
        <bean id="adminUsersView" class="org.argeo.security.ui.admin.views.UsersView"
                scope="prototype">
                <property name="repository" ref="nodeRepository" />
-               <!-- <property name="session" ref="session" />  -->
        </bean>
        
        <bean id="adminRolesView" class="org.argeo.security.ui.admin.views.RolesView"
index 968e602f96a5383970dbcf5eea989206ded501de..7d721beb05f3119605d90a99849023853c2f07c5 100644 (file)
@@ -1,20 +1,17 @@
 Bundle-SymbolicName: org.argeo.security.ui.admin;singleton:=true
-
 Bundle-Activator: org.argeo.security.ui.admin.SecurityAdminPlugin
 Bundle-ActivationPolicy: lazy
 
 Require-Bundle:        org.eclipse.core.runtime
 
-Export-Packages: org.argeo.security.ui.admin.*
-
 Import-Package:        org.eclipse.core.runtime.jobs,\
-                               org.argeo.eclipse.spring,\
-                               org.eclipse.jface.window,\
-                               org.eclipse.swt,\
-                               org.eclipse.swt.widgets;version="[0,1)",\
-                               org.eclipse.ui.services,\
-                               org.osgi.framework;version="[1.5,2)",\
-                               org.springframework.core,\
-                               org.springframework.dao,\
-                               org.springframework.security.provisioning,\
-                               *                               
+org.argeo.eclipse.spring,\
+org.eclipse.jface.window,\
+org.eclipse.swt,\
+org.eclipse.swt.widgets,\
+org.eclipse.ui.services,\
+org.osgi.framework,\
+org.springframework.core,\
+org.springframework.dao,\
+org.springframework.security.provisioning,\
+*                              
index 2b88024a36af1e5335735001db800f7c0d51beb9..fda9a19aa27064c3ebb679e724fb4968cefde6f2 100644 (file)
@@ -1,5 +1,6 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
-<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+       xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
        <modelVersion>4.0.0</modelVersion>
        <parent>
                <groupId>org.argeo.commons</groupId>
        <name>Commons CMS Workbench Admin</name>
        <packaging>jar</packaging>
        <dependencies>
+               <dependency>
+                       <groupId>org.argeo.commons</groupId>
+                       <artifactId>org.argeo.cms</artifactId>
+                       <version>2.1.17-SNAPSHOT</version>
+               </dependency>
                <dependency>
                        <groupId>org.argeo.commons</groupId>
                        <artifactId>org.argeo.util</artifactId>
index 660896de8a493cf1c0522bf037d569b8b6dfe85a..c2442c48ac9327ac3bd7020969a8b62bb7c390b7 100644 (file)
@@ -18,10 +18,9 @@ package org.argeo.security.ui.admin.commands;
 import javax.jcr.Repository;
 import javax.jcr.Session;
 
+import org.argeo.cms.users.NewUserWizard;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrSecurityModel;
-import org.argeo.security.ui.admin.wizards.NewUserWizard;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
@@ -32,14 +31,15 @@ import org.eclipse.ui.handlers.HandlerUtil;
 public class NewUser extends AbstractHandler {
        private Repository repository;
        private UserAdminService userAdminService;
-       private JcrSecurityModel jcrSecurityModel;
+
+       // private JcrSecurityModel jcrSecurityModel;
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
                Session session = null;
                try {
                        session = repository.login();
                        NewUserWizard newUserWizard = new NewUserWizard(session,
-                                       userAdminService, jcrSecurityModel);
+                                       userAdminService);
                        WizardDialog dialog = new WizardDialog(
                                        HandlerUtil.getActiveShell(event), newUserWizard);
                        dialog.open();
@@ -59,8 +59,8 @@ public class NewUser extends AbstractHandler {
                this.userAdminService = userAdminService;
        }
 
-       public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
-               this.jcrSecurityModel = jcrSecurityModel;
-       }
+       // public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
+       // this.jcrSecurityModel = jcrSecurityModel;
+       // }
 
 }
index 657dfc70aeedbd6b86487342f407ecf080446c09..3b8b352ecfff18d77ada4a0831d6cf366524189d 100644 (file)
@@ -20,7 +20,6 @@ import javax.jcr.Session;
 
 import org.argeo.jcr.JcrUtils;
 import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrSecurityModel;
 import org.argeo.security.ui.admin.wizards.UserBatchUpdateWizard;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
@@ -32,14 +31,13 @@ import org.eclipse.ui.handlers.HandlerUtil;
 public class UserBatchUpdate extends AbstractHandler {
        private Repository repository;
        private UserAdminService userAdminService;
-       private JcrSecurityModel jcrSecurityModel;
 
        public Object execute(ExecutionEvent event) throws ExecutionException {
                Session session = null;
                try {
                        session = repository.login();
-                       UserBatchUpdateWizard userBatchUpdateWizard = new UserBatchUpdateWizard(session,
-                                       userAdminService, jcrSecurityModel);
+                       UserBatchUpdateWizard userBatchUpdateWizard = new UserBatchUpdateWizard(
+                                       session, userAdminService);
                        WizardDialog dialog = new WizardDialog(
                                        HandlerUtil.getActiveShell(event), userBatchUpdateWizard);
                        dialog.open();
@@ -59,8 +57,8 @@ public class UserBatchUpdate extends AbstractHandler {
                this.userAdminService = userAdminService;
        }
 
-       public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
-               this.jcrSecurityModel = jcrSecurityModel;
-       }
+       // public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
+       // this.jcrSecurityModel = jcrSecurityModel;
+       // }
 
 }
diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/MainUserInfoWizardPage.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/MainUserInfoWizardPage.java
deleted file mode 100644 (file)
index af1f3d9..0000000
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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.ui.admin.wizards;
-
-import javax.jcr.Node;
-import javax.jcr.Property;
-import javax.jcr.RepositoryException;
-
-import org.argeo.ArgeoException;
-import org.argeo.eclipse.ui.EclipseUiUtils;
-import org.argeo.jcr.ArgeoNames;
-import org.argeo.security.UserAdminService;
-import org.eclipse.jface.wizard.WizardPage;
-import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.ModifyEvent;
-import org.eclipse.swt.events.ModifyListener;
-import org.eclipse.swt.layout.GridLayout;
-import org.eclipse.swt.widgets.Composite;
-import org.eclipse.swt.widgets.Text;
-import org.springframework.security.core.userdetails.UserDetails;
-import org.springframework.security.core.userdetails.UsernameNotFoundException;
-
-public class MainUserInfoWizardPage extends WizardPage implements
-               ModifyListener, ArgeoNames {
-       private static final long serialVersionUID = -3367329974808698649L;
-       private Text username, firstName, lastName, primaryEmail, password1,
-                       password2;
-       private UserAdminService userAdminService;
-
-       public MainUserInfoWizardPage(UserAdminService userAdminService) {
-               super("Main");
-               this.userAdminService = userAdminService;
-               setTitle("Required Information");
-       }
-
-       @Override
-       public void createControl(Composite parent) {
-               Composite composite = new Composite(parent, SWT.NONE);
-               composite.setLayout(new GridLayout(2, false));
-               username = EclipseUiUtils.createGridLT(composite, "Username", this);
-               primaryEmail = EclipseUiUtils.createGridLT(composite, "Email", this);
-               firstName = EclipseUiUtils.createGridLT(composite, "First name", this);
-               lastName = EclipseUiUtils.createGridLT(composite, "Last name", this);
-               password1 = EclipseUiUtils.createGridLP(composite, "Password", this);
-               password2 = EclipseUiUtils.createGridLP(composite, "Repeat password",
-                               this);
-               setControl(composite);
-               
-               // Initialize buttons
-               setPageComplete(false);
-               getContainer().updateButtons();
-       }
-
-       @Override
-       public void modifyText(ModifyEvent event) {
-               String message = checkComplete();
-               if (message != null) {
-                       setMessage(message, WizardPage.ERROR);
-                       setPageComplete(false);
-               } else {
-                       setMessage("Complete", WizardPage.INFORMATION);
-                       setPageComplete(true);
-               }
-               getContainer().updateButtons();
-       }
-
-       /** @return error message or null if complete */
-       protected String checkComplete() {
-               // if (!username.getText().matches(UserAdminService.USERNAME_PATTERN))
-               // return
-               // "Wrong user name format, should be lower case, between 3 and 64 characters with only '_' an '@' as acceptable special character.";
-               
-               if (username.getText().trim().equals(""))
-                       return "User name must not be empty";
-               
-               try {
-                       UserDetails userDetails = userAdminService
-                                       .loadUserByUsername(username.getText());
-                       return "User " + userDetails.getUsername() + " already exists";
-               } catch (UsernameNotFoundException e) {
-                       // silent
-               }
-               if (!primaryEmail.getText().matches(UserAdminService.EMAIL_PATTERN))
-                       return "Not a valid email address";
-               if (firstName.getText().trim().equals(""))
-                       return "Specify a first name";
-               if (lastName.getText().trim().equals(""))
-                       return "Specify a last name";
-               if (password1.getText().trim().equals(""))
-                       return "Specify a password";
-               if (password2.getText().trim().equals(""))
-                       return "Repeat the password";
-               if (!password2.getText().equals(password1.getText()))
-                       return "Passwords are different";
-               return null;
-       }
-
-       public String getUsername() {
-               return username.getText();
-       }
-
-       public String getPassword() {
-               return password1.getText();
-       }
-
-       public void mapToProfileNode(Node up) {
-               try {
-                       up.setProperty(ARGEO_PRIMARY_EMAIL, primaryEmail.getText());
-                       up.setProperty(ARGEO_FIRST_NAME, firstName.getText());
-                       up.setProperty(ARGEO_LAST_NAME, lastName.getText());
-
-                       // derived values
-                       // TODO add wizard pages to do it
-                       up.setProperty(Property.JCR_TITLE, firstName.getText() + " "
-                                       + lastName.getText());
-                       up.setProperty(Property.JCR_DESCRIPTION, "");
-               } catch (RepositoryException e) {
-                       throw new ArgeoException("Cannot map to " + up, e);
-               }
-       }
-}
diff --git a/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/NewUserWizard.java b/org.argeo.security.ui.admin/src/org/argeo/security/ui/admin/wizards/NewUserWizard.java
deleted file mode 100644 (file)
index 83f4c48..0000000
+++ /dev/null
@@ -1,102 +0,0 @@
-/*
- * Copyright (C) 2007-2012 Argeo GmbH
- *
- * 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.ui.admin.wizards;
-
-import java.util.ArrayList;
-
-import javax.jcr.Node;
-import javax.jcr.RepositoryException;
-import javax.jcr.Session;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
-import org.argeo.jcr.JcrUtils;
-import org.argeo.jcr.UserJcrUtils;
-import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrSecurityModel;
-import org.argeo.security.jcr.JcrUserDetails;
-import org.eclipse.jface.wizard.Wizard;
-import org.springframework.security.core.GrantedAuthority;
-
-/** Wizard to create a new user */
-public class NewUserWizard extends Wizard {
-       private final static Log log = LogFactory.getLog(NewUserWizard.class);
-       private Session session;
-       private UserAdminService userAdminService;
-       private JcrSecurityModel jcrSecurityModel;
-
-       // pages
-       private MainUserInfoWizardPage mainUserInfo;
-
-       public NewUserWizard(Session session, UserAdminService userAdminService,
-                       JcrSecurityModel jcrSecurityModel) {
-               this.session = session;
-               this.userAdminService = userAdminService;
-               this.jcrSecurityModel = jcrSecurityModel;
-       }
-
-       @Override
-       public void addPages() {
-               mainUserInfo = new MainUserInfoWizardPage(userAdminService);
-               addPage(mainUserInfo);
-       }
-
-       @Override
-       public boolean performFinish() {
-               if (!canFinish())
-                       return false;
-
-               String username = mainUserInfo.getUsername();
-               try {
-                       // Node userProfile = SecurityJcrUtils.createUserProfile(session,
-                       // username);
-                       Node userProfile = jcrSecurityModel.sync(session, username, null);
-                       session.getWorkspace().getVersionManager()
-                                       .checkout(userProfile.getPath());
-                       mainUserInfo.mapToProfileNode(userProfile);
-                       String password = mainUserInfo.getPassword();
-                       // TODO add roles
-                       JcrUserDetails jcrUserDetails = new JcrUserDetails(userProfile,
-                                       password, new ArrayList<GrantedAuthority>());
-                       session.save();
-                       session.getWorkspace().getVersionManager()
-                                       .checkin(userProfile.getPath());
-                       userAdminService.createUser(jcrUserDetails);
-                       return true;
-               } catch (Exception e) {
-                       JcrUtils.discardQuietly(session);
-                       Node userHome = UserJcrUtils.getUserHome(session, username);
-                       if (userHome != null) {
-                               try {
-                                       userHome.remove();
-                                       session.save();
-                               } catch (RepositoryException e1) {
-                                       JcrUtils.discardQuietly(session);
-                                       log.warn("Error when trying to clean up failed new user "
-                                                       + username, e1);
-                               }
-                       }
-                       ErrorFeedback.show("Cannot create new user " + username, e);
-                       return false;
-               }
-       }
-
-       public void setSession(Session session) {
-               this.session = session;
-       }
-
-}
index 0cf3c49e35a3f9c037e63b1368fbf22e46ce104f..bfa65a7b8d0ea550fa4198e11069532fb2f3eba7 100644 (file)
@@ -35,7 +35,6 @@ import org.argeo.eclipse.ui.parts.UsersTable;
 import org.argeo.jcr.ArgeoNames;
 import org.argeo.jcr.JcrUtils;
 import org.argeo.security.UserAdminService;
-import org.argeo.security.jcr.JcrSecurityModel;
 import org.argeo.security.jcr.JcrUserDetails;
 import org.argeo.security.ui.PrivilegedJob;
 import org.argeo.security.ui.admin.SecurityAdminPlugin;
@@ -92,10 +91,9 @@ public class UserBatchUpdateWizard extends Wizard {
        };
 
        public UserBatchUpdateWizard(Session session,
-                       UserAdminService userAdminService, JcrSecurityModel jcrSecurityModel) {
+                       UserAdminService userAdminService) {
                this.session = session;
                this.userAdminService = userAdminService;
-               // this.jcrSecurityModel = jcrSecurityModel;
        }
 
        @Override
@@ -562,8 +560,7 @@ public class UserBatchUpdateWizard extends Wizard {
                                ((IPageChangeProvider) container).addPageChangedListener(this);
                        }
 
-                       userTableCmp = new UsersTable(mainCmp, SWT.NO_FOCUS,
-                                       session);
+                       userTableCmp = new UsersTable(mainCmp, SWT.NO_FOCUS, session);
                        userTableCmp.populate(false, false);
                        setControl(mainCmp);
                }
index 9b01c552535afed97544bf234f0023430289d26c..7f92ab7cb913965a54fff22fb17647164824f111 100644 (file)
@@ -30,7 +30,7 @@ import org.apache.commons.logging.LogFactory;
 import org.argeo.ArgeoException;
 import org.argeo.cms.KernelHeader;
 import org.argeo.cms.auth.ArgeoLoginContext;
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.security.ui.auth.DefaultLoginDialog;
 import org.argeo.util.LocaleUtils;
 import org.eclipse.jface.dialogs.MessageDialog;
@@ -150,8 +150,8 @@ public class SecureEntryPoint implements EntryPoint {
                // Logout callback when the display is disposed
                display.disposeExec(new Runnable() {
                        public void run() {
-                               log.debug("Display disposed");
-                               // logout(loginContext, username);
+                               if (log.isTraceEnabled())
+                                       log.trace("Display disposed");
                                try {
                                        loginContext.logout();
                                } catch (LoginException e) {
@@ -174,7 +174,7 @@ public class SecureEntryPoint implements EntryPoint {
                                }
                        });
                        // Explicit exit from workbench
-                       logout(loginContext, username);
+                       fullLogout(loginContext, username);
                } finally {
                        display.dispose();
                }
@@ -229,7 +229,7 @@ public class SecureEntryPoint implements EntryPoint {
                        return null;
        }
 
-       private void logout(LoginContext loginContext, String username) {
+       private void fullLogout(LoginContext loginContext, String username) {
                try {
                        loginContext.logout();
                        SecurityContextHolder.clearContext();
index 6cc16c79ad263e892b279c62e45b04e8c0dbf275..a530a4e9a85ead9bc03252eb4f71bfd0742738e3 100644 (file)
@@ -15,7 +15,7 @@
  */
 package org.argeo.security.ui.commands;
 
-import org.argeo.eclipse.ui.workbench.ErrorFeedback;
+import org.argeo.eclipse.ui.dialogs.ErrorFeedback;
 import org.argeo.security.ui.UserHomePerspective;
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;