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