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
.cms
.users
;
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
.dialogs
.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
.NewUserDetails
;
29 import org
.eclipse
.jface
.wizard
.Wizard
;
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
;
36 // private JcrSecurityModel jcrSecurityModel;
39 private MainUserInfoWizardPage mainUserInfo
;
41 public NewUserWizard(Session session
, UserAdminService userAdminService
) {
42 this.session
= session
;
43 this.userAdminService
= userAdminService
;
44 // this.jcrSecurityModel = jcrSecurityModel;
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,
62 // Node userProfile = jcrSecurityModel.sync(session, username,
64 // session.getWorkspace().getVersionManager()
65 // .checkout(userProfile.getPath());
66 // mainUserInfo.mapToProfileNode(userProfile);
67 char[] password
= mainUserInfo
.getPassword();
69 NewUserDetails jcrUserDetails
= new NewUserDetails(username
,
71 private static final long serialVersionUID
= 7480071525603380742L;
74 public void mapToProfileNode(Node userProfile
)
75 throws RepositoryException
{
76 mainUserInfo
.mapToProfileNode(userProfile
);
80 // session.getWorkspace().getVersionManager()
81 // .checkin(userProfile.getPath());
82 userAdminService
.createUser(jcrUserDetails
);
84 } catch (Exception e
) {
85 JcrUtils
.discardQuietly(session
);
86 Node userHome
= UserJcrUtils
.getUserHome(session
, username
);
87 if (userHome
!= null) {
91 } catch (RepositoryException e1
) {
92 JcrUtils
.discardQuietly(session
);
93 log
.warn("Error when trying to clean up failed new user "
97 ErrorFeedback
.show("Cannot create new user " + username
, e
);
102 public void setSession(Session session
) {
103 this.session
= session
;