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;
31 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a>
34 public abstract class AbstractUserManager
35 implements UserManager
37 protected Logger log = LoggerFactory.getLogger( getClass() );
39 private List<UserManagerListener> listeners = new ArrayList<UserManagerListener>();
41 public void addUserManagerListener( UserManagerListener listener )
43 if ( !listeners.contains( listener ) )
45 listeners.add( listener );
49 public void removeUserManagerListener( UserManagerListener listener )
51 listeners.remove( listener );
54 protected void fireUserManagerInit( boolean freshDatabase )
56 for ( UserManagerListener listener : listeners )
60 listener.userManagerInit( freshDatabase );
69 protected void fireUserManagerUserAdded( User addedUser )
71 for ( UserManagerListener listener : listeners )
75 listener.userManagerUserAdded( addedUser );
84 protected void fireUserManagerUserRemoved( User removedUser )
86 for ( UserManagerListener listener : listeners )
90 listener.userManagerUserRemoved( removedUser );
99 protected void fireUserManagerUserUpdated( User updatedUser )
101 for ( UserManagerListener listener : listeners )
105 listener.userManagerUserUpdated( updatedUser );
107 catch ( Exception e )
114 public User getGuestUser()
115 throws UserNotFoundException
117 return findUser( GUEST_USERNAME );
120 public User createGuestUser()
124 User u = getGuestUser();
130 catch ( UserNotFoundException e )
135 User user = createUser( GUEST_USERNAME, "Guest", "" );
136 user.setPermanent( true );
137 user.setPasswordChangeRequired( false );
139 user = addUser( user );