1 package org.apache.maven.archiva.webdav;
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 java.io.BufferedReader;
23 import java.io.IOException;
24 import java.io.UnsupportedEncodingException;
25 import java.security.Principal;
26 import java.util.Enumeration;
27 import java.util.Locale;
29 import javax.servlet.RequestDispatcher;
30 import javax.servlet.ServletInputStream;
31 import javax.servlet.http.Cookie;
32 import javax.servlet.http.HttpServletRequest;
33 import javax.servlet.http.HttpServletResponse;
34 import javax.servlet.http.HttpSession;
35 import junit.framework.TestCase;
36 import org.apache.jackrabbit.webdav.DavSessionProvider;
37 import org.apache.jackrabbit.webdav.WebdavRequest;
38 import org.apache.jackrabbit.webdav.WebdavRequestImpl;
39 import org.apache.maven.archiva.security.ServletAuthenticator;
40 import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
41 import org.codehaus.plexus.redback.authentication.AuthenticationException;
42 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
43 import org.codehaus.plexus.redback.authorization.AuthorizationException;
44 import org.codehaus.plexus.redback.authorization.UnauthorizedException;
45 import org.codehaus.plexus.redback.policy.AccountLockedException;
46 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
47 import org.codehaus.plexus.redback.system.SecuritySession;
48 import org.codehaus.plexus.redback.users.User;
49 import org.codehaus.plexus.redback.xwork.filter.authentication.HttpAuthenticator;
51 public class ArchivaDavSessionProviderTest extends TestCase
53 private DavSessionProvider sessionProvider;
55 private WebdavRequest request;
58 protected void setUp()
62 sessionProvider = new ArchivaDavSessionProvider(new ServletAuthenticatorMock(), new HttpAuthenticatorMock(), null);
63 request = new WebdavRequestImpl(new HttpServletRequestMock(), null);
66 public void testAttachSession()
69 assertNull(request.getDavSession());
70 sessionProvider.attachSession(request);
71 assertNotNull(request.getDavSession());
74 public void testReleaseSession()
77 assertNull(request.getDavSession());
78 sessionProvider.attachSession(request);
79 assertNotNull(request.getDavSession());
81 sessionProvider.releaseSession(request);
82 assertNull(request.getDavSession());
85 private class HttpServletRequestMock implements HttpServletRequest
87 public Object getAttribute(String arg0) {
88 throw new UnsupportedOperationException("Not supported yet.");
91 public Enumeration getAttributeNames() {
92 throw new UnsupportedOperationException("Not supported yet.");
95 public String getCharacterEncoding() {
96 throw new UnsupportedOperationException("Not supported yet.");
99 public int getContentLength() {
100 throw new UnsupportedOperationException("Not supported yet.");
103 public String getContentType() {
104 throw new UnsupportedOperationException("Not supported yet.");
107 public ServletInputStream getInputStream()
110 throw new UnsupportedOperationException("Not supported yet.");
113 public String getLocalAddr() {
114 throw new UnsupportedOperationException("Not supported yet.");
117 public String getLocalName() {
118 throw new UnsupportedOperationException("Not supported yet.");
121 public int getLocalPort() {
122 throw new UnsupportedOperationException("Not supported yet.");
125 public Locale getLocale() {
126 throw new UnsupportedOperationException("Not supported yet.");
129 public Enumeration getLocales()
131 throw new UnsupportedOperationException("Not supported yet.");
134 public String getParameter(String arg0)
136 throw new UnsupportedOperationException("Not supported yet.");
139 public Map getParameterMap()
141 throw new UnsupportedOperationException("Not supported yet.");
144 public Enumeration getParameterNames()
146 throw new UnsupportedOperationException("Not supported yet.");
149 public String[] getParameterValues(String arg0)
151 throw new UnsupportedOperationException("Not supported yet.");
154 public String getProtocol() {
155 throw new UnsupportedOperationException("Not supported yet.");
158 public BufferedReader getReader()
161 throw new UnsupportedOperationException("Not supported yet.");
164 public String getRealPath(String arg0)
166 throw new UnsupportedOperationException("Not supported yet.");
169 public String getRemoteAddr()
171 throw new UnsupportedOperationException("Not supported yet.");
174 public String getRemoteHost()
176 throw new UnsupportedOperationException("Not supported yet.");
179 public int getRemotePort()
181 throw new UnsupportedOperationException("Not supported yet.");
184 public RequestDispatcher getRequestDispatcher(String arg0)
186 throw new UnsupportedOperationException("Not supported yet.");
189 public String getScheme()
194 public String getServerName()
196 throw new UnsupportedOperationException("Not supported yet.");
199 public int getServerPort()
201 throw new UnsupportedOperationException("Not supported yet.");
204 public boolean isSecure()
206 throw new UnsupportedOperationException("Not supported yet.");
209 public void removeAttribute(String arg0)
211 throw new UnsupportedOperationException("Not supported yet.");
214 public void setAttribute(String arg0, Object arg1)
216 throw new UnsupportedOperationException("Not supported yet.");
219 public void setCharacterEncoding(String arg0)
220 throws UnsupportedEncodingException
222 throw new UnsupportedOperationException("Not supported yet.");
226 public String getAuthType()
228 throw new UnsupportedOperationException("Not supported yet.");
231 public String getContextPath()
236 public Cookie[] getCookies()
238 throw new UnsupportedOperationException("Not supported yet.");
241 public long getDateHeader(String arg0)
243 throw new UnsupportedOperationException("Not supported yet.");
246 public String getHeader(String arg0) {
250 public Enumeration getHeaderNames()
252 throw new UnsupportedOperationException("Not supported yet.");
255 public Enumeration getHeaders(String arg0)
257 throw new UnsupportedOperationException("Not supported yet.");
260 public int getIntHeader(String arg0)
262 throw new UnsupportedOperationException("Not supported yet.");
265 public String getMethod()
267 throw new UnsupportedOperationException("Not supported yet.");
270 public String getPathInfo()
272 throw new UnsupportedOperationException("Not supported yet.");
275 public String getPathTranslated()
277 throw new UnsupportedOperationException("Not supported yet.");
280 public String getQueryString()
282 throw new UnsupportedOperationException("Not supported yet.");
285 public String getRemoteUser()
287 throw new UnsupportedOperationException("Not supported yet.");
290 public String getRequestURI()
295 public StringBuffer getRequestURL()
297 throw new UnsupportedOperationException("Not supported yet.");
300 public String getRequestedSessionId()
302 throw new UnsupportedOperationException("Not supported yet.");
305 public String getServletPath()
307 throw new UnsupportedOperationException("Not supported yet.");
310 public HttpSession getSession(boolean arg0)
312 throw new UnsupportedOperationException("Not supported yet.");
315 public HttpSession getSession()
317 throw new UnsupportedOperationException("Not supported yet.");
320 public Principal getUserPrincipal()
322 throw new UnsupportedOperationException("Not supported yet.");
325 public boolean isRequestedSessionIdFromCookie()
327 throw new UnsupportedOperationException("Not supported yet.");
330 public boolean isRequestedSessionIdFromURL()
332 throw new UnsupportedOperationException("Not supported yet.");
335 public boolean isRequestedSessionIdFromUrl()
337 throw new UnsupportedOperationException("Not supported yet.");
340 public boolean isRequestedSessionIdValid()
342 throw new UnsupportedOperationException("Not supported yet.");
345 public boolean isUserInRole(String arg0)
347 throw new UnsupportedOperationException("Not supported yet.");
351 private class ServletAuthenticatorMock implements ServletAuthenticator
353 public boolean isAuthenticated(HttpServletRequest arg0, AuthenticationResult arg1)
354 throws AuthenticationException, AccountLockedException, MustChangePasswordException
359 public boolean isAuthorized(HttpServletRequest arg0, SecuritySession arg1, String arg2, boolean arg3)
360 throws AuthorizationException, UnauthorizedException
365 public boolean isAuthorized(String arg0, String arg1)
366 throws UnauthorizedException
372 private class HttpAuthenticatorMock extends HttpAuthenticator
375 public void challenge(HttpServletRequest arg0, HttpServletResponse arg1, String arg2, AuthenticationException arg3)
382 public AuthenticationResult getAuthenticationResult(HttpServletRequest arg0, HttpServletResponse arg1)
383 throws AuthenticationException, AccountLockedException, MustChangePasswordException
385 return new AuthenticationResult();
390 public AuthenticationResult authenticate(AuthenticationDataSource arg0)
391 throws AuthenticationException, AccountLockedException, MustChangePasswordException
393 return new AuthenticationResult();
397 public void authenticate(HttpServletRequest arg0, HttpServletResponse arg1)
398 throws AuthenticationException
404 public Map getContextSession()
406 return super.getContextSession();
410 public SecuritySession getSecuritySession()
412 return super.getSecuritySession();
416 public User getSessionUser()
418 return super.getSessionUser();
422 public boolean isAlreadyAuthenticated()
424 return super.isAlreadyAuthenticated();
428 public void setSecuritySession(SecuritySession session)
430 super.setSecuritySession(session);
434 public void setSessionUser(User user) {
435 super.setSessionUser(user);
439 public String storeDefaultUser(String user) {
440 return super.storeDefaultUser(user);