2 * Copyright (C) 2007-2012 Argeo GmbH
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
.jcr
.UserJcrUtils
;
27 import org
.argeo
.security
.UserAdminService
;
28 import org
.argeo
.security
.jcr
.JcrSecurityModel
;
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
;
38 private JcrSecurityModel jcrSecurityModel
;
41 private MainUserInfoWizardPage mainUserInfo
;
43 public NewUserWizard(Session session
, UserAdminService userAdminService
,
44 JcrSecurityModel jcrSecurityModel
) {
45 this.session
= session
;
46 this.userAdminService
= userAdminService
;
47 this.jcrSecurityModel
= jcrSecurityModel
;
51 public void addPages() {
52 mainUserInfo
= new MainUserInfoWizardPage(userAdminService
);
53 addPage(mainUserInfo
);
57 public boolean performFinish() {
61 String username
= mainUserInfo
.getUsername();
63 // Node userProfile = SecurityJcrUtils.createUserProfile(session,
65 Node userProfile
= jcrSecurityModel
.sync(session
, username
, null);
66 session
.getWorkspace().getVersionManager()
67 .checkout(userProfile
.getPath());
68 mainUserInfo
.mapToProfileNode(userProfile
);
69 String password
= mainUserInfo
.getPassword();
71 JcrUserDetails jcrUserDetails
= new JcrUserDetails(userProfile
,
72 password
, new GrantedAuthority
[0]);
74 session
.getWorkspace().getVersionManager()
75 .checkin(userProfile
.getPath());
76 userAdminService
.createUser(jcrUserDetails
);
78 } catch (Exception e
) {
79 JcrUtils
.discardQuietly(session
);
80 Node userHome
= UserJcrUtils
.getUserHome(session
, username
);
81 if (userHome
!= null) {
85 } catch (RepositoryException e1
) {
86 JcrUtils
.discardQuietly(session
);
87 log
.warn("Error when trying to clean up failed new user "
91 ErrorFeedback
.show("Cannot create new user " + username
, e
);
96 public void setSession(Session session
) {
97 this.session
= session
;