2 * Licensed to the Apache Software Foundation (ASF) under one
\r
3 * or more contributor license agreements. See the NOTICE file
\r
4 * distributed with this work for additional information
\r
5 * regarding copyright ownership. The ASF licenses this file
\r
6 * to you under the Apache License, Version 2.0 (the
\r
7 * "License"); you may not use this file except in compliance
\r
8 * with the License. You may obtain a copy of the License at
\r
10 * http://www.apache.org/licenses/LICENSE-2.0
\r
12 * Unless required by applicable law or agreed to in writing,
\r
13 * software distributed under the License is distributed on an
\r
14 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
\r
15 * KIND, either express or implied. See the License for the
\r
16 * specific language governing permissions and limitations
\r
17 * under the License.
\r
19 package org.apache.maven.archiva.xmlrpc.security;
\r
21 import junit.framework.TestCase;
\r
22 import org.apache.xmlrpc.XmlRpcRequest;
\r
23 import org.apache.xmlrpc.XmlRpcRequestConfig;
\r
24 import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
\r
25 import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
\r
26 import org.codehaus.plexus.redback.authentication.AuthenticationException;
\r
27 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
\r
28 import org.codehaus.plexus.redback.authorization.AuthorizationException;
\r
29 import org.codehaus.plexus.redback.authorization.AuthorizationResult;
\r
30 import org.codehaus.plexus.redback.keys.KeyManager;
\r
31 import org.codehaus.plexus.redback.policy.AccountLockedException;
\r
32 import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
\r
33 import org.codehaus.plexus.redback.system.SecuritySession;
\r
34 import org.codehaus.plexus.redback.system.SecuritySystem;
\r
35 import org.codehaus.plexus.redback.users.User;
\r
36 import org.codehaus.plexus.redback.users.UserManager;
\r
37 import org.codehaus.plexus.redback.users.UserNotFoundException;
\r
39 public class XmlRpcAuthenticatorTest
\r
42 private static final String USERNAME = "username";
\r
44 private static final String PASSWORD = "password";
\r
46 public void testAuthentication()
\r
49 MockSecuritySystem securitySystem = new MockSecuritySystem( true, true, USERNAME, PASSWORD );
\r
50 XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator( securitySystem );
\r
51 MockXmlRpcRequest request = new MockXmlRpcRequest( USERNAME, PASSWORD );
\r
53 //assertTrue( authenticator.isAuthorized( request ) );
\r
56 class MockXmlRpcRequest
\r
57 implements XmlRpcRequest
\r
59 private final XmlRpcHttpRequestConfigImpl configImpl;
\r
61 public MockXmlRpcRequest( String username, String password )
\r
63 configImpl = new XmlRpcHttpRequestConfigImpl();
\r
64 configImpl.setBasicUserName( username );
\r
65 configImpl.setBasicPassword( password );
\r
68 public XmlRpcRequestConfig getConfig()
\r
73 public String getMethodName()
\r
75 throw new UnsupportedOperationException( "Not supported yet." );
\r
78 public Object getParameter( int pIndex )
\r
80 throw new UnsupportedOperationException( "Not supported yet." );
\r
83 public int getParameterCount()
\r
85 throw new UnsupportedOperationException( "Not supported yet." );
\r
89 class MockSecuritySystem
\r
90 implements SecuritySystem
\r
92 private final boolean authorized;
\r
94 private final boolean authenticate;
\r
96 private final String username;
\r
98 private final String password;
\r
100 public MockSecuritySystem( boolean authorized, boolean authenticate, String username, String password )
\r
102 this.authorized = authorized;
\r
103 this.authenticate = authenticate;
\r
104 this.username = username;
\r
105 this.password = password;
\r
108 public SecuritySession authenticate( AuthenticationDataSource dataSource )
\r
109 throws AuthenticationException, UserNotFoundException, AccountLockedException
\r
111 return new SecuritySession()
\r
114 public AuthenticationResult getAuthenticationResult()
\r
116 throw new UnsupportedOperationException( "Not supported yet." );
\r
119 public User getUser()
\r
121 throw new UnsupportedOperationException( "Not supported yet." );
\r
124 public boolean isAuthenticated()
\r
126 throw new UnsupportedOperationException();
\r
131 public AuthorizationResult authorize( SecuritySession session, Object arg1 )
\r
132 throws AuthorizationException
\r
134 throw new UnsupportedOperationException( "Not supported yet." );
\r
137 public AuthorizationResult authorize( SecuritySession session, Object arg1, Object arg2 )
\r
138 throws AuthorizationException
\r
140 throw new UnsupportedOperationException( "Not supported yet." );
\r
143 public String getAuthenticatorId()
\r
145 throw new UnsupportedOperationException( "Not supported yet." );
\r
148 public String getAuthorizerId()
\r
150 throw new UnsupportedOperationException( "Not supported yet." );
\r
153 public KeyManager getKeyManager()
\r
155 throw new UnsupportedOperationException( "Not supported yet." );
\r
158 public UserSecurityPolicy getPolicy()
\r
160 throw new UnsupportedOperationException( "Not supported yet." );
\r
163 public String getUserManagementId()
\r
165 throw new UnsupportedOperationException( "Not supported yet." );
\r
168 public UserManager getUserManager()
\r
170 throw new UnsupportedOperationException( "Not supported yet." );
\r
173 public boolean isAuthenticated( AuthenticationDataSource dataSource )
\r
174 throws AuthenticationException, UserNotFoundException, AccountLockedException
\r
176 throw new UnsupportedOperationException( "Not supported yet." );
\r
179 public boolean isAuthorized( SecuritySession session, Object arg1 )
\r
180 throws AuthorizationException
\r
182 throw new UnsupportedOperationException( "Not supported yet." );
\r
185 public boolean isAuthorized( SecuritySession session, Object arg1, Object arg2 )
\r
186 throws AuthorizationException
\r
188 throw new UnsupportedOperationException( "Not supported yet." );
\r