1 package org.apache.archiva.web.rss;
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 org.apache.archiva.redback.authentication.AuthenticationDataSource;
23 import org.apache.archiva.redback.authentication.AuthenticationException;
24 import org.apache.archiva.redback.authentication.AuthenticationResult;
25 import org.apache.archiva.redback.authorization.AuthorizationException;
26 import org.apache.archiva.redback.authorization.AuthorizationResult;
27 import org.apache.archiva.redback.keys.KeyManager;
28 import org.apache.archiva.redback.policy.AccountLockedException;
29 import org.apache.archiva.redback.policy.UserSecurityPolicy;
30 import org.apache.archiva.redback.system.DefaultSecuritySession;
31 import org.apache.archiva.redback.system.SecuritySession;
32 import org.apache.archiva.redback.system.SecuritySystem;
33 import org.apache.archiva.redback.users.User;
34 import org.apache.archiva.redback.users.UserManager;
35 import org.apache.archiva.redback.users.UserManagerListener;
36 import org.apache.archiva.redback.users.UserNotFoundException;
37 import org.apache.archiva.redback.users.UserQuery;
38 import org.apache.archiva.redback.users.jdo.JdoUser;
40 import java.util.ArrayList;
41 import java.util.Date;
42 import java.util.HashMap;
43 import java.util.List;
47 * SecuritySystem stub used for testing.
49 public class SecuritySystemStub
50 implements SecuritySystem
52 Map<String, String> users = new HashMap<String, String>();
54 List<String> repoIds = new ArrayList<String>();
56 public SecuritySystemStub()
58 users.put( "user1", "password1" );
59 users.put( "user2", "password2" );
60 users.put( "user3", "password3" );
62 repoIds.add( "test-repo" );
65 public SecuritySession authenticate( AuthenticationDataSource source )
66 throws AuthenticationException, UserNotFoundException, AccountLockedException
68 AuthenticationResult result = null;
69 SecuritySession session = null;
71 if ( users.get( source.getUsername() ) != null )
73 result = new AuthenticationResult( true, source.getUsername(), null );
75 User user = new JdoUser();
76 user.setUsername( source.getUsername() );
77 user.setPassword( users.get( source.getUsername() ) );
79 session = new DefaultSecuritySession( result, user );
83 result = new AuthenticationResult( false, source.getUsername(), null );
84 session = new DefaultSecuritySession( result );
89 public AuthorizationResult authorize( SecuritySession arg0, String arg1 )
90 throws AuthorizationException
95 public AuthorizationResult authorize( SecuritySession arg0, String arg1, String arg2 )
96 throws AuthorizationException
98 AuthorizationResult result = new AuthorizationResult( true, arg1, null );
103 public String getAuthenticatorId()
108 public String getAuthorizerId()
113 public KeyManager getKeyManager()
118 public UserSecurityPolicy getPolicy()
123 public String getUserManagementId()
128 public UserManager getUserManager()
130 return new UserManager()
133 public String getDescriptionKey()
135 return "French wine is better than Australian wine !";
138 public boolean isFinalImplementation()
143 public void initialize()
148 public boolean isReadOnly()
153 public String getId()
158 public void addUserManagerListener( UserManagerListener listener )
163 public void removeUserManagerListener( UserManagerListener listener )
168 public User createUser( String username, String fullName, String emailAddress )
173 public User createGuestUser()
178 public String getUsername()
183 public void setUsername( String name )
188 public String getFullName()
193 public void setFullName( String name )
195 //To change body of implemented methods use File | Settings | File Templates.
198 public String getEmail()
200 return null; //To change body of implemented methods use File | Settings | File Templates.
203 public void setEmail( String address )
205 //To change body of implemented methods use File | Settings | File Templates.
208 public String getPassword()
210 return null; //To change body of implemented methods use File | Settings | File Templates.
213 public void setPassword( String rawPassword )
215 //To change body of implemented methods use File | Settings | File Templates.
218 public String getEncodedPassword()
220 return null; //To change body of implemented methods use File | Settings | File Templates.
223 public void setEncodedPassword( String encodedPassword )
225 //To change body of implemented methods use File | Settings | File Templates.
228 public Date getLastPasswordChange()
230 return null; //To change body of implemented methods use File | Settings | File Templates.
233 public void setLastPasswordChange( Date passwordChangeDate )
235 //To change body of implemented methods use File | Settings | File Templates.
238 public List<String> getPreviousEncodedPasswords()
240 return null; //To change body of implemented methods use File | Settings | File Templates.
243 public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
245 //To change body of implemented methods use File | Settings | File Templates.
248 public void addPreviousEncodedPassword( String encodedPassword )
250 //To change body of implemented methods use File | Settings | File Templates.
253 public boolean isPermanent()
255 return false; //To change body of implemented methods use File | Settings | File Templates.
258 public void setPermanent( boolean permanent )
260 //To change body of implemented methods use File | Settings | File Templates.
263 public boolean isLocked()
265 return false; //To change body of implemented methods use File | Settings | File Templates.
268 public void setLocked( boolean locked )
270 //To change body of implemented methods use File | Settings | File Templates.
273 public boolean isPasswordChangeRequired()
275 return false; //To change body of implemented methods use File | Settings | File Templates.
278 public void setPasswordChangeRequired( boolean changeRequired )
280 //To change body of implemented methods use File | Settings | File Templates.
283 public boolean isValidated()
285 return false; //To change body of implemented methods use File | Settings | File Templates.
288 public void setValidated( boolean valid )
290 //To change body of implemented methods use File | Settings | File Templates.
293 public int getCountFailedLoginAttempts()
295 return 0; //To change body of implemented methods use File | Settings | File Templates.
298 public void setCountFailedLoginAttempts( int count )
300 //To change body of implemented methods use File | Settings | File Templates.
303 public Date getAccountCreationDate()
305 return null; //To change body of implemented methods use File | Settings | File Templates.
308 public void setAccountCreationDate( Date date )
310 //To change body of implemented methods use File | Settings | File Templates.
313 public Date getLastLoginDate()
315 return null; //To change body of implemented methods use File | Settings | File Templates.
318 public void setLastLoginDate( Date date )
320 //To change body of implemented methods use File | Settings | File Templates.
323 public String getUserManagerId()
330 public UserQuery createUserQuery()
332 return null; //To change body of implemented methods use File | Settings | File Templates.
335 public List<User> getUsers()
337 return null; //To change body of implemented methods use File | Settings | File Templates.
340 public List<User> getUsers( boolean orderAscending )
342 return null; //To change body of implemented methods use File | Settings | File Templates.
345 public User addUser( User user )
347 return null; //To change body of implemented methods use File | Settings | File Templates.
350 public User updateUser( User user )
351 throws UserNotFoundException
353 return null; //To change body of implemented methods use File | Settings | File Templates.
356 public User findUser( String username )
357 throws UserNotFoundException
359 return null; //To change body of implemented methods use File | Settings | File Templates.
362 public User getGuestUser()
363 throws UserNotFoundException
368 public String getUsername()
373 public void setUsername( String name )
378 public String getFullName()
380 return null; //To change body of implemented methods use File | Settings | File Templates.
383 public void setFullName( String name )
385 //To change body of implemented methods use File | Settings | File Templates.
388 public String getEmail()
390 return null; //To change body of implemented methods use File | Settings | File Templates.
393 public void setEmail( String address )
395 //To change body of implemented methods use File | Settings | File Templates.
398 public String getPassword()
400 return null; //To change body of implemented methods use File | Settings | File Templates.
403 public void setPassword( String rawPassword )
405 //To change body of implemented methods use File | Settings | File Templates.
408 public String getEncodedPassword()
410 return null; //To change body of implemented methods use File | Settings | File Templates.
413 public void setEncodedPassword( String encodedPassword )
415 //To change body of implemented methods use File | Settings | File Templates.
418 public Date getLastPasswordChange()
420 return null; //To change body of implemented methods use File | Settings | File Templates.
423 public void setLastPasswordChange( Date passwordChangeDate )
425 //To change body of implemented methods use File | Settings | File Templates.
428 public List<String> getPreviousEncodedPasswords()
430 return null; //To change body of implemented methods use File | Settings | File Templates.
433 public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
435 //To change body of implemented methods use File | Settings | File Templates.
438 public void addPreviousEncodedPassword( String encodedPassword )
440 //To change body of implemented methods use File | Settings | File Templates.
443 public boolean isPermanent()
445 return false; //To change body of implemented methods use File | Settings | File Templates.
448 public void setPermanent( boolean permanent )
450 //To change body of implemented methods use File | Settings | File Templates.
453 public boolean isLocked()
455 return false; //To change body of implemented methods use File | Settings | File Templates.
458 public void setLocked( boolean locked )
460 //To change body of implemented methods use File | Settings | File Templates.
463 public boolean isPasswordChangeRequired()
465 return false; //To change body of implemented methods use File | Settings | File Templates.
468 public void setPasswordChangeRequired( boolean changeRequired )
470 //To change body of implemented methods use File | Settings | File Templates.
473 public boolean isValidated()
475 return false; //To change body of implemented methods use File | Settings | File Templates.
478 public void setValidated( boolean valid )
480 //To change body of implemented methods use File | Settings | File Templates.
483 public int getCountFailedLoginAttempts()
485 return 0; //To change body of implemented methods use File | Settings | File Templates.
488 public void setCountFailedLoginAttempts( int count )
490 //To change body of implemented methods use File | Settings | File Templates.
493 public Date getAccountCreationDate()
495 return null; //To change body of implemented methods use File | Settings | File Templates.
498 public void setAccountCreationDate( Date date )
500 //To change body of implemented methods use File | Settings | File Templates.
503 public Date getLastLoginDate()
505 return null; //To change body of implemented methods use File | Settings | File Templates.
508 public void setLastLoginDate( Date date )
510 //To change body of implemented methods use File | Settings | File Templates.
513 public String getUserManagerId()
520 public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
522 return null; //To change body of implemented methods use File | Settings | File Templates.
525 public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
527 return null; //To change body of implemented methods use File | Settings | File Templates.
530 public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
532 return null; //To change body of implemented methods use File | Settings | File Templates.
535 public List<User> findUsersByQuery( UserQuery query )
537 return null; //To change body of implemented methods use File | Settings | File Templates.
540 public boolean userExists( String principal )
542 return false; //To change body of implemented methods use File | Settings | File Templates.
545 public void deleteUser( String username )
546 throws UserNotFoundException
548 //To change body of implemented methods use File | Settings | File Templates.
551 public void addUserUnchecked( User user )
553 //To change body of implemented methods use File | Settings | File Templates.
556 public void eraseDatabase()
558 //To change body of implemented methods use File | Settings | File Templates.
561 public User updateUser( User user, boolean passwordChangeRequired )
562 throws UserNotFoundException
564 return null; //To change body of implemented methods use File | Settings | File Templates.
569 public boolean isAuthenticated( AuthenticationDataSource arg0 )
570 throws AuthenticationException, UserNotFoundException, AccountLockedException
575 public boolean isAuthorized( SecuritySession arg0, String arg1 )
576 throws AuthorizationException
581 public boolean isAuthorized( SecuritySession arg0, String arg1, String arg2 )
582 throws AuthorizationException
584 if ( repoIds.contains( arg2 ) )
592 public boolean userManagerReadOnly()