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