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;
30 import javax.servlet.RequestDispatcher;
31 import javax.servlet.ServletInputStream;
32 import javax.servlet.http.Cookie;
33 import javax.servlet.http.HttpServletRequest;
34 import javax.servlet.http.HttpServletResponse;
35 import javax.servlet.http.HttpSession;
37 import junit.framework.TestCase;
39 import org.apache.jackrabbit.webdav.DavSessionProvider;
40 import org.apache.jackrabbit.webdav.WebdavRequest;
41 import org.apache.jackrabbit.webdav.WebdavRequestImpl;
42 import org.apache.maven.archiva.security.ServletAuthenticator;
43 import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
44 import org.codehaus.plexus.redback.authentication.AuthenticationException;
45 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
46 import org.codehaus.plexus.redback.authorization.AuthorizationException;
47 import org.codehaus.plexus.redback.authorization.UnauthorizedException;
48 import org.codehaus.plexus.redback.policy.AccountLockedException;
49 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
50 import org.codehaus.plexus.redback.system.SecuritySession;
51 import org.codehaus.plexus.redback.users.User;
52 import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator;
54 public class ArchivaDavSessionProviderTest extends TestCase
56 private DavSessionProvider sessionProvider;
58 private WebdavRequest request;
61 protected void setUp()
65 sessionProvider = new ArchivaDavSessionProvider(new ServletAuthenticatorMock(), new HttpAuthenticatorMock(), null);
66 request = new WebdavRequestImpl(new HttpServletRequestMock(), null);
69 public void testAttachSession()
72 assertNull(request.getDavSession());
73 sessionProvider.attachSession(request);
74 assertNotNull(request.getDavSession());
77 public void testReleaseSession()
80 assertNull(request.getDavSession());
81 sessionProvider.attachSession(request);
82 assertNotNull(request.getDavSession());
84 sessionProvider.releaseSession(request);
85 assertNull(request.getDavSession());
88 @SuppressWarnings("unchecked")
89 private class HttpServletRequestMock implements HttpServletRequest
91 public Object getAttribute(String arg0) {
92 throw new UnsupportedOperationException("Not supported yet.");
95 public Enumeration getAttributeNames() {
96 throw new UnsupportedOperationException("Not supported yet.");
99 public String getCharacterEncoding() {
100 throw new UnsupportedOperationException("Not supported yet.");
103 public int getContentLength() {
104 throw new UnsupportedOperationException("Not supported yet.");
107 public String getContentType() {
108 throw new UnsupportedOperationException("Not supported yet.");
111 public ServletInputStream getInputStream()
114 throw new UnsupportedOperationException("Not supported yet.");
117 public String getLocalAddr() {
118 throw new UnsupportedOperationException("Not supported yet.");
121 public String getLocalName() {
122 throw new UnsupportedOperationException("Not supported yet.");
125 public int getLocalPort() {
126 throw new UnsupportedOperationException("Not supported yet.");
129 public Locale getLocale() {
130 throw new UnsupportedOperationException("Not supported yet.");
133 public Enumeration getLocales()
135 throw new UnsupportedOperationException("Not supported yet.");
138 public String getParameter(String arg0)
140 throw new UnsupportedOperationException("Not supported yet.");
143 public Map getParameterMap()
145 throw new UnsupportedOperationException("Not supported yet.");
148 public Enumeration getParameterNames()
150 throw new UnsupportedOperationException("Not supported yet.");
153 public String[] getParameterValues(String arg0)
155 throw new UnsupportedOperationException("Not supported yet.");
158 public String getProtocol() {
159 throw new UnsupportedOperationException("Not supported yet.");
162 public BufferedReader getReader()
165 throw new UnsupportedOperationException("Not supported yet.");
168 public String getRealPath(String arg0)
170 throw new UnsupportedOperationException("Not supported yet.");
173 public String getRemoteAddr()
175 throw new UnsupportedOperationException("Not supported yet.");
178 public String getRemoteHost()
180 throw new UnsupportedOperationException("Not supported yet.");
183 public int getRemotePort()
185 throw new UnsupportedOperationException("Not supported yet.");
188 public RequestDispatcher getRequestDispatcher(String arg0)
190 throw new UnsupportedOperationException("Not supported yet.");
193 public String getScheme()
198 public String getServerName()
200 throw new UnsupportedOperationException("Not supported yet.");
203 public int getServerPort()
205 throw new UnsupportedOperationException("Not supported yet.");
208 public boolean isSecure()
210 throw new UnsupportedOperationException("Not supported yet.");
213 public void removeAttribute(String arg0)
215 throw new UnsupportedOperationException("Not supported yet.");
218 public void setAttribute(String arg0, Object arg1)
220 throw new UnsupportedOperationException("Not supported yet.");
223 public void setCharacterEncoding(String arg0)
224 throws UnsupportedEncodingException
226 throw new UnsupportedOperationException("Not supported yet.");
230 public String getAuthType()
232 throw new UnsupportedOperationException("Not supported yet.");
235 public String getContextPath()
240 public Cookie[] getCookies()
242 throw new UnsupportedOperationException("Not supported yet.");
245 public long getDateHeader(String arg0)
247 throw new UnsupportedOperationException("Not supported yet.");
250 public String getHeader(String arg0) {
254 public Enumeration getHeaderNames()
256 throw new UnsupportedOperationException("Not supported yet.");
259 public Enumeration getHeaders(String arg0)
261 throw new UnsupportedOperationException("Not supported yet.");
264 public int getIntHeader(String arg0)
266 throw new UnsupportedOperationException("Not supported yet.");
269 public String getMethod()
271 throw new UnsupportedOperationException("Not supported yet.");
274 public String getPathInfo()
276 throw new UnsupportedOperationException("Not supported yet.");
279 public String getPathTranslated()
281 throw new UnsupportedOperationException("Not supported yet.");
284 public String getQueryString()
286 throw new UnsupportedOperationException("Not supported yet.");
289 public String getRemoteUser()
291 throw new UnsupportedOperationException("Not supported yet.");
294 public String getRequestURI()
299 public StringBuffer getRequestURL()
301 throw new UnsupportedOperationException("Not supported yet.");
304 public String getRequestedSessionId()
306 throw new UnsupportedOperationException("Not supported yet.");
309 public String getServletPath()
311 throw new UnsupportedOperationException("Not supported yet.");
314 public HttpSession getSession(boolean arg0)
316 throw new UnsupportedOperationException("Not supported yet.");
319 public HttpSession getSession()
321 throw new UnsupportedOperationException("Not supported yet.");
324 public Principal getUserPrincipal()
326 throw new UnsupportedOperationException("Not supported yet.");
329 public boolean isRequestedSessionIdFromCookie()
331 throw new UnsupportedOperationException("Not supported yet.");
334 public boolean isRequestedSessionIdFromURL()
336 throw new UnsupportedOperationException("Not supported yet.");
339 public boolean isRequestedSessionIdFromUrl()
341 throw new UnsupportedOperationException("Not supported yet.");
344 public boolean isRequestedSessionIdValid()
346 throw new UnsupportedOperationException("Not supported yet.");
349 public boolean isUserInRole(String arg0)
351 throw new UnsupportedOperationException("Not supported yet.");
355 private class ServletAuthenticatorMock implements ServletAuthenticator
357 public boolean isAuthenticated(HttpServletRequest arg0, AuthenticationResult arg1)
358 throws AuthenticationException, AccountLockedException, MustChangePasswordException
363 public boolean isAuthorized(HttpServletRequest arg0, SecuritySession arg1, String arg2, boolean arg3)
364 throws AuthorizationException, UnauthorizedException
369 public boolean isAuthorized(String arg0, String arg1, boolean isWriteRequest)
370 throws UnauthorizedException
376 private class HttpAuthenticatorMock extends HttpAuthenticator
379 public void challenge(HttpServletRequest arg0, HttpServletResponse arg1, String arg2, AuthenticationException arg3)
386 public AuthenticationResult getAuthenticationResult(HttpServletRequest arg0, HttpServletResponse arg1)
387 throws AuthenticationException, AccountLockedException, MustChangePasswordException
389 return new AuthenticationResult();
394 public AuthenticationResult authenticate(AuthenticationDataSource arg0, HttpSession httpSession)
395 throws AuthenticationException, AccountLockedException, MustChangePasswordException
397 return new AuthenticationResult();
401 public void authenticate(HttpServletRequest arg0, HttpServletResponse arg1)
402 throws AuthenticationException
408 public SecuritySession getSecuritySession(HttpSession httpSession)
410 return super.getSecuritySession(httpSession);
414 public User getSessionUser(HttpSession httpSession)
416 return super.getSessionUser(httpSession);
420 public boolean isAlreadyAuthenticated(HttpSession httpSession)
422 return super.isAlreadyAuthenticated(httpSession);