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 private class HttpServletRequestMock implements HttpServletRequest
90 public Object getAttribute(String arg0) {
91 throw new UnsupportedOperationException("Not supported yet.");
94 public Enumeration getAttributeNames() {
95 throw new UnsupportedOperationException("Not supported yet.");
98 public String getCharacterEncoding() {
99 throw new UnsupportedOperationException("Not supported yet.");
102 public int getContentLength() {
103 throw new UnsupportedOperationException("Not supported yet.");
106 public String getContentType() {
107 throw new UnsupportedOperationException("Not supported yet.");
110 public ServletInputStream getInputStream()
113 throw new UnsupportedOperationException("Not supported yet.");
116 public String getLocalAddr() {
117 throw new UnsupportedOperationException("Not supported yet.");
120 public String getLocalName() {
121 throw new UnsupportedOperationException("Not supported yet.");
124 public int getLocalPort() {
125 throw new UnsupportedOperationException("Not supported yet.");
128 public Locale getLocale() {
129 throw new UnsupportedOperationException("Not supported yet.");
132 public Enumeration getLocales()
134 throw new UnsupportedOperationException("Not supported yet.");
137 public String getParameter(String arg0)
139 throw new UnsupportedOperationException("Not supported yet.");
142 public Map getParameterMap()
144 throw new UnsupportedOperationException("Not supported yet.");
147 public Enumeration getParameterNames()
149 throw new UnsupportedOperationException("Not supported yet.");
152 public String[] getParameterValues(String arg0)
154 throw new UnsupportedOperationException("Not supported yet.");
157 public String getProtocol() {
158 throw new UnsupportedOperationException("Not supported yet.");
161 public BufferedReader getReader()
164 throw new UnsupportedOperationException("Not supported yet.");
167 public String getRealPath(String arg0)
169 throw new UnsupportedOperationException("Not supported yet.");
172 public String getRemoteAddr()
174 throw new UnsupportedOperationException("Not supported yet.");
177 public String getRemoteHost()
179 throw new UnsupportedOperationException("Not supported yet.");
182 public int getRemotePort()
184 throw new UnsupportedOperationException("Not supported yet.");
187 public RequestDispatcher getRequestDispatcher(String arg0)
189 throw new UnsupportedOperationException("Not supported yet.");
192 public String getScheme()
197 public String getServerName()
199 throw new UnsupportedOperationException("Not supported yet.");
202 public int getServerPort()
204 throw new UnsupportedOperationException("Not supported yet.");
207 public boolean isSecure()
209 throw new UnsupportedOperationException("Not supported yet.");
212 public void removeAttribute(String arg0)
214 throw new UnsupportedOperationException("Not supported yet.");
217 public void setAttribute(String arg0, Object arg1)
219 throw new UnsupportedOperationException("Not supported yet.");
222 public void setCharacterEncoding(String arg0)
223 throws UnsupportedEncodingException
225 throw new UnsupportedOperationException("Not supported yet.");
229 public String getAuthType()
231 throw new UnsupportedOperationException("Not supported yet.");
234 public String getContextPath()
239 public Cookie[] getCookies()
241 throw new UnsupportedOperationException("Not supported yet.");
244 public long getDateHeader(String arg0)
246 throw new UnsupportedOperationException("Not supported yet.");
249 public String getHeader(String arg0) {
253 public Enumeration getHeaderNames()
255 throw new UnsupportedOperationException("Not supported yet.");
258 public Enumeration getHeaders(String arg0)
260 throw new UnsupportedOperationException("Not supported yet.");
263 public int getIntHeader(String arg0)
265 throw new UnsupportedOperationException("Not supported yet.");
268 public String getMethod()
270 throw new UnsupportedOperationException("Not supported yet.");
273 public String getPathInfo()
275 throw new UnsupportedOperationException("Not supported yet.");
278 public String getPathTranslated()
280 throw new UnsupportedOperationException("Not supported yet.");
283 public String getQueryString()
285 throw new UnsupportedOperationException("Not supported yet.");
288 public String getRemoteUser()
290 throw new UnsupportedOperationException("Not supported yet.");
293 public String getRequestURI()
298 public StringBuffer getRequestURL()
300 throw new UnsupportedOperationException("Not supported yet.");
303 public String getRequestedSessionId()
305 throw new UnsupportedOperationException("Not supported yet.");
308 public String getServletPath()
310 throw new UnsupportedOperationException("Not supported yet.");
313 public HttpSession getSession(boolean arg0)
315 throw new UnsupportedOperationException("Not supported yet.");
318 public HttpSession getSession()
320 throw new UnsupportedOperationException("Not supported yet.");
323 public Principal getUserPrincipal()
325 throw new UnsupportedOperationException("Not supported yet.");
328 public boolean isRequestedSessionIdFromCookie()
330 throw new UnsupportedOperationException("Not supported yet.");
333 public boolean isRequestedSessionIdFromURL()
335 throw new UnsupportedOperationException("Not supported yet.");
338 public boolean isRequestedSessionIdFromUrl()
340 throw new UnsupportedOperationException("Not supported yet.");
343 public boolean isRequestedSessionIdValid()
345 throw new UnsupportedOperationException("Not supported yet.");
348 public boolean isUserInRole(String arg0)
350 throw new UnsupportedOperationException("Not supported yet.");
354 private class ServletAuthenticatorMock implements ServletAuthenticator
356 public boolean isAuthenticated(HttpServletRequest arg0, AuthenticationResult arg1)
357 throws AuthenticationException, AccountLockedException, MustChangePasswordException
362 public boolean isAuthorized(HttpServletRequest arg0, SecuritySession arg1, String arg2, boolean arg3)
363 throws AuthorizationException, UnauthorizedException
368 public boolean isAuthorized(String arg0, String arg1, boolean isWriteRequest)
369 throws UnauthorizedException
375 private class HttpAuthenticatorMock extends HttpAuthenticator
378 public void challenge(HttpServletRequest arg0, HttpServletResponse arg1, String arg2, AuthenticationException arg3)
385 public AuthenticationResult getAuthenticationResult(HttpServletRequest arg0, HttpServletResponse arg1)
386 throws AuthenticationException, AccountLockedException, MustChangePasswordException
388 return new AuthenticationResult();
393 public AuthenticationResult authenticate(AuthenticationDataSource arg0, HttpSession httpSession)
394 throws AuthenticationException, AccountLockedException, MustChangePasswordException
396 return new AuthenticationResult();
400 public void authenticate(HttpServletRequest arg0, HttpServletResponse arg1)
401 throws AuthenticationException
407 public SecuritySession getSecuritySession(HttpSession httpSession)
409 return super.getSecuritySession(httpSession);
413 public User getSessionUser(HttpSession httpSession)
415 return super.getSessionUser(httpSession);
419 public boolean isAlreadyAuthenticated(HttpSession httpSession)
421 return super.isAlreadyAuthenticated(httpSession);