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
.ArgeoJcrUtils
;
26 import org
.argeo
.jcr
.JcrUtils
;
27 import org
.argeo
.jcr
.security
.SecurityJcrUtils
;
28 import org
.argeo
.security
.UserAdminService
;
29 import org
.argeo
.security
.jcr
.JcrUserDetails
;
30 import org
.eclipse
.jface
.wizard
.Wizard
;
31 import org
.springframework
.security
.GrantedAuthority
;
33 /** Wizard to create a new user */
34 public class NewUserWizard
extends Wizard
{
35 private final static Log log
= LogFactory
.getLog(NewUserWizard
.class);
36 private Session session
;
37 private UserAdminService userAdminService
;
40 private MainUserInfoWizardPage mainUserInfo
;
42 public NewUserWizard(Session session
, UserAdminService userAdminService
) {
43 this.session
= session
;
44 this.userAdminService
= userAdminService
;
48 public void addPages() {
49 mainUserInfo
= new MainUserInfoWizardPage(userAdminService
);
50 addPage(mainUserInfo
);
54 public boolean performFinish() {
58 String username
= mainUserInfo
.getUsername();
60 Node userProfile
= SecurityJcrUtils
.createUserProfile(session
, username
);
61 // session.getWorkspace().getVersionManager()
62 // .checkout(userProfile.getPath());
63 mainUserInfo
.mapToProfileNode(userProfile
);
64 String password
= mainUserInfo
.getPassword();
66 JcrUserDetails jcrUserDetails
= new JcrUserDetails(userProfile
,
67 password
, new GrantedAuthority
[0]);
69 session
.getWorkspace().getVersionManager()
70 .checkin(userProfile
.getPath());
71 userAdminService
.createUser(jcrUserDetails
);
73 } catch (Exception e
) {
74 JcrUtils
.discardQuietly(session
);
75 Node userHome
= ArgeoJcrUtils
.getUserHome(session
, username
);
76 if (userHome
!= null) {
80 } catch (RepositoryException e1
) {
81 JcrUtils
.discardQuietly(session
);
82 log
.warn("Error when trying to clean up failed new user "
86 ErrorFeedback
.show("Cannot create new user " + username
, e
);
91 public void setSession(Session session
) {
92 this.session
= session
;