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.UserManagerException;
36 import org.apache.archiva.redback.users.UserManagerListener;
37 import org.apache.archiva.redback.users.UserNotFoundException;
38 import org.apache.archiva.redback.users.UserQuery;
39 import org.apache.archiva.redback.users.jdo.JdoUser;
41 import java.util.ArrayList;
42 import java.util.Date;
43 import java.util.HashMap;
44 import java.util.List;
48 * SecuritySystem stub used for testing.
50 public class SecuritySystemStub
51 implements SecuritySystem
53 Map<String, String> users = new HashMap<>();
55 List<String> repoIds = new ArrayList<>();
57 public SecuritySystemStub()
59 users.put( "user1", "password1" );
60 users.put( "user2", "password2" );
61 users.put( "user3", "password3" );
63 repoIds.add( "test-repo" );
67 public SecuritySession authenticate( AuthenticationDataSource source )
68 throws AuthenticationException, UserNotFoundException, AccountLockedException
70 AuthenticationResult result = null;
71 SecuritySession session = null;
73 if ( users.get( source.getUsername() ) != null )
75 result = new AuthenticationResult( true, source.getUsername(), null );
77 User user = new JdoUser();
78 user.setUsername( source.getUsername() );
79 user.setPassword( users.get( source.getUsername() ) );
81 session = new DefaultSecuritySession( result, user );
85 result = new AuthenticationResult( false, source.getUsername(), null );
86 session = new DefaultSecuritySession( result );
92 public AuthorizationResult authorize( SecuritySession arg0, String arg1 )
93 throws AuthorizationException
99 public AuthorizationResult authorize( SecuritySession arg0, String arg1, String arg2 )
100 throws AuthorizationException
102 AuthorizationResult result = new AuthorizationResult( true, arg1, null );
107 public String getAuthenticatorId()
112 public String getAuthorizerId()
118 public KeyManager getKeyManager()
124 public UserSecurityPolicy getPolicy()
129 public String getUserManagementId()
135 public UserManager getUserManager()
137 return new UserManager()
141 public String getDescriptionKey()
143 return "French wine is better than Australian wine !";
147 public boolean isFinalImplementation()
153 public void initialize()
159 public boolean isReadOnly()
165 public String getId()
171 public void addUserManagerListener( UserManagerListener listener )
177 public void removeUserManagerListener( UserManagerListener listener )
183 public User createUser( String username, String fullName, String emailAddress )
189 public User createGuestUser()
195 public String getUsername()
201 public void setUsername( String name )
207 public String getFullName()
213 public void setFullName( String name )
215 //To change body of implemented methods use File | Settings | File Templates.
219 public String getEmail()
221 return null; //To change body of implemented methods use File | Settings | File Templates.
225 public void setEmail( String address )
227 //To change body of implemented methods use File | Settings | File Templates.
231 public String getPassword()
233 return null; //To change body of implemented methods use File | Settings | File Templates.
237 public void setPassword( String rawPassword )
239 //To change body of implemented methods use File | Settings | File Templates.
243 public String getEncodedPassword()
245 return null; //To change body of implemented methods use File | Settings | File Templates.
249 public void setEncodedPassword( String encodedPassword )
251 //To change body of implemented methods use File | Settings | File Templates.
255 public Date getLastPasswordChange()
257 return null; //To change body of implemented methods use File | Settings | File Templates.
261 public void setLastPasswordChange( Date passwordChangeDate )
263 //To change body of implemented methods use File | Settings | File Templates.
267 public List<String> getPreviousEncodedPasswords()
269 return null; //To change body of implemented methods use File | Settings | File Templates.
273 public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
275 //To change body of implemented methods use File | Settings | File Templates.
279 public void addPreviousEncodedPassword( String encodedPassword )
281 //To change body of implemented methods use File | Settings | File Templates.
285 public boolean isPermanent()
287 return false; //To change body of implemented methods use File | Settings | File Templates.
291 public void setPermanent( boolean permanent )
293 //To change body of implemented methods use File | Settings | File Templates.
297 public boolean isLocked()
299 return false; //To change body of implemented methods use File | Settings | File Templates.
303 public void setLocked( boolean locked )
305 //To change body of implemented methods use File | Settings | File Templates.
309 public boolean isPasswordChangeRequired()
311 return false; //To change body of implemented methods use File | Settings | File Templates.
315 public void setPasswordChangeRequired( boolean changeRequired )
317 //To change body of implemented methods use File | Settings | File Templates.
321 public boolean isValidated()
323 return false; //To change body of implemented methods use File | Settings | File Templates.
327 public void setValidated( boolean valid )
329 //To change body of implemented methods use File | Settings | File Templates.
333 public int getCountFailedLoginAttempts()
335 return 0; //To change body of implemented methods use File | Settings | File Templates.
339 public void setCountFailedLoginAttempts( int count )
341 //To change body of implemented methods use File | Settings | File Templates.
345 public Date getAccountCreationDate()
347 return null; //To change body of implemented methods use File | Settings | File Templates.
351 public void setAccountCreationDate( Date date )
353 //To change body of implemented methods use File | Settings | File Templates.
357 public Date getLastLoginDate()
359 return null; //To change body of implemented methods use File | Settings | File Templates.
363 public void setLastLoginDate( Date date )
365 //To change body of implemented methods use File | Settings | File Templates.
369 public String getUserManagerId()
377 public UserQuery createUserQuery()
379 return null; //To change body of implemented methods use File | Settings | File Templates.
383 public List<User> getUsers()
385 return null; //To change body of implemented methods use File | Settings | File Templates.
389 public List<User> getUsers( boolean orderAscending )
391 return null; //To change body of implemented methods use File | Settings | File Templates.
395 public User addUser( User user )
397 return null; //To change body of implemented methods use File | Settings | File Templates.
401 public User updateUser( User user )
402 throws UserNotFoundException
404 return null; //To change body of implemented methods use File | Settings | File Templates.
408 public User findUser( String username )
409 throws UserNotFoundException
411 return null; //To change body of implemented methods use File | Settings | File Templates.
415 public User findUser( String username, boolean useCache )
416 throws UserNotFoundException, UserManagerException
422 public User getGuestUser()
423 throws UserNotFoundException
429 public String getUsername()
435 public void setUsername( String name )
441 public String getFullName()
443 return null; //To change body of implemented methods use File | Settings | File Templates.
447 public void setFullName( String name )
449 //To change body of implemented methods use File | Settings | File Templates.
453 public String getEmail()
455 return null; //To change body of implemented methods use File | Settings | File Templates.
459 public void setEmail( String address )
461 //To change body of implemented methods use File | Settings | File Templates.
465 public String getPassword()
467 return null; //To change body of implemented methods use File | Settings | File Templates.
471 public void setPassword( String rawPassword )
473 //To change body of implemented methods use File | Settings | File Templates.
477 public String getEncodedPassword()
479 return null; //To change body of implemented methods use File | Settings | File Templates.
483 public void setEncodedPassword( String encodedPassword )
485 //To change body of implemented methods use File | Settings | File Templates.
489 public Date getLastPasswordChange()
491 return null; //To change body of implemented methods use File | Settings | File Templates.
495 public void setLastPasswordChange( Date passwordChangeDate )
497 //To change body of implemented methods use File | Settings | File Templates.
501 public List<String> getPreviousEncodedPasswords()
503 return null; //To change body of implemented methods use File | Settings | File Templates.
507 public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
509 //To change body of implemented methods use File | Settings | File Templates.
513 public void addPreviousEncodedPassword( String encodedPassword )
515 //To change body of implemented methods use File | Settings | File Templates.
519 public boolean isPermanent()
521 return false; //To change body of implemented methods use File | Settings | File Templates.
525 public void setPermanent( boolean permanent )
527 //To change body of implemented methods use File | Settings | File Templates.
531 public boolean isLocked()
533 return false; //To change body of implemented methods use File | Settings | File Templates.
537 public void setLocked( boolean locked )
539 //To change body of implemented methods use File | Settings | File Templates.
543 public boolean isPasswordChangeRequired()
545 return false; //To change body of implemented methods use File | Settings | File Templates.
549 public void setPasswordChangeRequired( boolean changeRequired )
551 //To change body of implemented methods use File | Settings | File Templates.
555 public boolean isValidated()
557 return false; //To change body of implemented methods use File | Settings | File Templates.
561 public void setValidated( boolean valid )
563 //To change body of implemented methods use File | Settings | File Templates.
567 public int getCountFailedLoginAttempts()
569 return 0; //To change body of implemented methods use File | Settings | File Templates.
573 public void setCountFailedLoginAttempts( int count )
575 //To change body of implemented methods use File | Settings | File Templates.
579 public Date getAccountCreationDate()
581 return null; //To change body of implemented methods use File | Settings | File Templates.
585 public void setAccountCreationDate( Date date )
587 //To change body of implemented methods use File | Settings | File Templates.
591 public Date getLastLoginDate()
593 return null; //To change body of implemented methods use File | Settings | File Templates.
597 public void setLastLoginDate( Date date )
599 //To change body of implemented methods use File | Settings | File Templates.
603 public String getUserManagerId()
611 public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
613 return null; //To change body of implemented methods use File | Settings | File Templates.
617 public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
619 return null; //To change body of implemented methods use File | Settings | File Templates.
623 public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
625 return null; //To change body of implemented methods use File | Settings | File Templates.
629 public List<User> findUsersByQuery( UserQuery query )
631 return null; //To change body of implemented methods use File | Settings | File Templates.
635 public boolean userExists( String principal )
637 return false; //To change body of implemented methods use File | Settings | File Templates.
641 public void deleteUser( String username )
642 throws UserNotFoundException
644 //To change body of implemented methods use File | Settings | File Templates.
648 public void addUserUnchecked( User user )
650 //To change body of implemented methods use File | Settings | File Templates.
654 public void eraseDatabase()
656 //To change body of implemented methods use File | Settings | File Templates.
660 public User updateUser( User user, boolean passwordChangeRequired )
661 throws UserNotFoundException
663 return null; //To change body of implemented methods use File | Settings | File Templates.
669 public boolean isAuthenticated( AuthenticationDataSource arg0 )
670 throws AuthenticationException, UserNotFoundException, AccountLockedException
676 public boolean isAuthorized( SecuritySession arg0, String arg1 )
677 throws AuthorizationException
683 public boolean isAuthorized( SecuritySession arg0, String arg1, String arg2 )
684 throws AuthorizationException
686 if ( repoIds.contains( arg2 ) )
695 public boolean userManagerReadOnly()