--- /dev/null
+/*
+ * 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);
+}
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;
userDetailsManagerReg.unregister();
userAdminServiceReg.unregister();
authenticationManagerReg.unregister();
+
+ userAdmin.destroy();
userAdminReg.unregister();
}
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);
}
@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");
}
}
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()) {
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;
this.userDetails = userDetails;
}
- JcrUserDetails getUserDetails() {
+ public UserDetails getUserDetails() {
return userDetails;
}
package org.argeo.cms.internal.useradmin;
+import org.argeo.cms.CmsException;
import org.osgi.service.useradmin.Group;
import org.osgi.service.useradmin.Role;
@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() {
import java.util.Dictionary;
+import org.argeo.cms.CmsException;
import org.osgi.service.useradmin.Role;
abstract class JcrRole implements Role {
@Override
public Dictionary<String, Object> getProperties() {
- // TODO Auto-generated method stub
- return null;
+ throw new CmsException("Not implemented yet");
}
}
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;
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) {
@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);
}
}
@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
return userAdminService;
}
- public void setUserAdminService(UserAdminService userAdminService) {
+ public void setUserAdminService(JackrabbitUserAdminService userAdminService) {
this.userAdminService = userAdminService;
}
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
}
Node userProfile = UserJcrUtils.getUserProfile(session, username);
+ // new user
if (userProfile == null) {
String personPath = generateUserPath(
ArgeoJcrConstants.PEOPLE_BASE_PATH, username);
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
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;
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;
@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);
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;
--- /dev/null
+/*
+ * 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);
+ }
+ }
+}
--- /dev/null
+/*
+ * 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;
+ }
+
+}
--- /dev/null
+/*
+ * 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
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;
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;
// Enable user CRUD // INJECTED
private UserAdminService userAdminService;
- private JcrSecurityModel jcrSecurityModel;
// private UserDetailsManager userDetailsManager;
private String userWkspName;
@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)
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);
*/
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
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;
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;
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;
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;
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;
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;
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;
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;
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;
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;
--- /dev/null
+/*
+ * 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
+++ /dev/null
-/*
- * 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
+++ /dev/null
-/*
- * 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);
-}
--- /dev/null
+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;
+ }
+}
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"
</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
<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"
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,\
+*
<?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>
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;
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();
this.userAdminService = userAdminService;
}
- public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
- this.jcrSecurityModel = jcrSecurityModel;
- }
+ // public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
+ // this.jcrSecurityModel = jcrSecurityModel;
+ // }
}
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;
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();
this.userAdminService = userAdminService;
}
- public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
- this.jcrSecurityModel = jcrSecurityModel;
- }
+ // public void setJcrSecurityModel(JcrSecurityModel jcrSecurityModel) {
+ // this.jcrSecurityModel = jcrSecurityModel;
+ // }
}
+++ /dev/null
-/*
- * 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);
- }
- }
-}
+++ /dev/null
-/*
- * 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;
- }
-
-}
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;
};
public UserBatchUpdateWizard(Session session,
- UserAdminService userAdminService, JcrSecurityModel jcrSecurityModel) {
+ UserAdminService userAdminService) {
this.session = session;
this.userAdminService = userAdminService;
- // this.jcrSecurityModel = jcrSecurityModel;
}
@Override
((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);
}
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;
// 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) {
}
});
// Explicit exit from workbench
- logout(loginContext, username);
+ fullLogout(loginContext, username);
} finally {
display.dispose();
}
return null;
}
- private void logout(LoginContext loginContext, String username) {
+ private void fullLogout(LoginContext loginContext, String username) {
try {
loginContext.logout();
SecurityContextHolder.clearContext();
*/
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;