1 package org.apache.archiva.redback.users.configurable;
4 * Copyright 2001-2007 The Apache Software Foundation.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
19 import org.apache.archiva.redback.configuration.UserConfiguration;
20 import org.apache.archiva.redback.configuration.UserConfigurationKeys;
21 import org.apache.archiva.redback.users.AbstractUserManager;
22 import org.apache.archiva.redback.users.User;
23 import org.apache.archiva.redback.users.UserManager;
24 import org.apache.archiva.redback.users.UserNotFoundException;
25 import org.apache.archiva.redback.users.UserQuery;
26 import org.springframework.context.ApplicationContext;
27 import org.springframework.stereotype.Service;
29 import javax.annotation.PostConstruct;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import java.util.List;
35 * @author <a href="jesse@codehaus.org"> jesse
37 @Service( "userManager#configurable" )
38 public class ConfigurableUserManager
39 extends AbstractUserManager
40 implements UserManager
43 @Named( value = "userConfiguration" )
44 private UserConfiguration config;
47 private ApplicationContext applicationContext;
49 private UserManager userManagerImpl;
53 public void initialize()
55 String userManagerRole = config.getString( UserConfigurationKeys.USER_MANAGER_IMPL );
57 if ( userManagerRole == null )
59 throw new RuntimeException( "User Manager Configuration Missing: " + UserConfigurationKeys.USER_MANAGER_IMPL
60 + " configuration property" );
63 log.info( "use userManager impl with key: '{}'", userManagerRole );
65 userManagerImpl = applicationContext.getBean( "userManager#" + userManagerRole, UserManager.class );
68 public User addUser( User user )
70 return userManagerImpl.addUser( user );
73 public void addUserUnchecked( User user )
75 userManagerImpl.addUserUnchecked( user );
78 public User createUser( String username, String fullName, String emailAddress )
80 return userManagerImpl.createUser( username, fullName, emailAddress );
83 public UserQuery createUserQuery()
85 return userManagerImpl.createUserQuery();
88 public void deleteUser( Object principal )
89 throws UserNotFoundException
91 userManagerImpl.deleteUser( principal );
94 public void deleteUser( String username )
95 throws UserNotFoundException
97 userManagerImpl.deleteUser( username );
100 public void eraseDatabase()
102 userManagerImpl.eraseDatabase();
105 public User findUser( String username )
106 throws UserNotFoundException
108 return userManagerImpl.findUser( username );
111 public User findUser( Object principal )
112 throws UserNotFoundException
114 return userManagerImpl.findUser( principal );
118 public User getGuestUser()
119 throws UserNotFoundException
121 return userManagerImpl.getGuestUser();
124 public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
126 return userManagerImpl.findUsersByEmailKey( emailKey, orderAscending );
129 public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
131 return userManagerImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
134 public List<User> findUsersByQuery( UserQuery query )
136 return userManagerImpl.findUsersByQuery( query );
139 public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
141 return userManagerImpl.findUsersByUsernameKey( usernameKey, orderAscending );
144 public String getId()
146 return "configurable";
149 public List<User> getUsers()
151 return userManagerImpl.getUsers();
154 public List<User> getUsers( boolean orderAscending )
156 return userManagerImpl.getUsers( orderAscending );
159 public boolean isReadOnly()
161 return userManagerImpl.isReadOnly();
164 public User updateUser( User user )
165 throws UserNotFoundException
167 return updateUser( user, false );
170 public User updateUser( User user, boolean passwordChangeRequired )
171 throws UserNotFoundException
173 return userManagerImpl.updateUser( user, passwordChangeRequired );
176 public boolean userExists( Object principal )
178 return userManagerImpl.userExists( principal );
181 public void setUserManagerImpl( UserManager userManagerImpl )
183 this.userManagerImpl = userManagerImpl;
186 public String getDescriptionKey()
188 return "archiva.redback.usermanager.configurable";