123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598 |
- package org.apache.archiva.webdav;
-
- /*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-
- import junit.framework.TestCase;
- import org.apache.archiva.redback.authentication.AuthenticationDataSource;
- import org.apache.archiva.redback.authentication.AuthenticationException;
- import org.apache.archiva.redback.authentication.AuthenticationResult;
- import org.apache.archiva.redback.authorization.AuthorizationException;
- import org.apache.archiva.redback.authorization.UnauthorizedException;
- import org.apache.archiva.redback.integration.filter.authentication.HttpAuthenticator;
- import org.apache.archiva.redback.policy.AccountLockedException;
- import org.apache.archiva.redback.policy.MustChangePasswordException;
- import org.apache.archiva.redback.system.SecuritySession;
- import org.apache.archiva.redback.users.User;
- import org.apache.archiva.security.ServletAuthenticator;
- import org.apache.archiva.test.utils.ArchivaBlockJUnit4ClassRunner;
- import org.apache.jackrabbit.webdav.DavSessionProvider;
- import org.apache.jackrabbit.webdav.WebdavRequest;
- import org.apache.jackrabbit.webdav.WebdavRequestImpl;
- import org.junit.Before;
- import org.junit.Test;
- import org.junit.runner.RunWith;
- import org.springframework.mock.web.MockHttpServletRequest;
-
- import javax.servlet.http.HttpServletRequest;
- import javax.servlet.http.HttpServletResponse;
- import javax.servlet.http.HttpSession;
- import java.io.IOException;
-
- @RunWith( ArchivaBlockJUnit4ClassRunner.class )
- public class ArchivaDavSessionProviderTest
- extends TestCase
- {
- private DavSessionProvider sessionProvider;
-
- private WebdavRequest request;
-
- @Override
- @Before
- public void setUp()
- throws Exception
- {
- super.setUp();
- sessionProvider = new ArchivaDavSessionProvider( new ServletAuthenticatorMock(), new HttpAuthenticatorMock() );
- request = new WebdavRequestImpl( new MockHttpServletRequest(), null );
- }
-
- @Test
- public void testAttachSession()
- throws Exception
- {
- assertNull( request.getDavSession() );
- sessionProvider.attachSession( request );
- assertNotNull( request.getDavSession() );
- }
-
- @Test
- public void testReleaseSession()
- throws Exception
- {
- assertNull( request.getDavSession() );
- sessionProvider.attachSession( request );
- assertNotNull( request.getDavSession() );
-
- sessionProvider.releaseSession( request );
- assertNull( request.getDavSession() );
- }
-
- @SuppressWarnings( "unchecked" )
- /*
- private class HttpServletRequestMock
- implements HttpServletRequest
- {
-
- @Override
- public long getContentLengthLong()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String changeSessionId()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public <T extends HttpUpgradeHandler> T upgrade( Class<T> handlerClass )
- throws IOException, ServletException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean authenticate( HttpServletResponse httpServletResponse )
- throws IOException, ServletException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public void login( String s, String s1 )
- throws ServletException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public void logout()
- throws ServletException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Collection<Part> getParts()
- throws IOException, ServletException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Part getPart( String s )
- throws IOException, ServletException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public ServletContext getServletContext()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public AsyncContext startAsync()
- throws IllegalStateException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public AsyncContext startAsync( ServletRequest servletRequest, ServletResponse servletResponse )
- throws IllegalStateException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean isAsyncStarted()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean isAsyncSupported()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public AsyncContext getAsyncContext()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public DispatcherType getDispatcherType()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Object getAttribute( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Enumeration getAttributeNames()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getCharacterEncoding()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public int getContentLength()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getContentType()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public ServletInputStream getInputStream()
- throws IOException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getLocalAddr()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getLocalName()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public int getLocalPort()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Locale getLocale()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Enumeration getLocales()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getParameter( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Map getParameterMap()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Enumeration getParameterNames()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String[] getParameterValues( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getProtocol()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public BufferedReader getReader()
- throws IOException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getRealPath( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getRemoteAddr()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getRemoteHost()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public int getRemotePort()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public RequestDispatcher getRequestDispatcher( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getScheme()
- {
- return "";
- }
-
- @Override
- public String getServerName()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public int getServerPort()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean isSecure()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public void removeAttribute( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public void setAttribute( String arg0, Object arg1 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public void setCharacterEncoding( String arg0 )
- throws UnsupportedEncodingException
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
-
- @Override
- public String getAuthType()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getContextPath()
- {
- return "/";
- }
-
- @Override
- public Cookie[] getCookies()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public long getDateHeader( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getHeader( String arg0 )
- {
- return "";
- }
-
- @Override
- public Enumeration getHeaderNames()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Enumeration getHeaders( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public int getIntHeader( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getMethod()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getPathInfo()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getPathTranslated()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getQueryString()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getRemoteUser()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getRequestURI()
- {
- return "/";
- }
-
- @Override
- public StringBuffer getRequestURL()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getRequestedSessionId()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public String getServletPath()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public HttpSession getSession( boolean arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public HttpSession getSession()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public Principal getUserPrincipal()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean isRequestedSessionIdFromCookie()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean isRequestedSessionIdFromURL()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean isRequestedSessionIdFromUrl()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean isRequestedSessionIdValid()
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
-
- @Override
- public boolean isUserInRole( String arg0 )
- {
- throw new UnsupportedOperationException( "Not supported yet." );
- }
- }
-
- */
- private class ServletAuthenticatorMock
- implements ServletAuthenticator
- {
- @Override
- public boolean isAuthenticated( HttpServletRequest arg0, AuthenticationResult arg1 )
- throws AuthenticationException, AccountLockedException, MustChangePasswordException
- {
- return true;
- }
-
- @Override
- public boolean isAuthorized( HttpServletRequest request, SecuritySession securitySession, String repositoryId,
- String permission )
- throws AuthorizationException, UnauthorizedException
- {
- return true;
- }
-
- @Override
- public boolean isAuthorized( String principal, String repoId, String permission )
- throws UnauthorizedException
- {
- return true;
- }
- }
-
- private class HttpAuthenticatorMock
- extends HttpAuthenticator
- {
- @Override
- public void challenge( HttpServletRequest arg0, HttpServletResponse arg1, String arg2,
- AuthenticationException arg3 )
- throws IOException
- {
- //Do nothing
- }
-
- @Override
- public AuthenticationResult getAuthenticationResult( HttpServletRequest arg0, HttpServletResponse arg1 )
- throws AuthenticationException, AccountLockedException, MustChangePasswordException
- {
- return new AuthenticationResult();
- }
-
-
- @Override
- public AuthenticationResult authenticate( AuthenticationDataSource arg0, HttpSession httpSession )
- throws AuthenticationException, AccountLockedException, MustChangePasswordException
- {
- return new AuthenticationResult();
- }
-
- @Override
- public void authenticate( HttpServletRequest arg0, HttpServletResponse arg1 )
- throws AuthenticationException
- {
- //Do nothing
- }
-
- @Override
- public SecuritySession getSecuritySession( HttpSession httpSession )
- {
- return super.getSecuritySession( httpSession );
- }
-
- @Override
- public User getSessionUser( HttpSession httpSession )
- {
- return super.getSessionUser( httpSession );
- }
-
- @Override
- public boolean isAlreadyAuthenticated( HttpSession httpSession )
- {
- return super.isAlreadyAuthenticated( httpSession );
- }
- }
- }
|