2 * Copyright (C) 2007-2012 Mathieu Baudier
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.security
.ui
.admin
.wizards
;
18 import javax
.jcr
.Node
;
19 import javax
.jcr
.RepositoryException
;
20 import javax
.jcr
.Session
;
22 import org
.apache
.commons
.logging
.Log
;
23 import org
.apache
.commons
.logging
.LogFactory
;
24 import org
.argeo
.eclipse
.ui
.ErrorFeedback
;
25 import org
.argeo
.jcr
.JcrUtils
;
26 import org
.argeo
.security
.UserAdminService
;
27 import org
.argeo
.security
.jcr
.JcrUserDetails
;
28 import org
.eclipse
.jface
.wizard
.Wizard
;
29 import org
.springframework
.security
.GrantedAuthority
;
31 /** Wizard to create a new user */
32 public class NewUserWizard
extends Wizard
{
33 private final static Log log
= LogFactory
.getLog(NewUserWizard
.class);
34 private Session session
;
35 private UserAdminService userAdminService
;
38 private MainUserInfoWizardPage mainUserInfo
;
40 public NewUserWizard(Session session
, UserAdminService userAdminService
) {
41 this.session
= session
;
42 this.userAdminService
= userAdminService
;
46 public void addPages() {
47 mainUserInfo
= new MainUserInfoWizardPage(userAdminService
);
48 addPage(mainUserInfo
);
52 public boolean performFinish() {
56 String username
= mainUserInfo
.getUsername();
58 Node userProfile
= JcrUtils
.createUserProfile(session
, username
);
59 // session.getWorkspace().getVersionManager()
60 // .checkout(userProfile.getPath());
61 mainUserInfo
.mapToProfileNode(userProfile
);
62 String password
= mainUserInfo
.getPassword();
64 JcrUserDetails jcrUserDetails
= new JcrUserDetails(userProfile
,
65 password
, new GrantedAuthority
[0]);
67 session
.getWorkspace().getVersionManager()
68 .checkin(userProfile
.getPath());
69 userAdminService
.createUser(jcrUserDetails
);
71 } catch (Exception e
) {
72 JcrUtils
.discardQuietly(session
);
73 Node userHome
= JcrUtils
.getUserHome(session
, username
);
74 if (userHome
!= null) {
78 } catch (RepositoryException e1
) {
79 JcrUtils
.discardQuietly(session
);
80 log
.warn("Error when trying to clean up failed new user "
84 ErrorFeedback
.show("Cannot create new user " + username
, e
);
89 public void setSession(Session session
) {
90 this.session
= session
;