1 package org
.argeo
.security
.ui
.admin
.wizards
;
4 import javax
.jcr
.RepositoryException
;
5 import javax
.jcr
.Session
;
7 import org
.apache
.commons
.logging
.Log
;
8 import org
.apache
.commons
.logging
.LogFactory
;
9 import org
.argeo
.eclipse
.ui
.dialogs
.Error
;
10 import org
.argeo
.jcr
.ArgeoNames
;
11 import org
.argeo
.jcr
.JcrUtils
;
12 import org
.argeo
.security
.UserAdminService
;
13 import org
.argeo
.security
.jcr
.JcrUserDetails
;
14 import org
.eclipse
.jface
.wizard
.Wizard
;
15 import org
.springframework
.security
.GrantedAuthority
;
17 /** Wizard to create a new user */
18 public class NewUserWizard
extends Wizard
{
19 private final static Log log
= LogFactory
.getLog(NewUserWizard
.class);
21 private String homeBasePath
= "/home";
22 private Session session
;
23 private UserAdminService userAdminService
;
26 private MainUserInfoWizardPage mainUserInfo
;
28 public NewUserWizard(Session session
, UserAdminService userAdminService
) {
29 this.session
= session
;
30 this.userAdminService
= userAdminService
;
34 public void addPages() {
35 mainUserInfo
= new MainUserInfoWizardPage(userAdminService
);
36 addPage(mainUserInfo
);
40 public boolean performFinish() {
44 String username
= mainUserInfo
.getUsername();
47 Node userHome
= JcrUtils
.createUserHome(session
, homeBasePath
,
49 Node userProfile
= userHome
.getNode(ArgeoNames
.ARGEO_PROFILE
);
50 mainUserInfo
.mapToProfileNode(userProfile
);
51 String password
= mainUserInfo
.getPassword();
52 JcrUserDetails jcrUserDetails
= new JcrUserDetails(
53 userHome
.getPath(), username
, password
, true, true, true,
54 true, new GrantedAuthority
[0]);
56 userAdminService
.createUser(jcrUserDetails
);
58 } catch (Exception e
) {
59 JcrUtils
.discardQuietly(session
);
60 Node userHome
= JcrUtils
.getUserHome(session
, username
);
61 if (userHome
!= null) {
65 } catch (RepositoryException e1
) {
66 JcrUtils
.discardQuietly(session
);
67 log
.warn("Error when trying to clean up failed new user "
71 Error
.show("Cannot create new user " + username
, e
);
76 public void setSession(Session session
) {
77 this.session
= session
;