]> source.dussan.org Git - archiva.git/blob
4b3bec808bc7016dd63ef7cbf3801bba9cba02ee
[archiva.git] /
1 package org.apache.archiva.web.rss;
2
3 /*
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
11  *
12  *  http://www.apache.org/licenses/LICENSE-2.0
13  *
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
19  * under the License.
20  */
21
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;
39
40 import java.util.ArrayList;
41 import java.util.Date;
42 import java.util.HashMap;
43 import java.util.List;
44 import java.util.Map;
45
46 /**
47  * SecuritySystem stub used for testing.
48  */
49 public class SecuritySystemStub
50     implements SecuritySystem
51 {
52     Map<String, String> users = new HashMap<String, String>();
53
54     List<String> repoIds = new ArrayList<String>();
55
56     public SecuritySystemStub()
57     {
58         users.put( "user1", "password1" );
59         users.put( "user2", "password2" );
60         users.put( "user3", "password3" );
61
62         repoIds.add( "test-repo" );
63     }
64
65     public SecuritySession authenticate( AuthenticationDataSource source )
66         throws AuthenticationException, UserNotFoundException, AccountLockedException
67     {
68         AuthenticationResult result = null;
69         SecuritySession session = null;
70
71         if ( users.get( source.getUsername() ) != null )
72         {
73             result = new AuthenticationResult( true, source.getUsername(), null );
74
75             User user = new JdoUser();
76             user.setUsername( source.getUsername() );
77             user.setPassword( users.get( source.getUsername() ) );
78
79             session = new DefaultSecuritySession( result, user );
80         }
81         else
82         {
83             result = new AuthenticationResult( false, source.getUsername(), null );
84             session = new DefaultSecuritySession( result );
85         }
86         return session;
87     }
88
89     public AuthorizationResult authorize( SecuritySession arg0, String arg1 )
90         throws AuthorizationException
91     {
92         return null;
93     }
94
95     public AuthorizationResult authorize( SecuritySession arg0, String arg1, String arg2 )
96         throws AuthorizationException
97     {
98         AuthorizationResult result = new AuthorizationResult( true, arg1, null );
99
100         return result;
101     }
102
103     public String getAuthenticatorId()
104     {
105         return null;
106     }
107
108     public String getAuthorizerId()
109     {
110         return null;
111     }
112
113     public KeyManager getKeyManager()
114     {
115         return null;
116     }
117
118     public UserSecurityPolicy getPolicy()
119     {
120         return null;
121     }
122
123     public String getUserManagementId()
124     {
125         return null;
126     }
127
128     public UserManager getUserManager()
129     {
130         return new UserManager()
131         {
132
133             public String getDescriptionKey()
134             {
135                 return "French wine is better than Australian wine !";
136             }
137
138             public boolean isFinalImplementation()
139             {
140                 return false;
141             }
142
143             public void initialize()
144             {
145                 // no op
146             }
147
148             public boolean isReadOnly()
149             {
150                 return false;
151             }
152
153             public String getId()
154             {
155                 return null;
156             }
157
158             public void addUserManagerListener( UserManagerListener listener )
159             {
160                 // no op
161             }
162
163             public void removeUserManagerListener( UserManagerListener listener )
164             {
165                 // no op
166             }
167
168             public User createUser( String username, String fullName, String emailAddress )
169             {
170                 return null;
171             }
172
173             public User createGuestUser()
174             {
175                 return new User()
176                 {
177
178                     public String getUsername()
179                     {
180                         return "guest";
181                     }
182
183                     public void setUsername( String name )
184                     {
185
186                     }
187
188                     public String getFullName()
189                     {
190                         return null;
191                     }
192
193                     public void setFullName( String name )
194                     {
195                         //To change body of implemented methods use File | Settings | File Templates.
196                     }
197
198                     public String getEmail()
199                     {
200                         return null;  //To change body of implemented methods use File | Settings | File Templates.
201                     }
202
203                     public void setEmail( String address )
204                     {
205                         //To change body of implemented methods use File | Settings | File Templates.
206                     }
207
208                     public String getPassword()
209                     {
210                         return null;  //To change body of implemented methods use File | Settings | File Templates.
211                     }
212
213                     public void setPassword( String rawPassword )
214                     {
215                         //To change body of implemented methods use File | Settings | File Templates.
216                     }
217
218                     public String getEncodedPassword()
219                     {
220                         return null;  //To change body of implemented methods use File | Settings | File Templates.
221                     }
222
223                     public void setEncodedPassword( String encodedPassword )
224                     {
225                         //To change body of implemented methods use File | Settings | File Templates.
226                     }
227
228                     public Date getLastPasswordChange()
229                     {
230                         return null;  //To change body of implemented methods use File | Settings | File Templates.
231                     }
232
233                     public void setLastPasswordChange( Date passwordChangeDate )
234                     {
235                         //To change body of implemented methods use File | Settings | File Templates.
236                     }
237
238                     public List<String> getPreviousEncodedPasswords()
239                     {
240                         return null;  //To change body of implemented methods use File | Settings | File Templates.
241                     }
242
243                     public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
244                     {
245                         //To change body of implemented methods use File | Settings | File Templates.
246                     }
247
248                     public void addPreviousEncodedPassword( String encodedPassword )
249                     {
250                         //To change body of implemented methods use File | Settings | File Templates.
251                     }
252
253                     public boolean isPermanent()
254                     {
255                         return false;  //To change body of implemented methods use File | Settings | File Templates.
256                     }
257
258                     public void setPermanent( boolean permanent )
259                     {
260                         //To change body of implemented methods use File | Settings | File Templates.
261                     }
262
263                     public boolean isLocked()
264                     {
265                         return false;  //To change body of implemented methods use File | Settings | File Templates.
266                     }
267
268                     public void setLocked( boolean locked )
269                     {
270                         //To change body of implemented methods use File | Settings | File Templates.
271                     }
272
273                     public boolean isPasswordChangeRequired()
274                     {
275                         return false;  //To change body of implemented methods use File | Settings | File Templates.
276                     }
277
278                     public void setPasswordChangeRequired( boolean changeRequired )
279                     {
280                         //To change body of implemented methods use File | Settings | File Templates.
281                     }
282
283                     public boolean isValidated()
284                     {
285                         return false;  //To change body of implemented methods use File | Settings | File Templates.
286                     }
287
288                     public void setValidated( boolean valid )
289                     {
290                         //To change body of implemented methods use File | Settings | File Templates.
291                     }
292
293                     public int getCountFailedLoginAttempts()
294                     {
295                         return 0;  //To change body of implemented methods use File | Settings | File Templates.
296                     }
297
298                     public void setCountFailedLoginAttempts( int count )
299                     {
300                         //To change body of implemented methods use File | Settings | File Templates.
301                     }
302
303                     public Date getAccountCreationDate()
304                     {
305                         return null;  //To change body of implemented methods use File | Settings | File Templates.
306                     }
307
308                     public void setAccountCreationDate( Date date )
309                     {
310                         //To change body of implemented methods use File | Settings | File Templates.
311                     }
312
313                     public Date getLastLoginDate()
314                     {
315                         return null;  //To change body of implemented methods use File | Settings | File Templates.
316                     }
317
318                     public void setLastLoginDate( Date date )
319                     {
320                         //To change body of implemented methods use File | Settings | File Templates.
321                     }
322
323                     public String getUserManagerId()
324                     {
325                         return "mock";
326                     }
327                 };
328             }
329
330             public UserQuery createUserQuery()
331             {
332                 return null;  //To change body of implemented methods use File | Settings | File Templates.
333             }
334
335             public List<User> getUsers()
336             {
337                 return null;  //To change body of implemented methods use File | Settings | File Templates.
338             }
339
340             public List<User> getUsers( boolean orderAscending )
341             {
342                 return null;  //To change body of implemented methods use File | Settings | File Templates.
343             }
344
345             public User addUser( User user )
346             {
347                 return null;  //To change body of implemented methods use File | Settings | File Templates.
348             }
349
350             public User updateUser( User user )
351                 throws UserNotFoundException
352             {
353                 return null;  //To change body of implemented methods use File | Settings | File Templates.
354             }
355
356             public User findUser( String username )
357                 throws UserNotFoundException
358             {
359                 return null;  //To change body of implemented methods use File | Settings | File Templates.
360             }
361
362             public User getGuestUser()
363                 throws UserNotFoundException
364             {
365                 return new User()
366                 {
367
368                     public String getUsername()
369                     {
370                         return "guest";
371                     }
372
373                     public void setUsername( String name )
374                     {
375
376                     }
377
378                     public String getFullName()
379                     {
380                         return null;  //To change body of implemented methods use File | Settings | File Templates.
381                     }
382
383                     public void setFullName( String name )
384                     {
385                         //To change body of implemented methods use File | Settings | File Templates.
386                     }
387
388                     public String getEmail()
389                     {
390                         return null;  //To change body of implemented methods use File | Settings | File Templates.
391                     }
392
393                     public void setEmail( String address )
394                     {
395                         //To change body of implemented methods use File | Settings | File Templates.
396                     }
397
398                     public String getPassword()
399                     {
400                         return null;  //To change body of implemented methods use File | Settings | File Templates.
401                     }
402
403                     public void setPassword( String rawPassword )
404                     {
405                         //To change body of implemented methods use File | Settings | File Templates.
406                     }
407
408                     public String getEncodedPassword()
409                     {
410                         return null;  //To change body of implemented methods use File | Settings | File Templates.
411                     }
412
413                     public void setEncodedPassword( String encodedPassword )
414                     {
415                         //To change body of implemented methods use File | Settings | File Templates.
416                     }
417
418                     public Date getLastPasswordChange()
419                     {
420                         return null;  //To change body of implemented methods use File | Settings | File Templates.
421                     }
422
423                     public void setLastPasswordChange( Date passwordChangeDate )
424                     {
425                         //To change body of implemented methods use File | Settings | File Templates.
426                     }
427
428                     public List<String> getPreviousEncodedPasswords()
429                     {
430                         return null;  //To change body of implemented methods use File | Settings | File Templates.
431                     }
432
433                     public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
434                     {
435                         //To change body of implemented methods use File | Settings | File Templates.
436                     }
437
438                     public void addPreviousEncodedPassword( String encodedPassword )
439                     {
440                         //To change body of implemented methods use File | Settings | File Templates.
441                     }
442
443                     public boolean isPermanent()
444                     {
445                         return false;  //To change body of implemented methods use File | Settings | File Templates.
446                     }
447
448                     public void setPermanent( boolean permanent )
449                     {
450                         //To change body of implemented methods use File | Settings | File Templates.
451                     }
452
453                     public boolean isLocked()
454                     {
455                         return false;  //To change body of implemented methods use File | Settings | File Templates.
456                     }
457
458                     public void setLocked( boolean locked )
459                     {
460                         //To change body of implemented methods use File | Settings | File Templates.
461                     }
462
463                     public boolean isPasswordChangeRequired()
464                     {
465                         return false;  //To change body of implemented methods use File | Settings | File Templates.
466                     }
467
468                     public void setPasswordChangeRequired( boolean changeRequired )
469                     {
470                         //To change body of implemented methods use File | Settings | File Templates.
471                     }
472
473                     public boolean isValidated()
474                     {
475                         return false;  //To change body of implemented methods use File | Settings | File Templates.
476                     }
477
478                     public void setValidated( boolean valid )
479                     {
480                         //To change body of implemented methods use File | Settings | File Templates.
481                     }
482
483                     public int getCountFailedLoginAttempts()
484                     {
485                         return 0;  //To change body of implemented methods use File | Settings | File Templates.
486                     }
487
488                     public void setCountFailedLoginAttempts( int count )
489                     {
490                         //To change body of implemented methods use File | Settings | File Templates.
491                     }
492
493                     public Date getAccountCreationDate()
494                     {
495                         return null;  //To change body of implemented methods use File | Settings | File Templates.
496                     }
497
498                     public void setAccountCreationDate( Date date )
499                     {
500                         //To change body of implemented methods use File | Settings | File Templates.
501                     }
502
503                     public Date getLastLoginDate()
504                     {
505                         return null;  //To change body of implemented methods use File | Settings | File Templates.
506                     }
507
508                     public void setLastLoginDate( Date date )
509                     {
510                         //To change body of implemented methods use File | Settings | File Templates.
511                     }
512
513                     public String getUserManagerId()
514                     {
515                         return "mock";
516                     }
517                 };
518             }
519
520             public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
521             {
522                 return null;  //To change body of implemented methods use File | Settings | File Templates.
523             }
524
525             public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
526             {
527                 return null;  //To change body of implemented methods use File | Settings | File Templates.
528             }
529
530             public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
531             {
532                 return null;  //To change body of implemented methods use File | Settings | File Templates.
533             }
534
535             public List<User> findUsersByQuery( UserQuery query )
536             {
537                 return null;  //To change body of implemented methods use File | Settings | File Templates.
538             }
539
540             public boolean userExists( String principal )
541             {
542                 return false;  //To change body of implemented methods use File | Settings | File Templates.
543             }
544
545             public void deleteUser( String username )
546                 throws UserNotFoundException
547             {
548                 //To change body of implemented methods use File | Settings | File Templates.
549             }
550
551             public void addUserUnchecked( User user )
552             {
553                 //To change body of implemented methods use File | Settings | File Templates.
554             }
555
556             public void eraseDatabase()
557             {
558                 //To change body of implemented methods use File | Settings | File Templates.
559             }
560
561             public User updateUser( User user, boolean passwordChangeRequired )
562                 throws UserNotFoundException
563             {
564                 return null;  //To change body of implemented methods use File | Settings | File Templates.
565             }
566         };
567     }
568
569     public boolean isAuthenticated( AuthenticationDataSource arg0 )
570         throws AuthenticationException, UserNotFoundException, AccountLockedException
571     {
572         return false;
573     }
574
575     public boolean isAuthorized( SecuritySession arg0, String arg1 )
576         throws AuthorizationException
577     {
578         return false;
579     }
580
581     public boolean isAuthorized( SecuritySession arg0, String arg1, String arg2 )
582         throws AuthorizationException
583     {
584         if ( repoIds.contains( arg2 ) )
585         {
586             return true;
587         }
588
589         return false;
590     }
591
592     public boolean userManagerReadOnly()
593     {
594         return true;
595     }
596 }