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.codehaus.plexus.redback.authentication.AuthenticationDataSource;
23 import org.codehaus.plexus.redback.authentication.AuthenticationException;
24 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
25 import org.codehaus.plexus.redback.authorization.AuthorizationException;
26 import org.codehaus.plexus.redback.authorization.AuthorizationResult;
27 import org.codehaus.plexus.redback.keys.KeyManager;
28 import org.codehaus.plexus.redback.policy.AccountLockedException;
29 import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
30 import org.codehaus.plexus.redback.system.DefaultSecuritySession;
31 import org.codehaus.plexus.redback.system.SecuritySession;
32 import org.codehaus.plexus.redback.system.SecuritySystem;
33 import org.codehaus.plexus.redback.users.User;
34 import org.codehaus.plexus.redback.users.UserManager;
35 import org.codehaus.plexus.redback.users.UserNotFoundException;
36 import org.codehaus.plexus.redback.users.jdo.JdoUser;
38 import java.util.ArrayList;
39 import java.util.HashMap;
40 import java.util.List;
44 * SecuritySystem stub used for testing.
48 public class SecuritySystemStub
49 implements SecuritySystem
51 Map<String, String> users = new HashMap<String, String>();
53 List<String> repoIds = new ArrayList<String>();
55 public SecuritySystemStub()
57 users.put( "user1", "password1" );
58 users.put( "user2", "password2" );
59 users.put( "user3", "password3" );
61 repoIds.add( "test-repo" );
64 public SecuritySession authenticate( AuthenticationDataSource source )
65 throws AuthenticationException, UserNotFoundException, AccountLockedException
67 AuthenticationResult result = null;
68 SecuritySession session = null;
70 if ( users.get( source.getPrincipal() ) != null )
72 result = new AuthenticationResult( true, source.getPrincipal(), null );
74 User user = new JdoUser();
75 user.setUsername( source.getPrincipal() );
76 user.setPassword( users.get( source.getPrincipal() ) );
78 session = new DefaultSecuritySession( result, user );
82 result = new AuthenticationResult( false, source.getPrincipal(), null );
83 session = new DefaultSecuritySession( result );
88 public AuthorizationResult authorize( SecuritySession arg0, Object arg1 )
89 throws AuthorizationException
94 public AuthorizationResult authorize( SecuritySession arg0, Object arg1, Object arg2 )
95 throws AuthorizationException
97 AuthorizationResult result = new AuthorizationResult( true, arg1, null );
102 public String getAuthenticatorId()
107 public String getAuthorizerId()
112 public KeyManager getKeyManager()
117 public UserSecurityPolicy getPolicy()
122 public String getUserManagementId()
127 public UserManager getUserManager()
132 public boolean isAuthenticated( AuthenticationDataSource arg0 )
133 throws AuthenticationException, UserNotFoundException, AccountLockedException
138 public boolean isAuthorized( SecuritySession arg0, Object arg1 )
139 throws AuthorizationException
144 public boolean isAuthorized( SecuritySession arg0, Object arg1, Object arg2 )
145 throws AuthorizationException
147 if ( repoIds.contains( arg2 ) )