1 package org.apache.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 junit.framework.TestCase;
23 import org.apache.archiva.redback.users.User;
24 import org.apache.jackrabbit.webdav.DavSessionProvider;
25 import org.apache.jackrabbit.webdav.WebdavRequest;
26 import org.apache.jackrabbit.webdav.WebdavRequestImpl;
27 import org.apache.archiva.security.ServletAuthenticator;
28 import org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
29 import org.codehaus.plexus.redback.authentication.AuthenticationException;
30 import org.codehaus.plexus.redback.authentication.AuthenticationResult;
31 import org.codehaus.plexus.redback.authorization.AuthorizationException;
32 import org.codehaus.plexus.redback.authorization.UnauthorizedException;
33 import org.codehaus.plexus.redback.policy.AccountLockedException;
34 import org.codehaus.plexus.redback.policy.MustChangePasswordException;
35 import org.codehaus.plexus.redback.system.SecuritySession;
36 import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator;
38 import javax.servlet.RequestDispatcher;
39 import javax.servlet.ServletInputStream;
40 import javax.servlet.http.Cookie;
41 import javax.servlet.http.HttpServletRequest;
42 import javax.servlet.http.HttpServletResponse;
43 import javax.servlet.http.HttpSession;
44 import java.io.BufferedReader;
45 import java.io.IOException;
46 import java.io.UnsupportedEncodingException;
47 import java.security.Principal;
48 import java.util.Enumeration;
49 import java.util.Locale;
52 public class ArchivaDavSessionProviderTest
55 private DavSessionProvider sessionProvider;
57 private WebdavRequest request;
60 protected void setUp()
64 sessionProvider = new ArchivaDavSessionProvider( new ServletAuthenticatorMock(), new HttpAuthenticatorMock() );
65 request = new WebdavRequestImpl( new HttpServletRequestMock(), null );
68 public void testAttachSession()
71 assertNull( request.getDavSession() );
72 sessionProvider.attachSession( request );
73 assertNotNull( request.getDavSession() );
76 public void testReleaseSession()
79 assertNull( request.getDavSession() );
80 sessionProvider.attachSession( request );
81 assertNotNull( request.getDavSession() );
83 sessionProvider.releaseSession( request );
84 assertNull( request.getDavSession() );
87 @SuppressWarnings( "unchecked" )
88 private class HttpServletRequestMock
89 implements HttpServletRequest
91 public Object getAttribute( String arg0 )
93 throw new UnsupportedOperationException( "Not supported yet." );
96 public Enumeration getAttributeNames()
98 throw new UnsupportedOperationException( "Not supported yet." );
101 public String getCharacterEncoding()
103 throw new UnsupportedOperationException( "Not supported yet." );
106 public int getContentLength()
108 throw new UnsupportedOperationException( "Not supported yet." );
111 public String getContentType()
113 throw new UnsupportedOperationException( "Not supported yet." );
116 public ServletInputStream getInputStream()
119 throw new UnsupportedOperationException( "Not supported yet." );
122 public String getLocalAddr()
124 throw new UnsupportedOperationException( "Not supported yet." );
127 public String getLocalName()
129 throw new UnsupportedOperationException( "Not supported yet." );
132 public int getLocalPort()
134 throw new UnsupportedOperationException( "Not supported yet." );
137 public Locale getLocale()
139 throw new UnsupportedOperationException( "Not supported yet." );
142 public Enumeration getLocales()
144 throw new UnsupportedOperationException( "Not supported yet." );
147 public String getParameter( String arg0 )
149 throw new UnsupportedOperationException( "Not supported yet." );
152 public Map getParameterMap()
154 throw new UnsupportedOperationException( "Not supported yet." );
157 public Enumeration getParameterNames()
159 throw new UnsupportedOperationException( "Not supported yet." );
162 public String[] getParameterValues( String arg0 )
164 throw new UnsupportedOperationException( "Not supported yet." );
167 public String getProtocol()
169 throw new UnsupportedOperationException( "Not supported yet." );
172 public BufferedReader getReader()
175 throw new UnsupportedOperationException( "Not supported yet." );
178 public String getRealPath( String arg0 )
180 throw new UnsupportedOperationException( "Not supported yet." );
183 public String getRemoteAddr()
185 throw new UnsupportedOperationException( "Not supported yet." );
188 public String getRemoteHost()
190 throw new UnsupportedOperationException( "Not supported yet." );
193 public int getRemotePort()
195 throw new UnsupportedOperationException( "Not supported yet." );
198 public RequestDispatcher getRequestDispatcher( String arg0 )
200 throw new UnsupportedOperationException( "Not supported yet." );
203 public String getScheme()
208 public String getServerName()
210 throw new UnsupportedOperationException( "Not supported yet." );
213 public int getServerPort()
215 throw new UnsupportedOperationException( "Not supported yet." );
218 public boolean isSecure()
220 throw new UnsupportedOperationException( "Not supported yet." );
223 public void removeAttribute( String arg0 )
225 throw new UnsupportedOperationException( "Not supported yet." );
228 public void setAttribute( String arg0, Object arg1 )
230 throw new UnsupportedOperationException( "Not supported yet." );
233 public void setCharacterEncoding( String arg0 )
234 throws UnsupportedEncodingException
236 throw new UnsupportedOperationException( "Not supported yet." );
240 public String getAuthType()
242 throw new UnsupportedOperationException( "Not supported yet." );
245 public String getContextPath()
250 public Cookie[] getCookies()
252 throw new UnsupportedOperationException( "Not supported yet." );
255 public long getDateHeader( String arg0 )
257 throw new UnsupportedOperationException( "Not supported yet." );
260 public String getHeader( String arg0 )
265 public Enumeration getHeaderNames()
267 throw new UnsupportedOperationException( "Not supported yet." );
270 public Enumeration getHeaders( String arg0 )
272 throw new UnsupportedOperationException( "Not supported yet." );
275 public int getIntHeader( String arg0 )
277 throw new UnsupportedOperationException( "Not supported yet." );
280 public String getMethod()
282 throw new UnsupportedOperationException( "Not supported yet." );
285 public String getPathInfo()
287 throw new UnsupportedOperationException( "Not supported yet." );
290 public String getPathTranslated()
292 throw new UnsupportedOperationException( "Not supported yet." );
295 public String getQueryString()
297 throw new UnsupportedOperationException( "Not supported yet." );
300 public String getRemoteUser()
302 throw new UnsupportedOperationException( "Not supported yet." );
305 public String getRequestURI()
310 public StringBuffer getRequestURL()
312 throw new UnsupportedOperationException( "Not supported yet." );
315 public String getRequestedSessionId()
317 throw new UnsupportedOperationException( "Not supported yet." );
320 public String getServletPath()
322 throw new UnsupportedOperationException( "Not supported yet." );
325 public HttpSession getSession( boolean arg0 )
327 throw new UnsupportedOperationException( "Not supported yet." );
330 public HttpSession getSession()
332 throw new UnsupportedOperationException( "Not supported yet." );
335 public Principal getUserPrincipal()
337 throw new UnsupportedOperationException( "Not supported yet." );
340 public boolean isRequestedSessionIdFromCookie()
342 throw new UnsupportedOperationException( "Not supported yet." );
345 public boolean isRequestedSessionIdFromURL()
347 throw new UnsupportedOperationException( "Not supported yet." );
350 public boolean isRequestedSessionIdFromUrl()
352 throw new UnsupportedOperationException( "Not supported yet." );
355 public boolean isRequestedSessionIdValid()
357 throw new UnsupportedOperationException( "Not supported yet." );
360 public boolean isUserInRole( String arg0 )
362 throw new UnsupportedOperationException( "Not supported yet." );
366 private class ServletAuthenticatorMock
367 implements ServletAuthenticator
369 public boolean isAuthenticated( HttpServletRequest arg0, AuthenticationResult arg1 )
370 throws AuthenticationException, AccountLockedException, MustChangePasswordException
375 public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
377 throws AuthorizationException, UnauthorizedException
382 public boolean isAuthorized( String principal, String repoId, String permission )
383 throws UnauthorizedException
389 private class HttpAuthenticatorMock
390 extends HttpAuthenticator
393 public void challenge( HttpServletRequest arg0, HttpServletResponse arg1, String arg2,
394 AuthenticationException arg3 )
401 public AuthenticationResult getAuthenticationResult( HttpServletRequest arg0, HttpServletResponse arg1 )
402 throws AuthenticationException, AccountLockedException, MustChangePasswordException
404 return new AuthenticationResult();
409 public AuthenticationResult authenticate( AuthenticationDataSource arg0, HttpSession httpSession )
410 throws AuthenticationException, AccountLockedException, MustChangePasswordException
412 return new AuthenticationResult();
416 public void authenticate( HttpServletRequest arg0, HttpServletResponse arg1 )
417 throws AuthenticationException
423 public SecuritySession getSecuritySession( HttpSession httpSession )
425 return super.getSecuritySession( httpSession );
429 public User getSessionUser( HttpSession httpSession )
431 return super.getSessionUser( httpSession );
435 public boolean isAlreadyAuthenticated( HttpSession httpSession )
437 return super.isAlreadyAuthenticated( httpSession );