3 * Licensed to the Apache Software Foundation (ASF) under one
\r
4 * or more contributor license agreements. See the NOTICE file
\r
5 * distributed with this work for additional information
\r
6 * regarding copyright ownership. The ASF licenses this file
\r
7 * to you under the Apache License, Version 2.0 (the
\r
8 * "License"); you may not use this file except in compliance
\r
9 * with the License. You may obtain a copy of the License at
\r
11 * http://www.apache.org/licenses/LICENSE-2.0
\r
13 * Unless required by applicable law or agreed to in writing,
\r
14 * software distributed under the License is distributed on an
\r
15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
\r
16 * KIND, either express or implied. See the License for the
\r
17 * specific language governing permissions and limitations
\r
18 * under the License.
\r
20 package org.apache.maven.archiva.xmlrpc.security;
\r
22 import junit.framework.TestCase;
\r
23 import org.apache.xmlrpc.XmlRpcRequest;
\r
24 import org.apache.xmlrpc.XmlRpcRequestConfig;
\r
25 import org.apache.xmlrpc.common.XmlRpcHttpRequestConfigImpl;
\r
26 import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
\r
27 import org.codehaus.plexus.redback.authentication.AuthenticationException;
\r
28 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
\r
29 import org.codehaus.plexus.redback.authorization.AuthorizationException;
\r
30 import org.codehaus.plexus.redback.authorization.AuthorizationResult;
\r
31 import org.codehaus.plexus.redback.keys.KeyManager;
\r
32 import org.codehaus.plexus.redback.policy.AccountLockedException;
\r
33 import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
\r
34 import org.codehaus.plexus.redback.system.SecuritySession;
\r
35 import org.codehaus.plexus.redback.system.SecuritySystem;
\r
36 import org.codehaus.plexus.redback.users.User;
\r
37 import org.codehaus.plexus.redback.users.UserManager;
\r
38 import org.codehaus.plexus.redback.users.UserNotFoundException;
\r
40 public class XmlRpcAuthenticatorTest extends TestCase
\r
42 private static final String USERNAME = "username";
\r
43 private static final String PASSWORD = "password";
\r
45 public void testAuthentication() throws Exception
\r
47 MockSecuritySystem securitySystem = new MockSecuritySystem(true, true, USERNAME, PASSWORD);
\r
48 XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator(securitySystem);
\r
49 MockXmlRpcRequest request = new MockXmlRpcRequest(USERNAME, PASSWORD);
\r
51 assertTrue(authenticator.isAuthorized(request));
\r
54 class MockXmlRpcRequest implements XmlRpcRequest
\r
56 private final XmlRpcHttpRequestConfigImpl configImpl;
\r
58 public MockXmlRpcRequest(String username, String password)
\r
60 configImpl = new XmlRpcHttpRequestConfigImpl();
\r
61 configImpl.setBasicUserName(username);
\r
62 configImpl.setBasicPassword(password);
\r
65 public XmlRpcRequestConfig getConfig() {
\r
69 public String getMethodName() {
\r
70 throw new UnsupportedOperationException("Not supported yet.");
\r
73 public Object getParameter(int pIndex) {
\r
74 throw new UnsupportedOperationException("Not supported yet.");
\r
77 public int getParameterCount() {
\r
78 throw new UnsupportedOperationException("Not supported yet.");
\r
82 class MockSecuritySystem implements SecuritySystem
\r
84 private final boolean authorized;
\r
85 private final boolean authenticate;
\r
86 private final String username;
\r
87 private final String password;
\r
89 public MockSecuritySystem(boolean authorized, boolean authenticate, String username, String password)
\r
91 this.authorized = authorized;
\r
92 this.authenticate = authenticate;
\r
93 this.username = username;
\r
94 this.password = password;
\r
97 public SecuritySession authenticate(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {
\r
98 return new SecuritySession() {
\r
100 public AuthenticationResult getAuthenticationResult() {
\r
101 throw new UnsupportedOperationException("Not supported yet.");
\r
104 public User getUser() {
\r
105 throw new UnsupportedOperationException("Not supported yet.");
\r
108 public boolean isAuthenticated() {
\r
109 throw new UnsupportedOperationException();
\r
114 public AuthorizationResult authorize(SecuritySession session, Object arg1) throws AuthorizationException {
\r
115 throw new UnsupportedOperationException("Not supported yet.");
\r
118 public AuthorizationResult authorize(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {
\r
119 throw new UnsupportedOperationException("Not supported yet.");
\r
122 public String getAuthenticatorId() {
\r
123 throw new UnsupportedOperationException("Not supported yet.");
\r
126 public String getAuthorizerId() {
\r
127 throw new UnsupportedOperationException("Not supported yet.");
\r
130 public KeyManager getKeyManager() {
\r
131 throw new UnsupportedOperationException("Not supported yet.");
\r
134 public UserSecurityPolicy getPolicy() {
\r
135 throw new UnsupportedOperationException("Not supported yet.");
\r
138 public String getUserManagementId() {
\r
139 throw new UnsupportedOperationException("Not supported yet.");
\r
142 public UserManager getUserManager() {
\r
143 throw new UnsupportedOperationException("Not supported yet.");
\r
146 public boolean isAuthenticated(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {
\r
147 throw new UnsupportedOperationException("Not supported yet.");
\r
150 public boolean isAuthorized(SecuritySession session, Object arg1) throws AuthorizationException {
\r
151 throw new UnsupportedOperationException("Not supported yet.");
\r
154 public boolean isAuthorized(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {
\r
155 throw new UnsupportedOperationException("Not supported yet.");
\r