1 package org.apache.archiva.redback.users;
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
12 * http://www.apache.org/licenses/LICENSE-2.0
14 * Unless required by applicable law or agreed to in writing,
15 * software distributed under the License is distributed on an
16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17 * KIND, either express or implied. See the License for the
18 * specific language governing permissions and limitations
22 import java.util.ArrayList;
23 import java.util.List;
25 import org.slf4j.Logger;
26 import org.slf4j.LoggerFactory;
28 import javax.annotation.PostConstruct;
33 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
36 public abstract class AbstractUserManager
37 implements UserManager
39 protected Logger log = LoggerFactory.getLogger( getClass() );
41 private List<UserManagerListener> listeners = new ArrayList<UserManagerListener>();
43 public void addUserManagerListener( UserManagerListener listener )
45 if ( !listeners.contains( listener ) )
47 listeners.add( listener );
51 public void removeUserManagerListener( UserManagerListener listener )
53 listeners.remove( listener );
56 protected void fireUserManagerInit( boolean freshDatabase )
58 for ( UserManagerListener listener : listeners )
62 listener.userManagerInit( freshDatabase );
71 protected void fireUserManagerUserAdded( User addedUser )
73 for ( UserManagerListener listener : listeners )
77 listener.userManagerUserAdded( addedUser );
86 protected void fireUserManagerUserRemoved( User removedUser )
88 for ( UserManagerListener listener : listeners )
92 listener.userManagerUserRemoved( removedUser );
101 protected void fireUserManagerUserUpdated( User updatedUser )
103 for ( UserManagerListener listener : listeners )
107 listener.userManagerUserUpdated( updatedUser );
109 catch ( Exception e )
116 public User getGuestUser()
117 throws UserNotFoundException
119 return findUser( GUEST_USERNAME );
122 public User createGuestUser()
126 User u = getGuestUser();
132 catch ( UserNotFoundException e )
137 User user = createUser( GUEST_USERNAME, "Guest", "" );
138 user.setPermanent( true );
139 user.setPasswordChangeRequired( false );
141 user = addUser( user );
145 public void initialize()
147 // no op prevent sub classes to need implement this method
148 // sub classes can implement their own
151 public boolean isFinalImplementation()
156 protected List<UserManagerListener> getListeners()