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.keys.KeyManager;
23 import org.apache.archiva.redback.policy.AccountLockedException;
24 import org.apache.archiva.redback.policy.UserSecurityPolicy;
25 import org.apache.archiva.redback.users.User;
26 import org.apache.archiva.redback.users.UserManager;
27 import org.apache.archiva.redback.users.UserManagerListener;
28 import org.apache.archiva.redback.users.UserNotFoundException;
29 import org.apache.archiva.redback.users.UserQuery;
30 import org.apache.archiva.redback.authentication.AuthenticationDataSource;
31 import org.apache.archiva.redback.authentication.AuthenticationException;
32 import org.apache.archiva.redback.authentication.AuthenticationResult;
33 import org.apache.archiva.redback.authorization.AuthorizationException;
34 import org.apache.archiva.redback.authorization.AuthorizationResult;
35 import org.apache.archiva.redback.system.DefaultSecuritySession;
36 import org.apache.archiva.redback.system.SecuritySession;
37 import org.apache.archiva.redback.system.SecuritySystem;
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.
51 public class SecuritySystemStub
52 implements SecuritySystem
54 Map<String, String> users = new HashMap<String, String>();
56 List<String> repoIds = new ArrayList<String>();
58 public SecuritySystemStub()
60 users.put( "user1", "password1" );
61 users.put( "user2", "password2" );
62 users.put( "user3", "password3" );
64 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.getPrincipal() ) != null )
75 result = new AuthenticationResult( true, source.getPrincipal(), null );
77 User user = new JdoUser();
78 user.setUsername( source.getPrincipal() );
79 user.setPassword( users.get( source.getPrincipal() ) );
81 session = new DefaultSecuritySession( result, user );
85 result = new AuthenticationResult( false, source.getPrincipal(), null );
86 session = new DefaultSecuritySession( result );
91 public AuthorizationResult authorize( SecuritySession arg0, Object arg1 )
92 throws AuthorizationException
97 public AuthorizationResult authorize( SecuritySession arg0, Object arg1, Object arg2 )
98 throws AuthorizationException
100 AuthorizationResult result = new AuthorizationResult( true, arg1, null );
105 public String getAuthenticatorId()
110 public String getAuthorizerId()
115 public KeyManager getKeyManager()
120 public UserSecurityPolicy getPolicy()
125 public String getUserManagementId()
130 public UserManager getUserManager()
132 return new UserManager()
134 public boolean isReadOnly()
136 return false; //To change body of implemented methods use File | Settings | File Templates.
139 public String getId()
141 return null; //To change body of implemented methods use File | Settings | File Templates.
144 public void addUserManagerListener( UserManagerListener listener )
146 //To change body of implemented methods use File | Settings | File Templates.
149 public void removeUserManagerListener( UserManagerListener listener )
151 //To change body of implemented methods use File | Settings | File Templates.
154 public User createUser( String username, String fullName, String emailAddress )
156 return null; //To change body of implemented methods use File | Settings | File Templates.
159 public User createGuestUser()
164 public String getUsername()
169 public void setUsername( String name )
174 public String getFullName()
179 public void setFullName( String name )
181 //To change body of implemented methods use File | Settings | File Templates.
184 public String getEmail()
186 return null; //To change body of implemented methods use File | Settings | File Templates.
189 public void setEmail( String address )
191 //To change body of implemented methods use File | Settings | File Templates.
194 public String getPassword()
196 return null; //To change body of implemented methods use File | Settings | File Templates.
199 public void setPassword( String rawPassword )
201 //To change body of implemented methods use File | Settings | File Templates.
204 public String getEncodedPassword()
206 return null; //To change body of implemented methods use File | Settings | File Templates.
209 public void setEncodedPassword( String encodedPassword )
211 //To change body of implemented methods use File | Settings | File Templates.
214 public Date getLastPasswordChange()
216 return null; //To change body of implemented methods use File | Settings | File Templates.
219 public void setLastPasswordChange( Date passwordChangeDate )
221 //To change body of implemented methods use File | Settings | File Templates.
224 public List<String> getPreviousEncodedPasswords()
226 return null; //To change body of implemented methods use File | Settings | File Templates.
229 public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
231 //To change body of implemented methods use File | Settings | File Templates.
234 public void addPreviousEncodedPassword( String encodedPassword )
236 //To change body of implemented methods use File | Settings | File Templates.
239 public boolean isPermanent()
241 return false; //To change body of implemented methods use File | Settings | File Templates.
244 public void setPermanent( boolean permanent )
246 //To change body of implemented methods use File | Settings | File Templates.
249 public boolean isLocked()
251 return false; //To change body of implemented methods use File | Settings | File Templates.
254 public void setLocked( boolean locked )
256 //To change body of implemented methods use File | Settings | File Templates.
259 public boolean isPasswordChangeRequired()
261 return false; //To change body of implemented methods use File | Settings | File Templates.
264 public void setPasswordChangeRequired( boolean changeRequired )
266 //To change body of implemented methods use File | Settings | File Templates.
269 public boolean isValidated()
271 return false; //To change body of implemented methods use File | Settings | File Templates.
274 public void setValidated( boolean valid )
276 //To change body of implemented methods use File | Settings | File Templates.
279 public int getCountFailedLoginAttempts()
281 return 0; //To change body of implemented methods use File | Settings | File Templates.
284 public void setCountFailedLoginAttempts( int count )
286 //To change body of implemented methods use File | Settings | File Templates.
289 public Date getAccountCreationDate()
291 return null; //To change body of implemented methods use File | Settings | File Templates.
294 public void setAccountCreationDate( Date date )
296 //To change body of implemented methods use File | Settings | File Templates.
299 public Date getLastLoginDate()
301 return null; //To change body of implemented methods use File | Settings | File Templates.
304 public void setLastLoginDate( Date date )
306 //To change body of implemented methods use File | Settings | File Templates.
311 public UserQuery createUserQuery()
313 return null; //To change body of implemented methods use File | Settings | File Templates.
316 public List<User> getUsers()
318 return null; //To change body of implemented methods use File | Settings | File Templates.
321 public List<User> getUsers( boolean orderAscending )
323 return null; //To change body of implemented methods use File | Settings | File Templates.
326 public User addUser( User user )
328 return null; //To change body of implemented methods use File | Settings | File Templates.
331 public User updateUser( User user )
332 throws UserNotFoundException
334 return null; //To change body of implemented methods use File | Settings | File Templates.
337 public User findUser( String username )
338 throws UserNotFoundException
340 return null; //To change body of implemented methods use File | Settings | File Templates.
343 public User getGuestUser()
344 throws UserNotFoundException
349 public String getUsername()
354 public void setUsername( String name )
359 public String getFullName()
361 return null; //To change body of implemented methods use File | Settings | File Templates.
364 public void setFullName( String name )
366 //To change body of implemented methods use File | Settings | File Templates.
369 public String getEmail()
371 return null; //To change body of implemented methods use File | Settings | File Templates.
374 public void setEmail( String address )
376 //To change body of implemented methods use File | Settings | File Templates.
379 public String getPassword()
381 return null; //To change body of implemented methods use File | Settings | File Templates.
384 public void setPassword( String rawPassword )
386 //To change body of implemented methods use File | Settings | File Templates.
389 public String getEncodedPassword()
391 return null; //To change body of implemented methods use File | Settings | File Templates.
394 public void setEncodedPassword( String encodedPassword )
396 //To change body of implemented methods use File | Settings | File Templates.
399 public Date getLastPasswordChange()
401 return null; //To change body of implemented methods use File | Settings | File Templates.
404 public void setLastPasswordChange( Date passwordChangeDate )
406 //To change body of implemented methods use File | Settings | File Templates.
409 public List<String> getPreviousEncodedPasswords()
411 return null; //To change body of implemented methods use File | Settings | File Templates.
414 public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
416 //To change body of implemented methods use File | Settings | File Templates.
419 public void addPreviousEncodedPassword( String encodedPassword )
421 //To change body of implemented methods use File | Settings | File Templates.
424 public boolean isPermanent()
426 return false; //To change body of implemented methods use File | Settings | File Templates.
429 public void setPermanent( boolean permanent )
431 //To change body of implemented methods use File | Settings | File Templates.
434 public boolean isLocked()
436 return false; //To change body of implemented methods use File | Settings | File Templates.
439 public void setLocked( boolean locked )
441 //To change body of implemented methods use File | Settings | File Templates.
444 public boolean isPasswordChangeRequired()
446 return false; //To change body of implemented methods use File | Settings | File Templates.
449 public void setPasswordChangeRequired( boolean changeRequired )
451 //To change body of implemented methods use File | Settings | File Templates.
454 public boolean isValidated()
456 return false; //To change body of implemented methods use File | Settings | File Templates.
459 public void setValidated( boolean valid )
461 //To change body of implemented methods use File | Settings | File Templates.
464 public int getCountFailedLoginAttempts()
466 return 0; //To change body of implemented methods use File | Settings | File Templates.
469 public void setCountFailedLoginAttempts( int count )
471 //To change body of implemented methods use File | Settings | File Templates.
474 public Date getAccountCreationDate()
476 return null; //To change body of implemented methods use File | Settings | File Templates.
479 public void setAccountCreationDate( Date date )
481 //To change body of implemented methods use File | Settings | File Templates.
484 public Date getLastLoginDate()
486 return null; //To change body of implemented methods use File | Settings | File Templates.
489 public void setLastLoginDate( Date date )
491 //To change body of implemented methods use File | Settings | File Templates.
496 public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
498 return null; //To change body of implemented methods use File | Settings | File Templates.
501 public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
503 return null; //To change body of implemented methods use File | Settings | File Templates.
506 public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
508 return null; //To change body of implemented methods use File | Settings | File Templates.
511 public List<User> findUsersByQuery( UserQuery query )
513 return null; //To change body of implemented methods use File | Settings | File Templates.
516 public User findUser( Object principal )
517 throws UserNotFoundException
519 return null; //To change body of implemented methods use File | Settings | File Templates.
522 public boolean userExists( Object principal )
524 return false; //To change body of implemented methods use File | Settings | File Templates.
527 public void deleteUser( Object principal )
528 throws UserNotFoundException
530 //To change body of implemented methods use File | Settings | File Templates.
533 public void deleteUser( String username )
534 throws UserNotFoundException
536 //To change body of implemented methods use File | Settings | File Templates.
539 public void addUserUnchecked( User user )
541 //To change body of implemented methods use File | Settings | File Templates.
544 public void eraseDatabase()
546 //To change body of implemented methods use File | Settings | File Templates.
549 public User updateUser( User user, boolean passwordChangeRequired )
550 throws UserNotFoundException
552 return null; //To change body of implemented methods use File | Settings | File Templates.
557 public boolean isAuthenticated( AuthenticationDataSource arg0 )
558 throws AuthenticationException, UserNotFoundException, AccountLockedException
563 public boolean isAuthorized( SecuritySession arg0, Object arg1 )
564 throws AuthorizationException
569 public boolean isAuthorized( SecuritySession arg0, Object arg1, Object arg2 )
570 throws AuthorizationException
572 if ( repoIds.contains( arg2 ) )