]> source.dussan.org Git - archiva.git/blob
d4a3a3616c326a257702102143e1bb25e12500bd
[archiva.git] /
1 package org.apache.archiva.redback.users.configurable;
2
3 /*
4  * Copyright 2001-2007 The Apache Software Foundation.
5  *
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
9  *
10  *      http://www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18
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;
28
29 import javax.annotation.PostConstruct;
30 import javax.inject.Inject;
31 import javax.inject.Named;
32 import java.util.List;
33
34 /**
35  * @author <a href="jesse@codehaus.org"> jesse
36  */
37 @Service( "userManager#configurable" )
38 public class ConfigurableUserManager
39     extends AbstractUserManager
40     implements UserManager
41 {
42     @Inject
43     @Named( value = "userConfiguration" )
44     private UserConfiguration config;
45
46     @Inject
47     private ApplicationContext applicationContext;
48
49     private UserManager userManagerImpl;
50
51
52     @PostConstruct
53     public void initialize()
54     {
55         String userManagerRole = config.getString( UserConfigurationKeys.USER_MANAGER_IMPL );
56
57         if ( userManagerRole == null )
58         {
59             throw new RuntimeException( "User Manager Configuration Missing: " + UserConfigurationKeys.USER_MANAGER_IMPL
60                                             + " configuration property" );
61         }
62
63         log.info( "use userManager impl with key: '{}'", userManagerRole );
64
65         userManagerImpl = applicationContext.getBean( "userManager#" + userManagerRole, UserManager.class );
66     }
67
68     public User addUser( User user )
69     {
70         return userManagerImpl.addUser( user );
71     }
72
73     public void addUserUnchecked( User user )
74     {
75         userManagerImpl.addUserUnchecked( user );
76     }
77
78     public User createUser( String username, String fullName, String emailAddress )
79     {
80         return userManagerImpl.createUser( username, fullName, emailAddress );
81     }
82
83     public UserQuery createUserQuery()
84     {
85         return userManagerImpl.createUserQuery();
86     }
87
88     public void deleteUser( Object principal )
89         throws UserNotFoundException
90     {
91         userManagerImpl.deleteUser( principal );
92     }
93
94     public void deleteUser( String username )
95         throws UserNotFoundException
96     {
97         userManagerImpl.deleteUser( username );
98     }
99
100     public void eraseDatabase()
101     {
102         userManagerImpl.eraseDatabase();
103     }
104
105     public User findUser( String username )
106         throws UserNotFoundException
107     {
108         return userManagerImpl.findUser( username );
109     }
110
111     public User findUser( Object principal )
112         throws UserNotFoundException
113     {
114         return userManagerImpl.findUser( principal );
115     }
116
117     @Override
118     public User getGuestUser()
119         throws UserNotFoundException
120     {
121         return userManagerImpl.getGuestUser();
122     }
123
124     public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
125     {
126         return userManagerImpl.findUsersByEmailKey( emailKey, orderAscending );
127     }
128
129     public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
130     {
131         return userManagerImpl.findUsersByFullNameKey( fullNameKey, orderAscending );
132     }
133
134     public List<User> findUsersByQuery( UserQuery query )
135     {
136         return userManagerImpl.findUsersByQuery( query );
137     }
138
139     public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
140     {
141         return userManagerImpl.findUsersByUsernameKey( usernameKey, orderAscending );
142     }
143
144     public String getId()
145     {
146         return "configurable";
147     }
148
149     public List<User> getUsers()
150     {
151         return userManagerImpl.getUsers();
152     }
153
154     public List<User> getUsers( boolean orderAscending )
155     {
156         return userManagerImpl.getUsers( orderAscending );
157     }
158
159     public boolean isReadOnly()
160     {
161         return userManagerImpl.isReadOnly();
162     }
163
164     public User updateUser( User user )
165         throws UserNotFoundException
166     {
167         return updateUser( user, false );
168     }
169
170     public User updateUser( User user, boolean passwordChangeRequired )
171         throws UserNotFoundException
172     {
173         return userManagerImpl.updateUser( user, passwordChangeRequired );
174     }
175
176     public boolean userExists( Object principal )
177     {
178         return userManagerImpl.userExists( principal );
179     }
180
181     public void setUserManagerImpl( UserManager userManagerImpl )
182     {
183         this.userManagerImpl = userManagerImpl;
184     }
185
186     public String getDescriptionKey()
187     {
188         return "archiva.redback.usermanager.configurable";
189     }
190 }