]> source.dussan.org Git - archiva.git/blob
e858a7d14f875cf35b4e6642b155ce4b378cb67e
[archiva.git] /
1 \r
2 /*\r
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
10  *\r
11  *  http://www.apache.org/licenses/LICENSE-2.0\r
12  *\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
19  */\r
20 package org.apache.maven.archiva.xmlrpc.security;\r
21 \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
39 \r
40 public class XmlRpcAuthenticatorTest extends TestCase\r
41 {\r
42     private static final String USERNAME = "username";\r
43     private static final String PASSWORD = "password";\r
44 \r
45     public void testAuthentication() throws Exception\r
46     {\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
50         \r
51         assertTrue(authenticator.isAuthorized(request));\r
52     }\r
53 \r
54     class MockXmlRpcRequest implements XmlRpcRequest\r
55     {\r
56         private final XmlRpcHttpRequestConfigImpl configImpl;\r
57         \r
58         public MockXmlRpcRequest(String username, String password)\r
59         {\r
60             configImpl = new XmlRpcHttpRequestConfigImpl();\r
61             configImpl.setBasicUserName(username);\r
62             configImpl.setBasicPassword(password);\r
63         }\r
64 \r
65         public XmlRpcRequestConfig getConfig() {\r
66             return configImpl;\r
67         }\r
68 \r
69         public String getMethodName() {\r
70             throw new UnsupportedOperationException("Not supported yet.");\r
71         }\r
72 \r
73         public Object getParameter(int pIndex) {\r
74             throw new UnsupportedOperationException("Not supported yet.");\r
75         }\r
76 \r
77         public int getParameterCount() {\r
78             throw new UnsupportedOperationException("Not supported yet.");\r
79         }\r
80     }\r
81 \r
82     class MockSecuritySystem implements SecuritySystem\r
83     {\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
88 \r
89         public MockSecuritySystem(boolean authorized, boolean authenticate, String username, String password)\r
90         {\r
91             this.authorized = authorized;\r
92             this.authenticate = authenticate;\r
93             this.username = username;\r
94             this.password = password;\r
95         }\r
96 \r
97         public SecuritySession authenticate(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {\r
98             return new SecuritySession() {\r
99 \r
100                 public AuthenticationResult getAuthenticationResult() {\r
101                     throw new UnsupportedOperationException("Not supported yet.");\r
102                 }\r
103 \r
104                 public User getUser() {\r
105                     throw new UnsupportedOperationException("Not supported yet.");\r
106                 }\r
107 \r
108                 public boolean isAuthenticated() {\r
109                     throw new UnsupportedOperationException();\r
110                 }\r
111             };\r
112         }\r
113 \r
114         public AuthorizationResult authorize(SecuritySession session, Object arg1) throws AuthorizationException {\r
115             throw new UnsupportedOperationException("Not supported yet.");\r
116         }\r
117 \r
118         public AuthorizationResult authorize(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {\r
119             throw new UnsupportedOperationException("Not supported yet.");\r
120         }\r
121 \r
122         public String getAuthenticatorId() {\r
123             throw new UnsupportedOperationException("Not supported yet.");\r
124         }\r
125 \r
126         public String getAuthorizerId() {\r
127             throw new UnsupportedOperationException("Not supported yet.");\r
128         }\r
129 \r
130         public KeyManager getKeyManager() {\r
131             throw new UnsupportedOperationException("Not supported yet.");\r
132         }\r
133 \r
134         public UserSecurityPolicy getPolicy() {\r
135             throw new UnsupportedOperationException("Not supported yet.");\r
136         }\r
137 \r
138         public String getUserManagementId() {\r
139             throw new UnsupportedOperationException("Not supported yet.");\r
140         }\r
141 \r
142         public UserManager getUserManager() {\r
143             throw new UnsupportedOperationException("Not supported yet.");\r
144         }\r
145 \r
146         public boolean isAuthenticated(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {\r
147             throw new UnsupportedOperationException("Not supported yet.");\r
148         }\r
149 \r
150         public boolean isAuthorized(SecuritySession session, Object arg1) throws AuthorizationException {\r
151             throw new UnsupportedOperationException("Not supported yet.");\r
152         }\r
153 \r
154         public boolean isAuthorized(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {\r
155             throw new UnsupportedOperationException("Not supported yet.");\r
156         }\r
157     }\r
158 }\r