<groupId>org.apache.archiva</groupId>\r
<artifactId>archiva-security-common</artifactId>\r
</dependency>\r
+ <dependency>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>archiva-rss</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.apache.archiva</groupId>\r
+ <artifactId>archiva-security</artifactId>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.codehaus.redback</groupId>\r
+ <artifactId>redback-common-integrations</artifactId>\r
+ <exclusions>\r
+ <exclusion>\r
+ <groupId>stax</groupId>\r
+ <artifactId>stax-api</artifactId>\r
+ </exclusion>\r
+ </exclusions>\r
+ </dependency>\r
<dependency>\r
<groupId>org.apache.archiva</groupId>\r
<artifactId>archiva-plexus-bridge</artifactId>\r
<groupId>org.springframework</groupId>\r
<artifactId>spring-web</artifactId>\r
</dependency>\r
+ <dependency>\r
+ <groupId>httpunit</groupId>\r
+ <artifactId>httpunit</artifactId>\r
+ <scope>test</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>junit</groupId>\r
+ <artifactId>junit</artifactId>\r
+ <scope>test</scope>\r
+ </dependency>\r
+ <dependency>\r
+ <groupId>org.slf4j</groupId>\r
+ <artifactId>slf4j-log4j12</artifactId>\r
+ <scope>test</scope>\r
+ </dependency>\r
</dependencies>\r
\r
<build>\r
javax.annotation,\r
javax.inject,\r
javax.servlet,\r
+ javax.servlet.http,\r
org.apache.archiva.common;version=${project.version},\r
org.apache.archiva.common.plexusbridge;version=${project.version},\r
org.apache.archiva.configuration;version=${project.version},\r
org.quartz;version="[2,3)",\r
org.slf4j;resolution:=optional,\r
org.springframework*;version="[3,4)",\r
- org.springframework.web*;version="[3,4)"\r
+ org.springframework.web*;version="[3,4)",\r
+ com.sun.syndication.feed.synd,\r
+ com.sun.syndication.io,\r
+ org.apache.archiva.metadata.repository,\r
+ org.apache.archiva.rss.processor,\r
+ org.apache.archiva.security,\r
+ org.apache.commons.codec,\r
+ org.apache.commons.codec.binary,\r
+ org.codehaus.plexus.redback.authentication,\r
+ org.codehaus.plexus.redback.authorization,\r
+ org.codehaus.plexus.redback.policy,\r
+ org.codehaus.plexus.redback.system,\r
+ org.codehaus.plexus.redback.users,\r
+ org.codehaus.redback.integration.filter.authentication\r
</Import-Package>\r
</instructions>\r
</configuration>\r
</plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-jar-plugin</artifactId>\r
+ <executions>\r
+ <execution>\r
+ <goals>\r
+ <goal>test-jar</goal>\r
+ </goals>\r
+ </execution>\r
+ </executions>\r
+ </plugin>\r
+ <plugin>\r
+ <groupId>org.apache.maven.plugins</groupId>\r
+ <artifactId>maven-surefire-plugin</artifactId>\r
+ <configuration>\r
+ <systemPropertyVariables>\r
+ <appserver.base>${project.build.directory}/appserver-base</appserver.base>\r
+ <plexus.home>${project.build.directory}/appserver-base</plexus.home>\r
+ <derby.system.home>${project.build.directory}/appserver-base</derby.system.home>\r
+ <archiva.user.configFileName>${basedir}/target/archiva.xml</archiva.user.configFileName>\r
+ <test.resources.path>${project.build.testOutputDirectory}</test.resources.path>\r
+ <redback.jdbc.url>${redbackTestJdbcUrl}</redback.jdbc.url>\r
+ <redback.jdbc.driver.name>${redbackTestJdbcDriver}</redback.jdbc.driver.name>\r
+ <basedir>${basedir}</basedir>\r
+ </systemPropertyVariables>\r
+ </configuration>\r
+ </plugin>\r
</plugins>\r
</build>\r
\r
--- /dev/null
+package org.apache.archiva.web.rss;
+
+/*
+ * 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 com.sun.syndication.feed.synd.SyndFeed;
+import com.sun.syndication.io.FeedException;
+import com.sun.syndication.io.SyndFeedOutput;
+import org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.rss.processor.RssFeedProcessor;
+import org.apache.archiva.security.AccessDeniedException;
+import org.apache.archiva.security.ArchivaSecurityException;
+import org.apache.archiva.security.PrincipalNotFoundException;
+import org.apache.archiva.security.ServletAuthenticator;
+import org.apache.archiva.security.UserRepositories;
+import org.apache.archiva.security.common.ArchivaRoleConstants;
+import org.apache.commons.codec.Decoder;
+import org.apache.commons.codec.DecoderException;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.commons.lang.StringUtils;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.UnauthorizedException;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.MustChangePasswordException;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import org.springframework.web.context.WebApplicationContext;
+import org.springframework.web.context.support.WebApplicationContextUtils;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Servlet for handling rss feed requests.
+ */
+public class RssFeedServlet
+ extends HttpServlet
+{
+ public static final String MIME_TYPE = "application/rss+xml; charset=UTF-8";
+
+ private static final String COULD_NOT_GENERATE_FEED_ERROR = "Could not generate feed";
+
+ private static final String COULD_NOT_AUTHENTICATE_USER = "Could not authenticate user";
+
+ private static final String USER_NOT_AUTHORIZED = "User not authorized to access feed.";
+
+ private Logger log = LoggerFactory.getLogger( RssFeedServlet.class );
+
+ private RssFeedProcessor processor;
+
+ private WebApplicationContext wac;
+
+ private UserRepositories userRepositories;
+
+ private ServletAuthenticator servletAuth;
+
+ private HttpAuthenticator httpAuth;
+
+ private RepositorySessionFactory repositorySessionFactory;
+
+ public void init( javax.servlet.ServletConfig servletConfig )
+ throws ServletException
+ {
+ super.init( servletConfig );
+ wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() );
+ userRepositories = wac.getBean( UserRepositories.class );
+ servletAuth = wac.getBean( ServletAuthenticator.class );
+ httpAuth = wac.getBean( "httpAuthenticator#basic", HttpAuthenticator.class );
+ // TODO: what if there are other types?
+ repositorySessionFactory = wac.getBean( "repositorySessionFactory", RepositorySessionFactory.class );
+ }
+
+ public void doGet( HttpServletRequest req, HttpServletResponse res )
+ throws ServletException, IOException
+ {
+ String repoId = null;
+ String groupId = null;
+ String artifactId = null;
+
+ String url = StringUtils.removeEnd( req.getRequestURL().toString(), "/" );
+ if ( StringUtils.countMatches( StringUtils.substringAfter( url, "feeds/" ), "/" ) > 0 )
+ {
+ artifactId = StringUtils.substringAfterLast( url, "/" );
+ groupId = StringUtils.substringBeforeLast( StringUtils.substringAfter( url, "feeds/" ), "/" );
+ groupId = StringUtils.replaceChars( groupId, '/', '.' );
+ }
+ else if ( StringUtils.countMatches( StringUtils.substringAfter( url, "feeds/" ), "/" ) == 0 )
+ {
+ repoId = StringUtils.substringAfterLast( url, "/" );
+ }
+ else
+ {
+ res.sendError( HttpServletResponse.SC_BAD_REQUEST, "Invalid request url." );
+ return;
+ }
+
+ try
+ {
+ Map<String, String> map = new HashMap<String, String>();
+ SyndFeed feed = null;
+
+ if ( isAllowed( req, repoId, groupId, artifactId ) )
+ {
+ if ( repoId != null )
+ {
+ // new artifacts in repo feed request
+ processor = wac.getBean( "rssFeedProcessor#new-artifacts", RssFeedProcessor.class );
+ map.put( RssFeedProcessor.KEY_REPO_ID, repoId );
+ }
+ else if ( ( groupId != null ) && ( artifactId != null ) )
+ {
+ // TODO: this only works for guest - we could pass in the list of repos
+ // new versions of artifact feed request
+ processor = wac.getBean( "rssFeedProcessor#new-versions", RssFeedProcessor.class );
+ map.put( RssFeedProcessor.KEY_GROUP_ID, groupId );
+ map.put( RssFeedProcessor.KEY_ARTIFACT_ID, artifactId );
+ }
+ }
+ else
+ {
+ res.sendError( HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED );
+ return;
+ }
+
+ RepositorySession repositorySession = repositorySessionFactory.createSession();
+ try
+ {
+ feed = processor.process( map, repositorySession.getRepository() );
+ }
+ finally
+ {
+ repositorySession.close();
+ }
+ if ( feed == null )
+ {
+ res.sendError( HttpServletResponse.SC_NO_CONTENT, "No information available." );
+ return;
+ }
+
+ res.setContentType( MIME_TYPE );
+
+ if ( repoId != null )
+ {
+ feed.setLink( req.getRequestURL().toString() );
+ }
+ else if ( ( groupId != null ) && ( artifactId != null ) )
+ {
+ feed.setLink( req.getRequestURL().toString() );
+ }
+
+ SyndFeedOutput output = new SyndFeedOutput();
+ output.output( feed, res.getWriter() );
+ }
+ catch ( UserNotFoundException unfe )
+ {
+ log.debug( COULD_NOT_AUTHENTICATE_USER, unfe );
+ res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
+ }
+ catch ( AccountLockedException acce )
+ {
+ res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
+ }
+ catch ( AuthenticationException authe )
+ {
+ log.debug( COULD_NOT_AUTHENTICATE_USER, authe );
+ res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
+ }
+ catch ( FeedException ex )
+ {
+ log.debug( COULD_NOT_GENERATE_FEED_ERROR, ex );
+ res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR );
+ }
+ catch ( MustChangePasswordException e )
+ {
+ res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
+ }
+ catch ( UnauthorizedException e )
+ {
+ log.debug( e.getMessage() );
+ if ( repoId != null )
+ {
+ res.setHeader( "WWW-Authenticate",
+ "Basic realm=\"Repository Archiva Managed " + repoId + " Repository" );
+ }
+ else
+ {
+ res.setHeader( "WWW-Authenticate", "Basic realm=\"Artifact " + groupId + ":" + artifactId );
+ }
+
+ res.sendError( HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED );
+ }
+ }
+
+ /**
+ * Basic authentication.
+ *
+ * @param req
+ * @param repositoryId TODO
+ * @param groupId TODO
+ * @param artifactId TODO
+ * @return
+ */
+ private boolean isAllowed( HttpServletRequest req, String repositoryId, String groupId, String artifactId )
+ throws UserNotFoundException, AccountLockedException, AuthenticationException, MustChangePasswordException,
+ UnauthorizedException
+ {
+ String auth = req.getHeader( "Authorization" );
+ List<String> repoIds = new ArrayList<String>();
+
+ if ( repositoryId != null )
+ {
+ repoIds.add( repositoryId );
+ }
+ else if ( artifactId != null && groupId != null )
+ {
+ if ( auth != null )
+ {
+ if ( !auth.toUpperCase().startsWith( "BASIC " ) )
+ {
+ return false;
+ }
+
+ Decoder dec = new Base64();
+ String usernamePassword = "";
+
+ try
+ {
+ usernamePassword = new String( (byte[]) dec.decode( auth.substring( 6 ).getBytes() ) );
+ }
+ catch ( DecoderException ie )
+ {
+ log.warn( "Error decoding username and password.", ie.getMessage() );
+ }
+
+ if ( usernamePassword == null || usernamePassword.trim().equals( "" ) )
+ {
+ repoIds = getObservableRepos( UserManager.GUEST_USERNAME );
+ }
+ else
+ {
+ String[] userCredentials = usernamePassword.split( ":" );
+ repoIds = getObservableRepos( userCredentials[0] );
+ }
+ }
+ else
+ {
+ repoIds = getObservableRepos( UserManager.GUEST_USERNAME );
+ }
+ }
+ else
+ {
+ return false;
+ }
+
+ for ( String repoId : repoIds )
+ {
+ try
+ {
+ AuthenticationResult result = httpAuth.getAuthenticationResult( req, null );
+ SecuritySession securitySession = httpAuth.getSecuritySession( req.getSession( true ) );
+
+ if ( servletAuth.isAuthenticated( req, result ) && servletAuth.isAuthorized( req, securitySession,
+ repoId,
+ ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ) )
+ {
+ return true;
+ }
+ }
+ catch ( AuthorizationException e )
+ {
+
+ }
+ catch ( UnauthorizedException e )
+ {
+
+ }
+ }
+
+ throw new UnauthorizedException( "Access denied." );
+ }
+
+ private List<String> getObservableRepos( String principal )
+ {
+ try
+ {
+ return userRepositories.getObservableRepositoryIds( principal );
+ }
+ catch ( PrincipalNotFoundException e )
+ {
+ log.warn( e.getMessage(), e );
+ }
+ catch ( AccessDeniedException e )
+ {
+ log.warn( e.getMessage(), e );
+ }
+ catch ( ArchivaSecurityException e )
+ {
+ log.warn( e.getMessage(), e );
+ }
+
+ return Collections.emptyList();
+ }
+
+}
--- /dev/null
+package org.apache.archiva.security;
+
+/*
+ * 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 java.util.Collections;
+import java.util.List;
+
+/**
+ * UserRepositories stub used for testing.
+ *
+ * @version $Id$
+ */
+public class UserRepositoriesStub
+ implements UserRepositories
+{
+ private List<String> repoIds = Collections.singletonList( "test-repo" );
+
+ public void createMissingRepositoryRoles( String repoId )
+ throws ArchivaSecurityException
+ {
+ }
+
+ public List<String> getObservableRepositoryIds( String principal )
+ throws ArchivaSecurityException
+ {
+ return repoIds;
+ }
+
+ public void setObservableRepositoryIds( List<String> repoIds )
+ {
+ this.repoIds = repoIds;
+ }
+
+ public boolean isAuthorizedToUploadArtifacts( String principal, String repoId )
+ throws ArchivaSecurityException
+ {
+ return false;
+ }
+
+ public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
+ {
+ return false;
+ }
+
+ public List<String> getManagableRepositoryIds( String principal )
+ throws ArchivaSecurityException
+ {
+ return null;
+ }
+
+ public List<String> getRepoIds()
+ {
+ return repoIds;
+ }
+
+ public void setRepoIds( List<String> repoIds )
+ {
+ this.repoIds = repoIds;
+ }
+}
--- /dev/null
+package org.apache.archiva.web.rss;
+/*
+ * 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 org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.apache.archiva.security.ArchivaSecurityException;
+import org.apache.archiva.security.UserRepositories;
+import org.codehaus.plexus.redback.role.RoleManager;
+import org.codehaus.plexus.redback.role.RoleManagerException;
+import org.codehaus.plexus.redback.role.model.RedbackRoleModel;
+import org.springframework.stereotype.Service;
+
+import java.net.URL;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * @author Olivier Lamy
+ */
+@Service("RoleManagerStub")
+public class RoleManagerStub
+ implements RoleManager
+{
+ public void loadRoleModel( URL resourceLocation )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void loadRoleModel( RedbackRoleModel model )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void createTemplatedRole( String templateId, String resource )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeTemplatedRole( String templateId, String resource )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void updateRole( String templateId, String oldResource, String newResource )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void assignRole( String roleId, String principal )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void assignRoleByName( String roleName, String principal )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void assignTemplatedRole( String templateId, String resource, String principal )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void unassignRole( String roleId, String principal )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void unassignRoleByName( String roleName, String principal )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean roleExists( String roleId )
+ throws RoleManagerException
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean templatedRoleExists( String templateId, String resource )
+ throws RoleManagerException
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public RedbackRoleModel getModel()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void verifyTemplatedRole( String templateID, String resource )
+ throws RoleManagerException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+
+}
--- /dev/null
+package org.apache.archiva.web.rss;
+
+/*
+ * 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 com.meterware.httpunit.GetMethodWebRequest;
+import com.meterware.httpunit.HttpException;
+import com.meterware.httpunit.WebRequest;
+import com.meterware.httpunit.WebResponse;
+import com.meterware.servletunit.ServletRunner;
+import com.meterware.servletunit.ServletUnitClient;
+import junit.framework.TestCase;
+import org.apache.commons.codec.Encoder;
+import org.apache.commons.codec.binary.Base64;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.BlockJUnit4ClassRunner;
+
+import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+
+@RunWith( BlockJUnit4ClassRunner.class )
+public class RssFeedServletTest
+ extends TestCase
+{
+ private ServletRunner sr;
+
+ private ServletUnitClient client;
+
+ static String PREVIOUS_ARCHIVA_PATH;
+
+ @BeforeClass
+ public static void initConfigurationPath()
+ throws Exception
+ {
+ PREVIOUS_ARCHIVA_PATH = System.getProperty( "archiva.user.configFileName" );
+ System.setProperty( "archiva.user.configFileName",
+ System.getProperty( "test.resources.path/" ) + "empty-archiva.xml" );
+ }
+
+ @AfterClass
+ public static void restoreConfigurationPath()
+ throws Exception
+ {
+ System.setProperty( "archiva.user.configFileName", PREVIOUS_ARCHIVA_PATH );
+ }
+
+ @Before
+ public void setUp()
+ throws Exception
+ {
+ sr = new ServletRunner( new File( "src/test/webapp/WEB-INF/feedServletTest-web.xml" ) );
+ client = sr.newClient();
+ }
+
+ @After
+ public void tearDown()
+ throws Exception
+ {
+ if ( client != null )
+ {
+ client.clearContents();
+ }
+
+ if ( sr != null )
+ {
+ sr.shutDown();
+ }
+
+ super.tearDown();
+ }
+
+ @Test
+ public void testRetrieveServlet()
+ throws Exception
+ {
+
+ RssFeedServlet servlet =
+ (RssFeedServlet) client.newInvocation( "http://localhost/feeds/test-repo" ).getServlet();
+ assertNotNull( servlet );
+ }
+
+ @Test
+ public void testRequestNewArtifactsInRepo()
+ throws Exception
+ {
+ RssFeedServlet servlet =
+ (RssFeedServlet) client.newInvocation( "http://localhost/feeds/test-repo" ).getServlet();
+ assertNotNull( servlet );
+
+ WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/test-repo" );
+
+ Base64 encoder = new Base64( 0, new byte[0] );
+ String userPass = "user1:password1";
+ String encodedUserPass = encoder.encodeToString( userPass.getBytes() );
+ request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
+
+ WebResponse response = client.getResponse( request );
+ assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) );
+ assertNotNull( "Should have recieved a response", response );
+ assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
+
+ }
+
+ @Test
+ public void testRequestNewVersionsOfArtifact()
+ throws Exception
+ {
+ RssFeedServlet servlet = (RssFeedServlet) client.newInvocation(
+ "http://localhost/feeds/org/apache/archiva/artifact-two" ).getServlet();
+ assertNotNull( servlet );
+
+ WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/org/apache/archiva/artifact-two" );
+
+ Base64 encoder = new Base64( 0, new byte[0] );
+ String userPass = "user1:password1";
+ String encodedUserPass = encoder.encodeToString( userPass.getBytes() );
+ request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
+
+ WebResponse response = client.getResponse( request );
+ assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) );
+ assertNotNull( "Should have recieved a response", response );
+ assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
+ }
+
+ @Ignore
+ public void XXX_testInvalidRequest()
+ throws Exception
+ {
+ RssFeedServlet servlet =
+ (RssFeedServlet) client.newInvocation( "http://localhost/feeds?invalid_param=xxx" ).getServlet();
+ assertNotNull( servlet );
+
+ try
+ {
+ WebResponse resp = client.getResponse( "http://localhost/feeds?invalid_param=xxx" );
+ assertEquals( HttpServletResponse.SC_BAD_REQUEST, resp.getResponseCode() );
+ }
+ catch ( HttpException he )
+ {
+ assertEquals( "Should have been a bad request response code.", HttpServletResponse.SC_BAD_REQUEST,
+ he.getResponseCode() );
+ }
+ }
+
+ @Ignore
+ public void XXX_testInvalidAuthenticationRequest()
+ throws Exception
+ {
+ RssFeedServlet servlet =
+ (RssFeedServlet) client.newInvocation( "http://localhost/feeds/unauthorized-repo" ).getServlet();
+ assertNotNull( servlet );
+
+ WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/unauthorized-repo" );
+
+ Encoder encoder = new Base64();
+ String userPass = "unauthUser:unauthPass";
+ String encodedUserPass = new String( (byte[]) encoder.encode( userPass.getBytes() ) );
+ request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
+
+ try
+ {
+ WebResponse resp = client.getResponse( request );
+ assertEquals( HttpServletResponse.SC_UNAUTHORIZED, resp.getResponseCode() );
+ }
+ catch ( HttpException he )
+ {
+ assertEquals( "Should have been a unauthorized response.", HttpServletResponse.SC_UNAUTHORIZED,
+ he.getResponseCode() );
+ }
+ }
+
+ @Ignore
+ public void XXX_testUnauthorizedRequest()
+ throws Exception
+ {
+ RssFeedServlet servlet =
+ (RssFeedServlet) client.newInvocation( "http://localhost/feeds/unauthorized-repo" ).getServlet();
+ assertNotNull( servlet );
+
+ WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/unauthorized-repo" );
+
+ Base64 encoder = new Base64( 0, new byte[0] );
+ String userPass = "user1:password1";
+ String encodedUserPass = encoder.encodeToString( userPass.getBytes() );
+ request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
+
+ try
+ {
+ WebResponse resp = client.getResponse( request );
+ assertEquals( HttpServletResponse.SC_UNAUTHORIZED, resp.getResponseCode() );
+ }
+ catch ( HttpException he )
+ {
+ assertEquals( "Should have been a unauthorized response.", HttpServletResponse.SC_UNAUTHORIZED,
+ he.getResponseCode() );
+ }
+ }
+
+
+}
--- /dev/null
+package org.apache.archiva.web.rss;
+
+/*
+ * 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 org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
+import org.codehaus.plexus.redback.authentication.AuthenticationException;
+import org.codehaus.plexus.redback.authentication.AuthenticationResult;
+import org.codehaus.plexus.redback.authorization.AuthorizationException;
+import org.codehaus.plexus.redback.authorization.AuthorizationResult;
+import org.codehaus.plexus.redback.keys.KeyManager;
+import org.codehaus.plexus.redback.policy.AccountLockedException;
+import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
+import org.codehaus.plexus.redback.system.DefaultSecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySession;
+import org.codehaus.plexus.redback.system.SecuritySystem;
+import org.codehaus.plexus.redback.users.User;
+import org.codehaus.plexus.redback.users.UserManager;
+import org.codehaus.plexus.redback.users.UserManagerListener;
+import org.codehaus.plexus.redback.users.UserNotFoundException;
+import org.codehaus.plexus.redback.users.UserQuery;
+import org.codehaus.plexus.redback.users.jdo.JdoUser;
+
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * SecuritySystem stub used for testing.
+ *
+ * @version $Id$
+ */
+public class SecuritySystemStub
+ implements SecuritySystem
+{
+ Map<String, String> users = new HashMap<String, String>();
+
+ List<String> repoIds = new ArrayList<String>();
+
+ public SecuritySystemStub()
+ {
+ users.put( "user1", "password1" );
+ users.put( "user2", "password2" );
+ users.put( "user3", "password3" );
+
+ repoIds.add( "test-repo" );
+ }
+
+ public SecuritySession authenticate( AuthenticationDataSource source )
+ throws AuthenticationException, UserNotFoundException, AccountLockedException
+ {
+ AuthenticationResult result = null;
+ SecuritySession session = null;
+
+ if ( users.get( source.getPrincipal() ) != null )
+ {
+ result = new AuthenticationResult( true, source.getPrincipal(), null );
+
+ User user = new JdoUser();
+ user.setUsername( source.getPrincipal() );
+ user.setPassword( users.get( source.getPrincipal() ) );
+
+ session = new DefaultSecuritySession( result, user );
+ }
+ else
+ {
+ result = new AuthenticationResult( false, source.getPrincipal(), null );
+ session = new DefaultSecuritySession( result );
+ }
+ return session;
+ }
+
+ public AuthorizationResult authorize( SecuritySession arg0, Object arg1 )
+ throws AuthorizationException
+ {
+ return null;
+ }
+
+ public AuthorizationResult authorize( SecuritySession arg0, Object arg1, Object arg2 )
+ throws AuthorizationException
+ {
+ AuthorizationResult result = new AuthorizationResult( true, arg1, null );
+
+ return result;
+ }
+
+ public String getAuthenticatorId()
+ {
+ return null;
+ }
+
+ public String getAuthorizerId()
+ {
+ return null;
+ }
+
+ public KeyManager getKeyManager()
+ {
+ return null;
+ }
+
+ public UserSecurityPolicy getPolicy()
+ {
+ return null;
+ }
+
+ public String getUserManagementId()
+ {
+ return null;
+ }
+
+ public UserManager getUserManager()
+ {
+ return new UserManager()
+ {
+ public boolean isReadOnly()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getId()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addUserManagerListener( UserManagerListener listener )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeUserManagerListener( UserManagerListener listener )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public User createUser( String username, String fullName, String emailAddress )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public User createGuestUser()
+ {
+ return new User()
+ {
+ public Object getPrincipal()
+ {
+ return "guest";
+ }
+
+ public String getUsername()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setUsername( String name )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getFullName()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setFullName( String name )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getEmail()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setEmail( String address )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getPassword()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setPassword( String rawPassword )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getEncodedPassword()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setEncodedPassword( String encodedPassword )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Date getLastPasswordChange()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setLastPasswordChange( Date passwordChangeDate )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<String> getPreviousEncodedPasswords()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addPreviousEncodedPassword( String encodedPassword )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isPermanent()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isLocked()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setLocked( boolean locked )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isPasswordChangeRequired()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setPasswordChangeRequired( boolean changeRequired )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isValidated()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setValidated( boolean valid )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getCountFailedLoginAttempts()
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setCountFailedLoginAttempts( int count )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Date getAccountCreationDate()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setAccountCreationDate( Date date )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Date getLastLoginDate()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setLastLoginDate( Date date )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+ };
+ }
+
+ public UserQuery createUserQuery()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<User> getUsers()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<User> getUsers( boolean orderAscending )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public User addUser( User user )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public User updateUser( User user )
+ throws UserNotFoundException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public User findUser( String username )
+ throws UserNotFoundException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public User getGuestUser()
+ throws UserNotFoundException
+ {
+ return new User()
+ {
+ public Object getPrincipal()
+ {
+ return "guest";
+ }
+
+ public String getUsername()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setUsername( String name )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getFullName()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setFullName( String name )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getEmail()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setEmail( String address )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getPassword()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setPassword( String rawPassword )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public String getEncodedPassword()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setEncodedPassword( String encodedPassword )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Date getLastPasswordChange()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setLastPasswordChange( Date passwordChangeDate )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<String> getPreviousEncodedPasswords()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addPreviousEncodedPassword( String encodedPassword )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isPermanent()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setPermanent( boolean permanent )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isLocked()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setLocked( boolean locked )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isPasswordChangeRequired()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setPasswordChangeRequired( boolean changeRequired )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean isValidated()
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setValidated( boolean valid )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getCountFailedLoginAttempts()
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setCountFailedLoginAttempts( int count )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Date getAccountCreationDate()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setAccountCreationDate( Date date )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Date getLastLoginDate()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void setLastLoginDate( Date date )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+ };
+ }
+
+ public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<User> findUsersByQuery( UserQuery query )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public User findUser( Object principal )
+ throws UserNotFoundException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public boolean userExists( Object principal )
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void deleteUser( Object principal )
+ throws UserNotFoundException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void deleteUser( String username )
+ throws UserNotFoundException
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void addUserUnchecked( User user )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void eraseDatabase()
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public User updateUser( User user, boolean passwordChangeRequired )
+ throws UserNotFoundException
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+ };
+ }
+
+ public boolean isAuthenticated( AuthenticationDataSource arg0 )
+ throws AuthenticationException, UserNotFoundException, AccountLockedException
+ {
+ return false;
+ }
+
+ public boolean isAuthorized( SecuritySession arg0, Object arg1 )
+ throws AuthorizationException
+ {
+ return false;
+ }
+
+ public boolean isAuthorized( SecuritySession arg0, Object arg1, Object arg2 )
+ throws AuthorizationException
+ {
+ if ( repoIds.contains( arg2 ) )
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+}
--- /dev/null
+package org.apache.archiva.webtest.memory;
+
+/*
+ * 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 org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.MetadataFacet;
+import org.apache.archiva.metadata.model.ProjectMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
+import org.apache.archiva.metadata.repository.MetadataRepository;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.Date;
+import java.util.List;
+
+public class TestMetadataRepository
+ implements MetadataRepository
+{
+ private static final String TEST_REPO = "test-repo";
+
+ private static final String TEST_NAMESPACE = "org.apache.archiva";
+
+ private List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
+
+ private List<String> versions = new ArrayList<String>();
+
+ public TestMetadataRepository()
+ {
+ Date whenGathered = new Date( 123456789 );
+
+ addArtifact( "artifact-one", "1.0", whenGathered );
+ addArtifact( "artifact-one", "1.1", whenGathered );
+ addArtifact( "artifact-one", "2.0", whenGathered );
+ addArtifact( "artifact-two", "1.0.1", whenGathered );
+ addArtifact( "artifact-two", "1.0.2", whenGathered );
+ addArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered );
+ addArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered );
+ addArtifact( "artifact-four", "1.1-beta-2", whenGathered );
+ }
+
+ private void addArtifact( String projectId, String projectVersion, Date whenGathered )
+ {
+ ArtifactMetadata artifact = new ArtifactMetadata();
+ artifact.setFileLastModified( System.currentTimeMillis() );
+ artifact.setNamespace( TEST_NAMESPACE );
+ artifact.setProjectVersion( projectVersion );
+ artifact.setVersion( projectVersion );
+ artifact.setId( projectId + "-" + projectVersion + ".jar" );
+ artifact.setProject( projectId );
+ artifact.setRepositoryId( TEST_REPO );
+ artifact.setWhenGathered( whenGathered );
+ artifacts.add( artifact );
+
+ versions.add( projectVersion );
+ }
+
+ public ProjectMetadata getProject( String repoId, String namespace, String projectId )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getRootNamespaces( String repoId )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getNamespaces( String repoId, String namespace )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getProjects( String repoId, String namespace )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
+ {
+ return versions;
+ }
+
+ public void updateProject( String repoId, ProjectMetadata project )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion,
+ ArtifactMetadata artifactMeta )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateProjectVersion( String repoId, String namespace, String projectId,
+ ProjectVersionMetadata versionMetadata )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void updateNamespace( String repoId, String namespace )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public List<String> getMetadataFacets( String repodId, String facetId )
+ {
+ return Collections.emptyList();
+ }
+
+ public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeMetadataFacets( String repositoryId, String facetId )
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public void removeMetadataFacet( String repoId, String facetId, String name )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
+ {
+ return artifacts;
+ }
+
+ public Collection<String> getRepositories()
+ {
+ return Collections.singletonList( TEST_REPO );
+ }
+
+ public List<ArtifactMetadata> getArtifactsByChecksum( String repoId, String checksum )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public void removeRepository( String repoId )
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
+ String projectVersion )
+ {
+ return artifacts;
+ }
+
+ public void save()
+ {
+ }
+
+ public void close()
+ {
+ }
+
+ public void revert()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ public boolean canObtainAccess( Class<?> aClass )
+ {
+ return false; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public Object obtainAccess( Class<?> aClass )
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public List<ArtifactMetadata> getArtifacts( String repositoryId )
+ {
+ return artifacts;
+ }
+}
\ No newline at end of file
--- /dev/null
+package org.apache.archiva.webtest.memory;
+
+/*
+ * 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 org.apache.archiva.metadata.model.ArtifactMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionMetadata;
+import org.apache.archiva.metadata.model.ProjectVersionReference;
+import org.apache.archiva.metadata.repository.MetadataResolver;
+import org.apache.archiva.metadata.repository.RepositorySession;
+
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+
+public class TestMetadataResolver
+ implements MetadataResolver
+{
+ private Map<String, ProjectVersionMetadata> projectVersions = new HashMap<String, ProjectVersionMetadata>();
+
+ private Map<String, List<ArtifactMetadata>> artifacts = new HashMap<String, List<ArtifactMetadata>>();
+
+ private Map<String, List<ProjectVersionReference>> references =
+ new HashMap<String, List<ProjectVersionReference>>();
+
+ private Map<String, List<String>> namespaces = new HashMap<String, List<String>>();
+
+ private Map<String, Collection<String>> projectsInNamespace = new HashMap<String, Collection<String>>();
+
+ private Map<String, Collection<String>> versionsInProject = new HashMap<String, Collection<String>>();
+
+ public ProjectVersionMetadata resolveProjectVersion( RepositorySession repositorySession, String repoId,
+ String namespace, String projectId, String projectVersion )
+ {
+ return projectVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
+ }
+
+ public Collection<ProjectVersionReference> resolveProjectReferences( RepositorySession repositorySession,
+ String repoId, String namespace,
+ String projectId, String projectVersion )
+ {
+ Collection<ProjectVersionReference> projectVersionReferences =
+ references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
+ return projectVersionReferences;
+ }
+
+ public Collection<String> resolveRootNamespaces( RepositorySession repositorySession, String repoId )
+ {
+ return resolveNamespaces( repositorySession, repoId, null );
+ }
+
+ public Collection<String> resolveNamespaces( RepositorySession repositorySession, String repoId,
+ String baseNamespace )
+ {
+ Set<String> namespaces = new LinkedHashSet<String>();
+ int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
+ for ( String namespace : this.namespaces.get( repoId ) )
+ {
+ if ( baseNamespace == null || namespace.startsWith( baseNamespace + "." ) )
+ {
+ int i = namespace.indexOf( '.', fromIndex );
+ if ( i >= 0 )
+ {
+ namespaces.add( namespace.substring( fromIndex, i ) );
+ }
+ else
+ {
+ namespaces.add( namespace.substring( fromIndex ) );
+ }
+ }
+ }
+ return namespaces;
+ }
+
+ public Collection<String> resolveProjects( RepositorySession repositorySession, String repoId, String namespace )
+ {
+ Collection<String> list = projectsInNamespace.get( namespace );
+ return list != null ? list : Collections.<String>emptyList();
+ }
+
+ public Collection<String> resolveProjectVersions( RepositorySession repositorySession, String repoId,
+ String namespace, String projectId )
+ {
+ Collection<String> list = versionsInProject.get( namespace + ":" + projectId );
+ return list != null ? list : Collections.<String>emptyList();
+ }
+
+ public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession repositorySession, String repoId,
+ String namespace, String projectId, String projectVersion )
+ {
+ List<ArtifactMetadata> artifacts =
+ this.artifacts.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
+ return ( artifacts != null ? artifacts : Collections.<ArtifactMetadata>emptyList() );
+ }
+
+ public void setProjectVersion( String repoId, String namespace, String projectId,
+ ProjectVersionMetadata versionMetadata )
+ {
+ projectVersions.put( createMapKey( repoId, namespace, projectId, versionMetadata.getId() ), versionMetadata );
+
+ Collection<String> projects = projectsInNamespace.get( namespace );
+ if ( projects == null )
+ {
+ projects = new LinkedHashSet<String>();
+ projectsInNamespace.put( namespace, projects );
+ }
+ projects.add( projectId );
+
+ String key = namespace + ":" + projectId;
+ Collection<String> versions = versionsInProject.get( key );
+ if ( versions == null )
+ {
+ versions = new LinkedHashSet<String>();
+ versionsInProject.put( key, versions );
+ }
+ versions.add( versionMetadata.getId() );
+ }
+
+ public void setArtifacts( String repoId, String namespace, String projectId, String projectVersion,
+ List<ArtifactMetadata> artifacts )
+ {
+ this.artifacts.put( createMapKey( repoId, namespace, projectId, projectVersion ), artifacts );
+ }
+
+ private String createMapKey( String repoId, String namespace, String projectId, String projectVersion )
+ {
+ return repoId + ":" + namespace + ":" + projectId + ":" + projectVersion;
+ }
+
+ public void setProjectReferences( String repoId, String namespace, String projectId, String projectVersion,
+ List<ProjectVersionReference> references )
+ {
+ this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references );
+ }
+
+ public void setNamespaces( String repoId, List<String> namespaces )
+ {
+ this.namespaces.put( repoId, namespaces );
+ }
+}
--- /dev/null
+package org.apache.archiva.webtest.memory;
+
+/*
+ * 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 org.apache.archiva.metadata.repository.RepositorySession;
+import org.apache.archiva.metadata.repository.RepositorySessionFactory;
+import org.springframework.stereotype.Service;
+
+@Service("repositorySessionFactory#test")
+public class TestRepositorySessionFactory
+ implements RepositorySessionFactory
+{
+ private RepositorySession repositorySession;
+
+ public void setRepositorySession( RepositorySession repositorySession )
+ {
+ this.repositorySession = repositorySession;
+ }
+
+ public RepositorySession createSession()
+ {
+ return repositorySession != null ? repositorySession : new RepositorySession( new TestMetadataRepository(),
+ new TestMetadataResolver() );
+ }
+}
--- /dev/null
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<!--
+ ~ 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.
+ -->
+
+<configuration>
+
+ <version>2</version>
+
+ <repositoryScanning>
+ <fileTypes>
+ <fileType>
+ <id>artifacts</id>
+ <patterns>
+ <pattern>**/*.pom</pattern>
+ <pattern>**/*.jar</pattern>
+ <pattern>**/*.ear</pattern>
+ <pattern>**/*.war</pattern>
+ <pattern>**/*.car</pattern>
+ <pattern>**/*.sar</pattern>
+ <pattern>**/*.mar</pattern>
+ <pattern>**/*.rar</pattern>
+ <pattern>**/*.dtd</pattern>
+ <pattern>**/*.tld</pattern>
+ <pattern>**/*.tar.gz</pattern>
+ <pattern>**/*.tar.bz2</pattern>
+ <pattern>**/*.zip</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>indexable-content</id>
+ <patterns>
+ <pattern>**/*.txt</pattern>
+ <pattern>**/*.TXT</pattern>
+ <pattern>**/*.block</pattern>
+ <pattern>**/*.config</pattern>
+ <pattern>**/*.pom</pattern>
+ <pattern>**/*.xml</pattern>
+ <pattern>**/*.xsd</pattern>
+ <pattern>**/*.dtd</pattern>
+ <pattern>**/*.tld</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>auto-remove</id>
+ <patterns>
+ <pattern>**/*.bak</pattern>
+ <pattern>**/*~</pattern>
+ <pattern>**/*-</pattern>
+ </patterns>
+ </fileType>
+ <fileType>
+ <id>ignored</id>
+ <patterns>
+ <pattern>**/.htaccess</pattern>
+ <pattern>**/KEYS</pattern>
+ <pattern>**/*.rb</pattern>
+ <pattern>**/*.sh</pattern>
+ <pattern>**/.svn/**</pattern>
+ <pattern>**/.DAV/**</pattern>
+ </patterns>
+ </fileType>
+ </fileTypes>
+ <knownContentConsumers>
+ <knownContentConsumer>update-db-artifact</knownContentConsumer>
+ <knownContentConsumer>create-missing-checksums</knownContentConsumer>
+ <knownContentConsumer>update-db-repository-metadata</knownContentConsumer>
+ <knownContentConsumer>validate-checksum</knownContentConsumer>
+ <knownContentConsumer>validate-signature</knownContentConsumer>
+ <knownContentConsumer>index-content</knownContentConsumer>
+ <knownContentConsumer>auto-remove</knownContentConsumer>
+ <knownContentConsumer>auto-rename</knownContentConsumer>
+ </knownContentConsumers>
+ <invalidContentConsumers>
+ <invalidContentConsumer>update-db-bad-content</invalidContentConsumer>
+ </invalidContentConsumers>
+ </repositoryScanning>
+
+ <databaseScanning>
+ <cronExpression>0 0 * * * ?</cronExpression>
+ <unprocessedConsumers>
+ <unprocessedConsumer>index-artifact</unprocessedConsumer>
+ <unprocessedConsumer>update-db-project</unprocessedConsumer>
+ <unprocessedConsumer>validate-repository-metadata</unprocessedConsumer>
+ <unprocessedConsumer>index-archive-toc</unprocessedConsumer>
+ <unprocessedConsumer>update-db-bytecode-stats</unprocessedConsumer>
+ <unprocessedConsumer>index-public-methods</unprocessedConsumer>
+ </unprocessedConsumers>
+ <cleanupConsumers>
+ <cleanupConsumer>not-present-remove-db-artifact</cleanupConsumer>
+ <cleanupConsumer>not-present-remove-db-project</cleanupConsumer>
+ <cleanupConsumer>not-present-remove-indexed</cleanupConsumer>
+ </cleanupConsumers>
+ </databaseScanning>
+
+</configuration>
--- /dev/null
+<?xml version="1.0" encoding="UTF-8" ?>
+<!--
+ ~ 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.
+ -->
+
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">
+
+ <appender name="console" class="org.apache.log4j.ConsoleAppender">
+ <layout class="org.apache.log4j.PatternLayout">
+ <param name="ConversionPattern" value="%d [%t] %-5p %c %x - %m%n"/>
+ </layout>
+ </appender>
+ <logger name="org.apache.archiva.web">
+ <level value="debug"/>
+ </logger>
+
+
+ <root>
+ <priority value ="info" />
+ <appender-ref ref="console" />
+ </root>
+
+</log4j:configuration>
--- /dev/null
+<?xml version="1.0"?>
+
+<!--
+ ~ 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.
+ -->
+<beans xmlns="http://www.springframework.org/schema/beans"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xmlns:context="http://www.springframework.org/schema/context"
+ xsi:schemaLocation="http://www.springframework.org/schema/beans
+ http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
+ http://www.springframework.org/schema/context
+ http://www.springframework.org/schema/context/spring-context-3.0.xsd"
+ default-lazy-init="true">
+
+ <context:property-placeholder system-properties-mode="OVERRIDE"/>
+
+ <context:annotation-config/>
+ <context:component-scan base-package="org.apache.archiva.webtest.memory"/>
+
+ <alias name="repositorySessionFactory#test" alias="repositorySessionFactory"/>
+
+ <bean name="userRepositories#test" class="org.apache.archiva.security.UserRepositoriesStub"/>
+
+ <alias name="userRepositories#test" alias="userRepositories"/>
+
+
+ <bean name="securitySystem#test" class="org.apache.archiva.web.rss.SecuritySystemStub"/>
+
+ <alias name="securitySystem#test" alias="securitySystem"/>
+
+ <bean name="archivaConfiguration#default" class="org.apache.archiva.configuration.DefaultArchivaConfiguration">
+ <property name="registry" ref="registry#default"/>
+ </bean>
+
+ <alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
+
+ <bean name="registry#default" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
+ <property name="properties">
+ <value>
+ <![CDATA[
+ <configuration>
+ <system/>
+ <xml fileName="${test.resources.path}/empty-archiva.xml" config-forceCreate="true"
+ config-optional="true"
+ config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
+ </configuration>
+ ]]>
+ </value>
+ </property>
+ </bean>
+
+ <bean name="RoleManagerStub" class="org.apache.archiva.web.rss.RoleManagerStub"/>
+
+</beans>
\ No newline at end of file
--- /dev/null
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
+
+ <display-name>Apache Archiva</display-name>
+
+ <listener>
+ <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+ <context-param>
+ <param-name>contextClass</param-name>
+ <param-value>org.codehaus.redback.components.springutils.CachingWebApplicationContext</param-value>
+ </context-param>
+
+ <servlet>
+ <servlet-name>RssFeedServlet</servlet-name>
+ <servlet-class>org.apache.archiva.web.rss.RssFeedServlet</servlet-class>
+ </servlet>
+
+ <servlet-mapping>
+ <servlet-name>RssFeedServlet</servlet-name>
+ <url-pattern>/feeds/*</url-pattern>
+ </servlet-mapping>
+
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>
+ classpath*:/META-INF/spring-context.xml
+ classpath*:/spring-context-rss-servlet.xml
+ </param-value>
+ </context-param>
+
+</web-app>
<optional>true</optional>
</dependency>
+ <dependency>
+ <groupId>org.apache.archiva</groupId>
+ <artifactId>archiva-webapp-common</artifactId>
+ <classifier>tests</classifier>
+ <scope>test</scope>
+ <version>${project.version}</version>
+ </dependency>
+
</dependencies>
<build>
<resources>
+++ /dev/null
-package org.apache.archiva.web.rss;
-
-/*
- * 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 com.sun.syndication.feed.synd.SyndFeed;
-import com.sun.syndication.io.FeedException;
-import com.sun.syndication.io.SyndFeedOutput;
-import org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.RepositorySessionFactory;
-import org.apache.archiva.rss.processor.RssFeedProcessor;
-import org.apache.archiva.security.common.ArchivaRoleConstants;
-import org.apache.commons.codec.Decoder;
-import org.apache.commons.codec.DecoderException;
-import org.apache.commons.codec.binary.Base64;
-import org.apache.commons.lang.StringUtils;
-import org.apache.archiva.security.AccessDeniedException;
-import org.apache.archiva.security.ArchivaSecurityException;
-import org.apache.archiva.security.PrincipalNotFoundException;
-import org.apache.archiva.security.ServletAuthenticator;
-import org.apache.archiva.security.UserRepositories;
-import org.codehaus.plexus.redback.authentication.AuthenticationException;
-import org.codehaus.plexus.redback.authentication.AuthenticationResult;
-import org.codehaus.plexus.redback.authorization.AuthorizationException;
-import org.codehaus.plexus.redback.authorization.UnauthorizedException;
-import org.codehaus.plexus.redback.policy.AccountLockedException;
-import org.codehaus.plexus.redback.policy.MustChangePasswordException;
-import org.codehaus.plexus.redback.system.SecuritySession;
-import org.codehaus.plexus.redback.users.UserManager;
-import org.codehaus.plexus.redback.users.UserNotFoundException;
-import org.codehaus.redback.integration.filter.authentication.HttpAuthenticator;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.web.context.WebApplicationContext;
-import org.springframework.web.context.support.WebApplicationContextUtils;
-
-import javax.servlet.ServletException;
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * Servlet for handling rss feed requests.
- */
-public class RssFeedServlet
- extends HttpServlet
-{
- public static final String MIME_TYPE = "application/rss+xml; charset=UTF-8";
-
- private static final String COULD_NOT_GENERATE_FEED_ERROR = "Could not generate feed";
-
- private static final String COULD_NOT_AUTHENTICATE_USER = "Could not authenticate user";
-
- private static final String USER_NOT_AUTHORIZED = "User not authorized to access feed.";
-
- private Logger log = LoggerFactory.getLogger( RssFeedServlet.class );
-
- private RssFeedProcessor processor;
-
- private WebApplicationContext wac;
-
- private UserRepositories userRepositories;
-
- private ServletAuthenticator servletAuth;
-
- private HttpAuthenticator httpAuth;
-
- private RepositorySessionFactory repositorySessionFactory;
-
- public void init( javax.servlet.ServletConfig servletConfig )
- throws ServletException
- {
- super.init( servletConfig );
- wac = WebApplicationContextUtils.getRequiredWebApplicationContext( servletConfig.getServletContext() );
- userRepositories = wac.getBean( UserRepositories.class );
- servletAuth = wac.getBean( ServletAuthenticator.class );
- httpAuth = wac.getBean( "httpAuthenticator#basic", HttpAuthenticator.class );
- // TODO: what if there are other types?
- repositorySessionFactory = wac.getBean( "repositorySessionFactory", RepositorySessionFactory.class );
- }
-
- public void doGet( HttpServletRequest req, HttpServletResponse res )
- throws ServletException, IOException
- {
- String repoId = null;
- String groupId = null;
- String artifactId = null;
-
- String url = StringUtils.removeEnd( req.getRequestURL().toString(), "/" );
- if ( StringUtils.countMatches( StringUtils.substringAfter( url, "feeds/" ), "/" ) > 0 )
- {
- artifactId = StringUtils.substringAfterLast( url, "/" );
- groupId = StringUtils.substringBeforeLast( StringUtils.substringAfter( url, "feeds/" ), "/" );
- groupId = StringUtils.replaceChars( groupId, '/', '.' );
- }
- else if ( StringUtils.countMatches( StringUtils.substringAfter( url, "feeds/" ), "/" ) == 0 )
- {
- repoId = StringUtils.substringAfterLast( url, "/" );
- }
- else
- {
- res.sendError( HttpServletResponse.SC_BAD_REQUEST, "Invalid request url." );
- return;
- }
-
- try
- {
- Map<String, String> map = new HashMap<String, String>();
- SyndFeed feed = null;
-
- if ( isAllowed( req, repoId, groupId, artifactId ) )
- {
- if ( repoId != null )
- {
- // new artifacts in repo feed request
- processor = wac.getBean( "rssFeedProcessor#new-artifacts", RssFeedProcessor.class );
- map.put( RssFeedProcessor.KEY_REPO_ID, repoId );
- }
- else if ( ( groupId != null ) && ( artifactId != null ) )
- {
- // TODO: this only works for guest - we could pass in the list of repos
- // new versions of artifact feed request
- processor = wac.getBean( "rssFeedProcessor#new-versions", RssFeedProcessor.class );
- map.put( RssFeedProcessor.KEY_GROUP_ID, groupId );
- map.put( RssFeedProcessor.KEY_ARTIFACT_ID, artifactId );
- }
- }
- else
- {
- res.sendError( HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED );
- return;
- }
-
- RepositorySession repositorySession = repositorySessionFactory.createSession();
- try
- {
- feed = processor.process( map, repositorySession.getRepository() );
- }
- finally
- {
- repositorySession.close();
- }
- if ( feed == null )
- {
- res.sendError( HttpServletResponse.SC_NO_CONTENT, "No information available." );
- return;
- }
-
- res.setContentType( MIME_TYPE );
-
- if ( repoId != null )
- {
- feed.setLink( req.getRequestURL().toString() );
- }
- else if ( ( groupId != null ) && ( artifactId != null ) )
- {
- feed.setLink( req.getRequestURL().toString() );
- }
-
- SyndFeedOutput output = new SyndFeedOutput();
- output.output( feed, res.getWriter() );
- }
- catch ( UserNotFoundException unfe )
- {
- log.debug( COULD_NOT_AUTHENTICATE_USER, unfe );
- res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
- }
- catch ( AccountLockedException acce )
- {
- res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
- }
- catch ( AuthenticationException authe )
- {
- log.debug( COULD_NOT_AUTHENTICATE_USER, authe );
- res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
- }
- catch ( FeedException ex )
- {
- log.debug( COULD_NOT_GENERATE_FEED_ERROR, ex );
- res.sendError( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, COULD_NOT_GENERATE_FEED_ERROR );
- }
- catch ( MustChangePasswordException e )
- {
- res.sendError( HttpServletResponse.SC_UNAUTHORIZED, COULD_NOT_AUTHENTICATE_USER );
- }
- catch ( UnauthorizedException e )
- {
- log.debug( e.getMessage() );
- if ( repoId != null )
- {
- res.setHeader( "WWW-Authenticate",
- "Basic realm=\"Repository Archiva Managed " + repoId + " Repository" );
- }
- else
- {
- res.setHeader( "WWW-Authenticate", "Basic realm=\"Artifact " + groupId + ":" + artifactId );
- }
-
- res.sendError( HttpServletResponse.SC_UNAUTHORIZED, USER_NOT_AUTHORIZED );
- }
- }
-
- /**
- * Basic authentication.
- *
- * @param req
- * @param repositoryId TODO
- * @param groupId TODO
- * @param artifactId TODO
- * @return
- */
- private boolean isAllowed( HttpServletRequest req, String repositoryId, String groupId, String artifactId )
- throws UserNotFoundException, AccountLockedException, AuthenticationException, MustChangePasswordException,
- UnauthorizedException
- {
- String auth = req.getHeader( "Authorization" );
- List<String> repoIds = new ArrayList<String>();
-
- if ( repositoryId != null )
- {
- repoIds.add( repositoryId );
- }
- else if ( artifactId != null && groupId != null )
- {
- if ( auth != null )
- {
- if ( !auth.toUpperCase().startsWith( "BASIC " ) )
- {
- return false;
- }
-
- Decoder dec = new Base64();
- String usernamePassword = "";
-
- try
- {
- usernamePassword = new String( (byte[]) dec.decode( auth.substring( 6 ).getBytes() ) );
- }
- catch ( DecoderException ie )
- {
- log.warn( "Error decoding username and password.", ie.getMessage() );
- }
-
- if ( usernamePassword == null || usernamePassword.trim().equals( "" ) )
- {
- repoIds = getObservableRepos( UserManager.GUEST_USERNAME );
- }
- else
- {
- String[] userCredentials = usernamePassword.split( ":" );
- repoIds = getObservableRepos( userCredentials[0] );
- }
- }
- else
- {
- repoIds = getObservableRepos( UserManager.GUEST_USERNAME );
- }
- }
- else
- {
- return false;
- }
-
- for ( String repoId : repoIds )
- {
- try
- {
- AuthenticationResult result = httpAuth.getAuthenticationResult( req, null );
- SecuritySession securitySession = httpAuth.getSecuritySession( req.getSession( true ) );
-
- if ( servletAuth.isAuthenticated( req, result ) && servletAuth.isAuthorized( req, securitySession,
- repoId,
- ArchivaRoleConstants.OPERATION_REPOSITORY_ACCESS ) )
- {
- return true;
- }
- }
- catch ( AuthorizationException e )
- {
-
- }
- catch ( UnauthorizedException e )
- {
-
- }
- }
-
- throw new UnauthorizedException( "Access denied." );
- }
-
- private List<String> getObservableRepos( String principal )
- {
- try
- {
- return userRepositories.getObservableRepositoryIds( principal );
- }
- catch ( PrincipalNotFoundException e )
- {
- log.warn( e.getMessage(), e );
- }
- catch ( AccessDeniedException e )
- {
- log.warn( e.getMessage(), e );
- }
- catch ( ArchivaSecurityException e )
- {
- log.warn( e.getMessage(), e );
- }
-
- return Collections.emptyList();
- }
-
-}
+++ /dev/null
-package org.apache.archiva.security;
-
-/*
- * 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 java.util.Collections;
-import java.util.List;
-
-/**
- * UserRepositories stub used for testing.
- *
- * @version $Id$
- */
-public class UserRepositoriesStub
- implements UserRepositories
-{
- private List<String> repoIds = Collections.singletonList( "test-repo" );
-
- public void createMissingRepositoryRoles( String repoId )
- throws ArchivaSecurityException
- {
- }
-
- public List<String> getObservableRepositoryIds( String principal )
- throws ArchivaSecurityException
- {
- return repoIds;
- }
-
- public void setObservableRepositoryIds( List<String> repoIds )
- {
- this.repoIds = repoIds;
- }
-
- public boolean isAuthorizedToUploadArtifacts( String principal, String repoId )
- throws ArchivaSecurityException
- {
- return false;
- }
-
- public boolean isAuthorizedToDeleteArtifacts( String principal, String repoId )
- {
- return false;
- }
-
- public List<String> getManagableRepositoryIds( String principal )
- throws ArchivaSecurityException
- {
- return null;
- }
-
- public List<String> getRepoIds()
- {
- return repoIds;
- }
-
- public void setRepoIds( List<String> repoIds )
- {
- this.repoIds = repoIds;
- }
-}
+++ /dev/null
-package org.apache.archiva.web.rss;
-/*
- * 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 org.codehaus.plexus.redback.role.RoleManager;
-import org.codehaus.plexus.redback.role.RoleManagerException;
-import org.codehaus.plexus.redback.role.model.RedbackRoleModel;
-import org.springframework.stereotype.Service;
-
-import java.net.URL;
-
-/**
- * @author Olivier Lamy
- */
-@Service("RoleManagerStub")
-public class RoleManagerStub
- implements RoleManager
-{
- public void loadRoleModel( URL resourceLocation )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void loadRoleModel( RedbackRoleModel model )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void createTemplatedRole( String templateId, String resource )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void removeTemplatedRole( String templateId, String resource )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void updateRole( String templateId, String oldResource, String newResource )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void assignRole( String roleId, String principal )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void assignRoleByName( String roleName, String principal )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void assignTemplatedRole( String templateId, String resource, String principal )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void unassignRole( String roleId, String principal )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void unassignRoleByName( String roleName, String principal )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean roleExists( String roleId )
- throws RoleManagerException
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean templatedRoleExists( String templateId, String resource )
- throws RoleManagerException
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public RedbackRoleModel getModel()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void verifyTemplatedRole( String templateID, String resource )
- throws RoleManagerException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-}
+++ /dev/null
-package org.apache.archiva.web.rss;
-
-/*
- * 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 com.meterware.httpunit.GetMethodWebRequest;
-import com.meterware.httpunit.HttpException;
-import com.meterware.httpunit.WebRequest;
-import com.meterware.httpunit.WebResponse;
-import com.meterware.servletunit.ServletRunner;
-import com.meterware.servletunit.ServletUnitClient;
-import junit.framework.TestCase;
-import org.apache.commons.codec.Encoder;
-import org.apache.commons.codec.binary.Base64;
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Ignore;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.BlockJUnit4ClassRunner;
-
-import javax.servlet.http.HttpServletResponse;
-import java.io.File;
-
-@RunWith( BlockJUnit4ClassRunner.class )
-public class RssFeedServletTest
- extends TestCase
-{
- private ServletRunner sr;
-
- private ServletUnitClient client;
-
- static String PREVIOUS_ARCHIVA_PATH;
-
- @BeforeClass
- public static void initConfigurationPath()
- throws Exception
- {
- PREVIOUS_ARCHIVA_PATH = System.getProperty( "archiva.user.configFileName" );
- System.setProperty( "archiva.user.configFileName",
- System.getProperty( "test.resources.path/" ) + "empty-archiva.xml" );
- }
-
- @AfterClass
- public static void restoreConfigurationPath()
- throws Exception
- {
- System.setProperty( "archiva.user.configFileName", PREVIOUS_ARCHIVA_PATH );
- }
-
- @Before
- public void setUp()
- throws Exception
- {
- sr = new ServletRunner( new File( "src/test/webapp/WEB-INF/feedServletTest-web.xml" ) );
- client = sr.newClient();
- }
-
- @After
- public void tearDown()
- throws Exception
- {
- if ( client != null )
- {
- client.clearContents();
- }
-
- if ( sr != null )
- {
- sr.shutDown();
- }
-
- super.tearDown();
- }
-
- @Test
- public void testRetrieveServlet()
- throws Exception
- {
-
- RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation( "http://localhost/feeds/test-repo" ).getServlet();
- assertNotNull( servlet );
- }
-
- @Test
- public void testRequestNewArtifactsInRepo()
- throws Exception
- {
- RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation( "http://localhost/feeds/test-repo" ).getServlet();
- assertNotNull( servlet );
-
- WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/test-repo" );
-
- Base64 encoder = new Base64( 0, new byte[0] );
- String userPass = "user1:password1";
- String encodedUserPass = encoder.encodeToString( userPass.getBytes() );
- request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
-
- WebResponse response = client.getResponse( request );
- assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) );
- assertNotNull( "Should have recieved a response", response );
- assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
-
- }
-
- @Test
- public void testRequestNewVersionsOfArtifact()
- throws Exception
- {
- RssFeedServlet servlet = (RssFeedServlet) client.newInvocation(
- "http://localhost/feeds/org/apache/archiva/artifact-two" ).getServlet();
- assertNotNull( servlet );
-
- WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/org/apache/archiva/artifact-two" );
-
- Base64 encoder = new Base64( 0, new byte[0] );
- String userPass = "user1:password1";
- String encodedUserPass = encoder.encodeToString( userPass.getBytes() );
- request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
-
- WebResponse response = client.getResponse( request );
- assertEquals( RssFeedServlet.MIME_TYPE, response.getHeaderField( "CONTENT-TYPE" ) );
- assertNotNull( "Should have recieved a response", response );
- assertEquals( "Should have been an OK response code.", HttpServletResponse.SC_OK, response.getResponseCode() );
- }
-
- @Ignore
- public void XXX_testInvalidRequest()
- throws Exception
- {
- RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation( "http://localhost/feeds?invalid_param=xxx" ).getServlet();
- assertNotNull( servlet );
-
- try
- {
- WebResponse resp = client.getResponse( "http://localhost/feeds?invalid_param=xxx" );
- assertEquals( HttpServletResponse.SC_BAD_REQUEST, resp.getResponseCode() );
- }
- catch ( HttpException he )
- {
- assertEquals( "Should have been a bad request response code.", HttpServletResponse.SC_BAD_REQUEST,
- he.getResponseCode() );
- }
- }
-
- @Ignore
- public void XXX_testInvalidAuthenticationRequest()
- throws Exception
- {
- RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation( "http://localhost/feeds/unauthorized-repo" ).getServlet();
- assertNotNull( servlet );
-
- WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/unauthorized-repo" );
-
- Encoder encoder = new Base64();
- String userPass = "unauthUser:unauthPass";
- String encodedUserPass = new String( (byte[]) encoder.encode( userPass.getBytes() ) );
- request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
-
- try
- {
- WebResponse resp = client.getResponse( request );
- assertEquals( HttpServletResponse.SC_UNAUTHORIZED, resp.getResponseCode() );
- }
- catch ( HttpException he )
- {
- assertEquals( "Should have been a unauthorized response.", HttpServletResponse.SC_UNAUTHORIZED,
- he.getResponseCode() );
- }
- }
-
- @Ignore
- public void XXX_testUnauthorizedRequest()
- throws Exception
- {
- RssFeedServlet servlet =
- (RssFeedServlet) client.newInvocation( "http://localhost/feeds/unauthorized-repo" ).getServlet();
- assertNotNull( servlet );
-
- WebRequest request = new GetMethodWebRequest( "http://localhost/feeds/unauthorized-repo" );
-
- Base64 encoder = new Base64( 0, new byte[0] );
- String userPass = "user1:password1";
- String encodedUserPass = encoder.encodeToString( userPass.getBytes() );
- request.setHeaderField( "Authorization", "BASIC " + encodedUserPass );
-
- try
- {
- WebResponse resp = client.getResponse( request );
- assertEquals( HttpServletResponse.SC_UNAUTHORIZED, resp.getResponseCode() );
- }
- catch ( HttpException he )
- {
- assertEquals( "Should have been a unauthorized response.", HttpServletResponse.SC_UNAUTHORIZED,
- he.getResponseCode() );
- }
- }
-
-
-}
+++ /dev/null
-package org.apache.archiva.web.rss;
-
-/*
- * 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 org.codehaus.plexus.redback.authentication.AuthenticationDataSource;
-import org.codehaus.plexus.redback.authentication.AuthenticationException;
-import org.codehaus.plexus.redback.authentication.AuthenticationResult;
-import org.codehaus.plexus.redback.authorization.AuthorizationException;
-import org.codehaus.plexus.redback.authorization.AuthorizationResult;
-import org.codehaus.plexus.redback.keys.KeyManager;
-import org.codehaus.plexus.redback.policy.AccountLockedException;
-import org.codehaus.plexus.redback.policy.UserSecurityPolicy;
-import org.codehaus.plexus.redback.system.DefaultSecuritySession;
-import org.codehaus.plexus.redback.system.SecuritySession;
-import org.codehaus.plexus.redback.system.SecuritySystem;
-import org.codehaus.plexus.redback.users.User;
-import org.codehaus.plexus.redback.users.UserManager;
-import org.codehaus.plexus.redback.users.UserManagerListener;
-import org.codehaus.plexus.redback.users.UserNotFoundException;
-import org.codehaus.plexus.redback.users.UserQuery;
-import org.codehaus.plexus.redback.users.jdo.JdoUser;
-
-import java.util.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-/**
- * SecuritySystem stub used for testing.
- *
- * @version $Id$
- */
-public class SecuritySystemStub
- implements SecuritySystem
-{
- Map<String, String> users = new HashMap<String, String>();
-
- List<String> repoIds = new ArrayList<String>();
-
- public SecuritySystemStub()
- {
- users.put( "user1", "password1" );
- users.put( "user2", "password2" );
- users.put( "user3", "password3" );
-
- repoIds.add( "test-repo" );
- }
-
- public SecuritySession authenticate( AuthenticationDataSource source )
- throws AuthenticationException, UserNotFoundException, AccountLockedException
- {
- AuthenticationResult result = null;
- SecuritySession session = null;
-
- if ( users.get( source.getPrincipal() ) != null )
- {
- result = new AuthenticationResult( true, source.getPrincipal(), null );
-
- User user = new JdoUser();
- user.setUsername( source.getPrincipal() );
- user.setPassword( users.get( source.getPrincipal() ) );
-
- session = new DefaultSecuritySession( result, user );
- }
- else
- {
- result = new AuthenticationResult( false, source.getPrincipal(), null );
- session = new DefaultSecuritySession( result );
- }
- return session;
- }
-
- public AuthorizationResult authorize( SecuritySession arg0, Object arg1 )
- throws AuthorizationException
- {
- return null;
- }
-
- public AuthorizationResult authorize( SecuritySession arg0, Object arg1, Object arg2 )
- throws AuthorizationException
- {
- AuthorizationResult result = new AuthorizationResult( true, arg1, null );
-
- return result;
- }
-
- public String getAuthenticatorId()
- {
- return null;
- }
-
- public String getAuthorizerId()
- {
- return null;
- }
-
- public KeyManager getKeyManager()
- {
- return null;
- }
-
- public UserSecurityPolicy getPolicy()
- {
- return null;
- }
-
- public String getUserManagementId()
- {
- return null;
- }
-
- public UserManager getUserManager()
- {
- return new UserManager()
- {
- public boolean isReadOnly()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getId()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void addUserManagerListener( UserManagerListener listener )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void removeUserManagerListener( UserManagerListener listener )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public User createUser( String username, String fullName, String emailAddress )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public User createGuestUser()
- {
- return new User()
- {
- public Object getPrincipal()
- {
- return "guest";
- }
-
- public String getUsername()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setUsername( String name )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getFullName()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setFullName( String name )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getEmail()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setEmail( String address )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getPassword()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setPassword( String rawPassword )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getEncodedPassword()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setEncodedPassword( String encodedPassword )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Date getLastPasswordChange()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setLastPasswordChange( Date passwordChangeDate )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<String> getPreviousEncodedPasswords()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void addPreviousEncodedPassword( String encodedPassword )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isPermanent()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setPermanent( boolean permanent )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isLocked()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setLocked( boolean locked )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isPasswordChangeRequired()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setPasswordChangeRequired( boolean changeRequired )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isValidated()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setValidated( boolean valid )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public int getCountFailedLoginAttempts()
- {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setCountFailedLoginAttempts( int count )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Date getAccountCreationDate()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setAccountCreationDate( Date date )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Date getLastLoginDate()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setLastLoginDate( Date date )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
- };
- }
-
- public UserQuery createUserQuery()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<User> getUsers()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<User> getUsers( boolean orderAscending )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public User addUser( User user )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public User updateUser( User user )
- throws UserNotFoundException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public User findUser( String username )
- throws UserNotFoundException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public User getGuestUser()
- throws UserNotFoundException
- {
- return new User()
- {
- public Object getPrincipal()
- {
- return "guest";
- }
-
- public String getUsername()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setUsername( String name )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getFullName()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setFullName( String name )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getEmail()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setEmail( String address )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getPassword()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setPassword( String rawPassword )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public String getEncodedPassword()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setEncodedPassword( String encodedPassword )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Date getLastPasswordChange()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setLastPasswordChange( Date passwordChangeDate )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<String> getPreviousEncodedPasswords()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setPreviousEncodedPasswords( List<String> encodedPasswordList )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void addPreviousEncodedPassword( String encodedPassword )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isPermanent()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setPermanent( boolean permanent )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isLocked()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setLocked( boolean locked )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isPasswordChangeRequired()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setPasswordChangeRequired( boolean changeRequired )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean isValidated()
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setValidated( boolean valid )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public int getCountFailedLoginAttempts()
- {
- return 0; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setCountFailedLoginAttempts( int count )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Date getAccountCreationDate()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setAccountCreationDate( Date date )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Date getLastLoginDate()
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void setLastLoginDate( Date date )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
- };
- }
-
- public List<User> findUsersByUsernameKey( String usernameKey, boolean orderAscending )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<User> findUsersByFullNameKey( String fullNameKey, boolean orderAscending )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<User> findUsersByEmailKey( String emailKey, boolean orderAscending )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<User> findUsersByQuery( UserQuery query )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public User findUser( Object principal )
- throws UserNotFoundException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public boolean userExists( Object principal )
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void deleteUser( Object principal )
- throws UserNotFoundException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void deleteUser( String username )
- throws UserNotFoundException
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void addUserUnchecked( User user )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void eraseDatabase()
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public User updateUser( User user, boolean passwordChangeRequired )
- throws UserNotFoundException
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
- };
- }
-
- public boolean isAuthenticated( AuthenticationDataSource arg0 )
- throws AuthenticationException, UserNotFoundException, AccountLockedException
- {
- return false;
- }
-
- public boolean isAuthorized( SecuritySession arg0, Object arg1 )
- throws AuthorizationException
- {
- return false;
- }
-
- public boolean isAuthorized( SecuritySession arg0, Object arg1, Object arg2 )
- throws AuthorizationException
- {
- if ( repoIds.contains( arg2 ) )
- {
- return true;
- }
-
- return false;
- }
-
-}
+++ /dev/null
-package org.apache.archiva.webtest.memory;
-
-/*
- * 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 org.apache.archiva.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.model.MetadataFacet;
-import org.apache.archiva.metadata.model.ProjectMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionReference;
-import org.apache.archiva.metadata.repository.MetadataRepository;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-public class TestMetadataRepository
- implements MetadataRepository
-{
- private static final String TEST_REPO = "test-repo";
-
- private static final String TEST_NAMESPACE = "org.apache.archiva";
-
- private List<ArtifactMetadata> artifacts = new ArrayList<ArtifactMetadata>();
-
- private List<String> versions = new ArrayList<String>();
-
- public TestMetadataRepository()
- {
- Date whenGathered = new Date( 123456789 );
-
- addArtifact( "artifact-one", "1.0", whenGathered );
- addArtifact( "artifact-one", "1.1", whenGathered );
- addArtifact( "artifact-one", "2.0", whenGathered );
- addArtifact( "artifact-two", "1.0.1", whenGathered );
- addArtifact( "artifact-two", "1.0.2", whenGathered );
- addArtifact( "artifact-two", "1.0.3-SNAPSHOT", whenGathered );
- addArtifact( "artifact-three", "2.0-SNAPSHOT", whenGathered );
- addArtifact( "artifact-four", "1.1-beta-2", whenGathered );
- }
-
- private void addArtifact( String projectId, String projectVersion, Date whenGathered )
- {
- ArtifactMetadata artifact = new ArtifactMetadata();
- artifact.setFileLastModified( System.currentTimeMillis() );
- artifact.setNamespace( TEST_NAMESPACE );
- artifact.setProjectVersion( projectVersion );
- artifact.setVersion( projectVersion );
- artifact.setId( projectId + "-" + projectVersion + ".jar" );
- artifact.setProject( projectId );
- artifact.setRepositoryId( TEST_REPO );
- artifact.setWhenGathered( whenGathered );
- artifacts.add( artifact );
-
- versions.add( projectVersion );
- }
-
- public ProjectMetadata getProject( String repoId, String namespace, String projectId )
- {
- throw new UnsupportedOperationException();
- }
-
- public ProjectVersionMetadata getProjectVersion( String repoId, String namespace, String projectId,
- String projectVersion )
- {
- throw new UnsupportedOperationException();
- }
-
- public Collection<String> getArtifactVersions( String repoId, String namespace, String projectId,
- String projectVersion )
- {
- throw new UnsupportedOperationException();
- }
-
- public Collection<ProjectVersionReference> getProjectReferences( String repoId, String namespace, String projectId,
- String projectVersion )
- {
- throw new UnsupportedOperationException();
- }
-
- public Collection<String> getRootNamespaces( String repoId )
- {
- throw new UnsupportedOperationException();
- }
-
- public Collection<String> getNamespaces( String repoId, String namespace )
- {
- throw new UnsupportedOperationException();
- }
-
- public Collection<String> getProjects( String repoId, String namespace )
- {
- throw new UnsupportedOperationException();
- }
-
- public Collection<String> getProjectVersions( String repoId, String namespace, String projectId )
- {
- return versions;
- }
-
- public void updateProject( String repoId, ProjectMetadata project )
- {
- throw new UnsupportedOperationException();
- }
-
- public void updateArtifact( String repoId, String namespace, String projectId, String projectVersion,
- ArtifactMetadata artifactMeta )
- {
- throw new UnsupportedOperationException();
- }
-
- public void updateProjectVersion( String repoId, String namespace, String projectId,
- ProjectVersionMetadata versionMetadata )
- {
- throw new UnsupportedOperationException();
- }
-
- public void updateNamespace( String repoId, String namespace )
- {
- throw new UnsupportedOperationException();
- }
-
- public List<String> getMetadataFacets( String repodId, String facetId )
- {
- return Collections.emptyList();
- }
-
- public MetadataFacet getMetadataFacet( String repositoryId, String facetId, String name )
- {
- throw new UnsupportedOperationException();
- }
-
- public void addMetadataFacet( String repositoryId, MetadataFacet metadataFacet )
- {
- throw new UnsupportedOperationException();
- }
-
- public void removeMetadataFacets( String repositoryId, String facetId )
- {
- throw new UnsupportedOperationException();
- }
-
- public void removeMetadataFacet( String repoId, String facetId, String name )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<ArtifactMetadata> getArtifactsByDateRange( String repoId, Date startTime, Date endTime )
- {
- return artifacts;
- }
-
- public Collection<String> getRepositories()
- {
- return Collections.singletonList( TEST_REPO );
- }
-
- public List<ArtifactMetadata> getArtifactsByChecksum( String repoId, String checksum )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void removeArtifact( String repositoryId, String namespace, String project, String version, String id )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public void removeRepository( String repoId )
- {
- //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Collection<ArtifactMetadata> getArtifacts( String repoId, String namespace, String projectId,
- String projectVersion )
- {
- return artifacts;
- }
-
- public void save()
- {
- }
-
- public void close()
- {
- }
-
- public void revert()
- {
- throw new UnsupportedOperationException();
- }
-
- public boolean canObtainAccess( Class<?> aClass )
- {
- return false; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public Object obtainAccess( Class<?> aClass )
- {
- return null; //To change body of implemented methods use File | Settings | File Templates.
- }
-
- public List<ArtifactMetadata> getArtifacts( String repositoryId )
- {
- return artifacts;
- }
-}
\ No newline at end of file
+++ /dev/null
-package org.apache.archiva.webtest.memory;
-
-/*
- * 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 org.apache.archiva.metadata.model.ArtifactMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionMetadata;
-import org.apache.archiva.metadata.model.ProjectVersionReference;
-import org.apache.archiva.metadata.repository.MetadataResolver;
-import org.apache.archiva.metadata.repository.RepositorySession;
-
-import java.util.Collection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.LinkedHashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-
-public class TestMetadataResolver
- implements MetadataResolver
-{
- private Map<String, ProjectVersionMetadata> projectVersions = new HashMap<String, ProjectVersionMetadata>();
-
- private Map<String, List<ArtifactMetadata>> artifacts = new HashMap<String, List<ArtifactMetadata>>();
-
- private Map<String, List<ProjectVersionReference>> references =
- new HashMap<String, List<ProjectVersionReference>>();
-
- private Map<String, List<String>> namespaces = new HashMap<String, List<String>>();
-
- private Map<String, Collection<String>> projectsInNamespace = new HashMap<String, Collection<String>>();
-
- private Map<String, Collection<String>> versionsInProject = new HashMap<String, Collection<String>>();
-
- public ProjectVersionMetadata resolveProjectVersion( RepositorySession repositorySession, String repoId,
- String namespace, String projectId, String projectVersion )
- {
- return projectVersions.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
- }
-
- public Collection<ProjectVersionReference> resolveProjectReferences( RepositorySession repositorySession,
- String repoId, String namespace,
- String projectId, String projectVersion )
- {
- Collection<ProjectVersionReference> projectVersionReferences =
- references.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
- return projectVersionReferences;
- }
-
- public Collection<String> resolveRootNamespaces( RepositorySession repositorySession, String repoId )
- {
- return resolveNamespaces( repositorySession, repoId, null );
- }
-
- public Collection<String> resolveNamespaces( RepositorySession repositorySession, String repoId,
- String baseNamespace )
- {
- Set<String> namespaces = new LinkedHashSet<String>();
- int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
- for ( String namespace : this.namespaces.get( repoId ) )
- {
- if ( baseNamespace == null || namespace.startsWith( baseNamespace + "." ) )
- {
- int i = namespace.indexOf( '.', fromIndex );
- if ( i >= 0 )
- {
- namespaces.add( namespace.substring( fromIndex, i ) );
- }
- else
- {
- namespaces.add( namespace.substring( fromIndex ) );
- }
- }
- }
- return namespaces;
- }
-
- public Collection<String> resolveProjects( RepositorySession repositorySession, String repoId, String namespace )
- {
- Collection<String> list = projectsInNamespace.get( namespace );
- return list != null ? list : Collections.<String>emptyList();
- }
-
- public Collection<String> resolveProjectVersions( RepositorySession repositorySession, String repoId,
- String namespace, String projectId )
- {
- Collection<String> list = versionsInProject.get( namespace + ":" + projectId );
- return list != null ? list : Collections.<String>emptyList();
- }
-
- public Collection<ArtifactMetadata> resolveArtifacts( RepositorySession repositorySession, String repoId,
- String namespace, String projectId, String projectVersion )
- {
- List<ArtifactMetadata> artifacts =
- this.artifacts.get( createMapKey( repoId, namespace, projectId, projectVersion ) );
- return ( artifacts != null ? artifacts : Collections.<ArtifactMetadata>emptyList() );
- }
-
- public void setProjectVersion( String repoId, String namespace, String projectId,
- ProjectVersionMetadata versionMetadata )
- {
- projectVersions.put( createMapKey( repoId, namespace, projectId, versionMetadata.getId() ), versionMetadata );
-
- Collection<String> projects = projectsInNamespace.get( namespace );
- if ( projects == null )
- {
- projects = new LinkedHashSet<String>();
- projectsInNamespace.put( namespace, projects );
- }
- projects.add( projectId );
-
- String key = namespace + ":" + projectId;
- Collection<String> versions = versionsInProject.get( key );
- if ( versions == null )
- {
- versions = new LinkedHashSet<String>();
- versionsInProject.put( key, versions );
- }
- versions.add( versionMetadata.getId() );
- }
-
- public void setArtifacts( String repoId, String namespace, String projectId, String projectVersion,
- List<ArtifactMetadata> artifacts )
- {
- this.artifacts.put( createMapKey( repoId, namespace, projectId, projectVersion ), artifacts );
- }
-
- private String createMapKey( String repoId, String namespace, String projectId, String projectVersion )
- {
- return repoId + ":" + namespace + ":" + projectId + ":" + projectVersion;
- }
-
- public void setProjectReferences( String repoId, String namespace, String projectId, String projectVersion,
- List<ProjectVersionReference> references )
- {
- this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references );
- }
-
- public void setNamespaces( String repoId, List<String> namespaces )
- {
- this.namespaces.put( repoId, namespaces );
- }
-}
+++ /dev/null
-package org.apache.archiva.webtest.memory;
-
-/*
- * 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 org.apache.archiva.metadata.repository.RepositorySession;
-import org.apache.archiva.metadata.repository.RepositorySessionFactory;
-import org.springframework.stereotype.Service;
-
-@Service("repositorySessionFactory#test")
-public class TestRepositorySessionFactory
- implements RepositorySessionFactory
-{
- private RepositorySession repositorySession;
-
- public void setRepositorySession( RepositorySession repositorySession )
- {
- this.repositorySession = repositorySession;
- }
-
- public RepositorySession createSession()
- {
- return repositorySession != null ? repositorySession : new RepositorySession( new TestMetadataRepository(),
- new TestMetadataResolver() );
- }
-}
+++ /dev/null
-<?xml version="1.0"?>
-
-<!--
- ~ 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.
- -->
-<beans xmlns="http://www.springframework.org/schema/beans"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns:context="http://www.springframework.org/schema/context"
- xsi:schemaLocation="http://www.springframework.org/schema/beans
- http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
- http://www.springframework.org/schema/context
- http://www.springframework.org/schema/context/spring-context-3.0.xsd"
- default-lazy-init="true">
-
- <context:property-placeholder system-properties-mode="OVERRIDE"/>
-
- <context:annotation-config/>
- <context:component-scan base-package="org.apache.archiva.webtest.memory"/>
-
- <alias name="repositorySessionFactory#test" alias="repositorySessionFactory"/>
-
- <bean name="userRepositories#test" class="org.apache.archiva.security.UserRepositoriesStub"/>
-
- <alias name="userRepositories#test" alias="userRepositories"/>
-
-
- <bean name="securitySystem#test" class="org.apache.archiva.web.rss.SecuritySystemStub"/>
-
- <alias name="securitySystem#test" alias="securitySystem"/>
-
- <bean name="archivaConfiguration#default" class="org.apache.archiva.configuration.DefaultArchivaConfiguration">
- <property name="registry" ref="registry#default"/>
- </bean>
-
- <alias name="archivaConfiguration#default" alias="archivaConfiguration"/>
-
- <bean name="registry#default" class="org.codehaus.redback.components.registry.commons.CommonsConfigurationRegistry">
- <property name="properties">
- <value>
- <![CDATA[
- <configuration>
- <system/>
- <xml fileName="${test.resources.path}/empty-archiva.xml" config-forceCreate="true"
- config-optional="true"
- config-name="org.apache.archiva.base" config-at="org.apache.archiva"/>
- </configuration>
- ]]>
- </value>
- </property>
- </bean>
-
- <bean name="RoleManagerStub" class="org.apache.archiva.web.rss.RoleManagerStub"/>
-
-</beans>
\ No newline at end of file
+++ /dev/null
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
- ~ 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.
- -->
-
-<web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
- xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
-
- <display-name>Apache Archiva</display-name>
-
- <listener>
- <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
- </listener>
-
- <context-param>
- <param-name>contextClass</param-name>
- <param-value>org.codehaus.redback.components.springutils.CachingWebApplicationContext</param-value>
- </context-param>
-
- <servlet>
- <servlet-name>RssFeedServlet</servlet-name>
- <servlet-class>org.apache.archiva.web.rss.RssFeedServlet</servlet-class>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>RssFeedServlet</servlet-name>
- <url-pattern>/feeds/*</url-pattern>
- </servlet-mapping>
-
- <context-param>
- <param-name>contextConfigLocation</param-name>
- <param-value>
- classpath*:/META-INF/spring-context.xml
- classpath*:/spring-context-rss-servlet.xml
- </param-value>
- </context-param>
-
-</web-app>