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.authentication.AuthenticationException;
24 import org.apache.archiva.redback.policy.AccountLockedException;
25 import org.apache.archiva.redback.policy.MustChangePasswordException;
26 import org.apache.archiva.redback.users.User;
27 import org.apache.jackrabbit.webdav.DavSessionProvider;
28 import org.apache.jackrabbit.webdav.WebdavRequest;
29 import org.apache.jackrabbit.webdav.WebdavRequestImpl;
30 import org.apache.archiva.security.ServletAuthenticator;
31 import org.apache.archiva.redback.authentication.AuthenticationDataSource;
32 import org.apache.archiva.redback.authentication.AuthenticationResult;
33 import org.apache.archiva.redback.authorization.AuthorizationException;
34 import org.apache.archiva.redback.authorization.UnauthorizedException;
35 import org.apache.archiva.redback.system.SecuritySession;
36 import org.apache.archiva.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;
51 import org.apache.archiva.test.ArchivaBlockJUnit4ClassRunner;
52 import org.junit.Before;
53 import org.junit.Test;
54 import org.junit.runner.RunWith;
56 @RunWith( ArchivaBlockJUnit4ClassRunner.class )
57 public class ArchivaDavSessionProviderTest
60 private DavSessionProvider sessionProvider;
62 private WebdavRequest request;
70 sessionProvider = new ArchivaDavSessionProvider( new ServletAuthenticatorMock(), new HttpAuthenticatorMock() );
71 request = new WebdavRequestImpl( new HttpServletRequestMock(), null );
75 public void testAttachSession()
78 assertNull( request.getDavSession() );
79 sessionProvider.attachSession( request );
80 assertNotNull( request.getDavSession() );
84 public void testReleaseSession()
87 assertNull( request.getDavSession() );
88 sessionProvider.attachSession( request );
89 assertNotNull( request.getDavSession() );
91 sessionProvider.releaseSession( request );
92 assertNull( request.getDavSession() );
95 @SuppressWarnings( "unchecked" )
96 private class HttpServletRequestMock
97 implements HttpServletRequest
99 public Object getAttribute( String arg0 )
101 throw new UnsupportedOperationException( "Not supported yet." );
104 public Enumeration getAttributeNames()
106 throw new UnsupportedOperationException( "Not supported yet." );
109 public String getCharacterEncoding()
111 throw new UnsupportedOperationException( "Not supported yet." );
114 public int getContentLength()
116 throw new UnsupportedOperationException( "Not supported yet." );
119 public String getContentType()
121 throw new UnsupportedOperationException( "Not supported yet." );
124 public ServletInputStream getInputStream()
127 throw new UnsupportedOperationException( "Not supported yet." );
130 public String getLocalAddr()
132 throw new UnsupportedOperationException( "Not supported yet." );
135 public String getLocalName()
137 throw new UnsupportedOperationException( "Not supported yet." );
140 public int getLocalPort()
142 throw new UnsupportedOperationException( "Not supported yet." );
145 public Locale getLocale()
147 throw new UnsupportedOperationException( "Not supported yet." );
150 public Enumeration getLocales()
152 throw new UnsupportedOperationException( "Not supported yet." );
155 public String getParameter( String arg0 )
157 throw new UnsupportedOperationException( "Not supported yet." );
160 public Map getParameterMap()
162 throw new UnsupportedOperationException( "Not supported yet." );
165 public Enumeration getParameterNames()
167 throw new UnsupportedOperationException( "Not supported yet." );
170 public String[] getParameterValues( String arg0 )
172 throw new UnsupportedOperationException( "Not supported yet." );
175 public String getProtocol()
177 throw new UnsupportedOperationException( "Not supported yet." );
180 public BufferedReader getReader()
183 throw new UnsupportedOperationException( "Not supported yet." );
186 public String getRealPath( String arg0 )
188 throw new UnsupportedOperationException( "Not supported yet." );
191 public String getRemoteAddr()
193 throw new UnsupportedOperationException( "Not supported yet." );
196 public String getRemoteHost()
198 throw new UnsupportedOperationException( "Not supported yet." );
201 public int getRemotePort()
203 throw new UnsupportedOperationException( "Not supported yet." );
206 public RequestDispatcher getRequestDispatcher( String arg0 )
208 throw new UnsupportedOperationException( "Not supported yet." );
211 public String getScheme()
216 public String getServerName()
218 throw new UnsupportedOperationException( "Not supported yet." );
221 public int getServerPort()
223 throw new UnsupportedOperationException( "Not supported yet." );
226 public boolean isSecure()
228 throw new UnsupportedOperationException( "Not supported yet." );
231 public void removeAttribute( String arg0 )
233 throw new UnsupportedOperationException( "Not supported yet." );
236 public void setAttribute( String arg0, Object arg1 )
238 throw new UnsupportedOperationException( "Not supported yet." );
241 public void setCharacterEncoding( String arg0 )
242 throws UnsupportedEncodingException
244 throw new UnsupportedOperationException( "Not supported yet." );
248 public String getAuthType()
250 throw new UnsupportedOperationException( "Not supported yet." );
253 public String getContextPath()
258 public Cookie[] getCookies()
260 throw new UnsupportedOperationException( "Not supported yet." );
263 public long getDateHeader( String arg0 )
265 throw new UnsupportedOperationException( "Not supported yet." );
268 public String getHeader( String arg0 )
273 public Enumeration getHeaderNames()
275 throw new UnsupportedOperationException( "Not supported yet." );
278 public Enumeration getHeaders( String arg0 )
280 throw new UnsupportedOperationException( "Not supported yet." );
283 public int getIntHeader( String arg0 )
285 throw new UnsupportedOperationException( "Not supported yet." );
288 public String getMethod()
290 throw new UnsupportedOperationException( "Not supported yet." );
293 public String getPathInfo()
295 throw new UnsupportedOperationException( "Not supported yet." );
298 public String getPathTranslated()
300 throw new UnsupportedOperationException( "Not supported yet." );
303 public String getQueryString()
305 throw new UnsupportedOperationException( "Not supported yet." );
308 public String getRemoteUser()
310 throw new UnsupportedOperationException( "Not supported yet." );
313 public String getRequestURI()
318 public StringBuffer getRequestURL()
320 throw new UnsupportedOperationException( "Not supported yet." );
323 public String getRequestedSessionId()
325 throw new UnsupportedOperationException( "Not supported yet." );
328 public String getServletPath()
330 throw new UnsupportedOperationException( "Not supported yet." );
333 public HttpSession getSession( boolean arg0 )
335 throw new UnsupportedOperationException( "Not supported yet." );
338 public HttpSession getSession()
340 throw new UnsupportedOperationException( "Not supported yet." );
343 public Principal getUserPrincipal()
345 throw new UnsupportedOperationException( "Not supported yet." );
348 public boolean isRequestedSessionIdFromCookie()
350 throw new UnsupportedOperationException( "Not supported yet." );
353 public boolean isRequestedSessionIdFromURL()
355 throw new UnsupportedOperationException( "Not supported yet." );
358 public boolean isRequestedSessionIdFromUrl()
360 throw new UnsupportedOperationException( "Not supported yet." );
363 public boolean isRequestedSessionIdValid()
365 throw new UnsupportedOperationException( "Not supported yet." );
368 public boolean isUserInRole( String arg0 )
370 throw new UnsupportedOperationException( "Not supported yet." );
374 private class ServletAuthenticatorMock
375 implements ServletAuthenticator
377 public boolean isAuthenticated( HttpServletRequest arg0, AuthenticationResult arg1 )
378 throws AuthenticationException, AccountLockedException, MustChangePasswordException
383 public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
385 throws AuthorizationException, UnauthorizedException
390 public boolean isAuthorized( String principal, String repoId, String permission )
391 throws UnauthorizedException
397 private class HttpAuthenticatorMock
398 extends HttpAuthenticator
401 public void challenge( HttpServletRequest arg0, HttpServletResponse arg1, String arg2,
402 AuthenticationException arg3 )
409 public AuthenticationResult getAuthenticationResult( HttpServletRequest arg0, HttpServletResponse arg1 )
410 throws AuthenticationException, AccountLockedException, MustChangePasswordException
412 return new AuthenticationResult();
417 public AuthenticationResult authenticate( AuthenticationDataSource arg0, HttpSession httpSession )
418 throws AuthenticationException, AccountLockedException, MustChangePasswordException
420 return new AuthenticationResult();
424 public void authenticate( HttpServletRequest arg0, HttpServletResponse arg1 )
425 throws AuthenticationException
431 public SecuritySession getSecuritySession( HttpSession httpSession )
433 return super.getSecuritySession( httpSession );
437 public User getSessionUser( HttpSession httpSession )
439 return super.getSessionUser( httpSession );
443 public boolean isAlreadyAuthenticated( HttpSession httpSession )
445 return super.isAlreadyAuthenticated( httpSession );