applied codestyle formatting

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches@702357 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Maria Odea B. Ching 2008-10-07 06:09:00 +00:00
parent ac11c556bd
commit 4d43fd26f3
3 changed files with 116 additions and 76 deletions

View File

@ -33,10 +33,13 @@ public abstract class AbstractArchivaXmlTestCase
extends TestCase
{
protected static final String OSLASH = "\u00f8";
protected static final String TRYGVIS = "Trygve Laugst" + OSLASH + "l";
protected static final String INFIN = "\u221e";
protected static final String INFINITE_ARCHIVA = "The " + INFIN + " Archiva";
protected File getExampleXml( String filename )
{
File examplesDir = new File( "src/test/examples" );

View File

@ -1,3 +1,4 @@
package org.apache.maven.archiva.xmlrpc.security;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -18,8 +19,6 @@
* under the License.
*/
package org.apache.maven.archiva.xmlrpc.security;
import org.apache.maven.archiva.security.ArchivaRoleConstants;
import org.apache.xmlrpc.XmlRpcException;
import org.apache.xmlrpc.XmlRpcRequest;
@ -34,58 +33,63 @@ import org.codehaus.plexus.redback.system.SecuritySession;
import org.codehaus.plexus.redback.system.SecuritySystem;
import org.codehaus.plexus.redback.users.UserNotFoundException;
public class XmlRpcAuthenticator implements AuthenticationHandler
public class XmlRpcAuthenticator
implements AuthenticationHandler
{
private final SecuritySystem securitySystem;
public XmlRpcAuthenticator(SecuritySystem securitySystem)
public XmlRpcAuthenticator( SecuritySystem securitySystem )
{
this.securitySystem = securitySystem;
}
public boolean isAuthorized(XmlRpcRequest pRequest) throws XmlRpcException {
if (pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl)
public boolean isAuthorized( XmlRpcRequest pRequest )
throws XmlRpcException
{
if ( pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl )
{
XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl)pRequest.getConfig();
SecuritySession session = authenticate(new PasswordBasedAuthenticationDataSource(config.getBasicUserName(), config.getBasicPassword()));
AuthorizationResult result = authorize(session);
XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl) pRequest.getConfig();
SecuritySession session =
authenticate( new PasswordBasedAuthenticationDataSource( config.getBasicUserName(),
config.getBasicPassword() ) );
AuthorizationResult result = authorize( session );
return result.isAuthorized();
}
throw new XmlRpcException("Unsupported transport (must be http)");
throw new XmlRpcException( "Unsupported transport (must be http)" );
}
private SecuritySession authenticate(PasswordBasedAuthenticationDataSource authenticationDataSource)
private SecuritySession authenticate( PasswordBasedAuthenticationDataSource authenticationDataSource )
throws XmlRpcException
{
try
{
return securitySystem.authenticate(authenticationDataSource);
return securitySystem.authenticate( authenticationDataSource );
}
catch (AccountLockedException e)
catch ( AccountLockedException e )
{
throw new XmlRpcException(401, e.getMessage(), e);
throw new XmlRpcException( 401, e.getMessage(), e );
}
catch (AuthenticationException e)
catch ( AuthenticationException e )
{
throw new XmlRpcException(401, e.getMessage(), e);
throw new XmlRpcException( 401, e.getMessage(), e );
}
catch (UserNotFoundException e)
catch ( UserNotFoundException e )
{
throw new XmlRpcException(401, e.getMessage(), e);
throw new XmlRpcException( 401, e.getMessage(), e );
}
}
private AuthorizationResult authorize(SecuritySession session)
private AuthorizationResult authorize( SecuritySession session )
throws XmlRpcException
{
try
{
return securitySystem.authorize(session, ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE);
return securitySystem.authorize( session, ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE );
}
catch (AuthorizationException e)
catch ( AuthorizationException e )
{
throw new XmlRpcException(401, e.getMessage(), e);
throw new XmlRpcException( 401, e.getMessage(), e );
}
}
}

View File

@ -1,4 +1,3 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
@ -37,56 +36,68 @@ import org.codehaus.plexus.redback.users.User;
import org.codehaus.plexus.redback.users.UserManager;
import org.codehaus.plexus.redback.users.UserNotFoundException;
public class XmlRpcAuthenticatorTest extends TestCase
public class XmlRpcAuthenticatorTest
extends TestCase
{
private static final String USERNAME = "username";
private static final String PASSWORD = "password";
public void testAuthentication() throws Exception
public void testAuthentication()
throws Exception
{
MockSecuritySystem securitySystem = new MockSecuritySystem(true, true, USERNAME, PASSWORD);
XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator(securitySystem);
MockXmlRpcRequest request = new MockXmlRpcRequest(USERNAME, PASSWORD);
assertTrue(authenticator.isAuthorized(request));
MockSecuritySystem securitySystem = new MockSecuritySystem( true, true, USERNAME, PASSWORD );
XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator( securitySystem );
MockXmlRpcRequest request = new MockXmlRpcRequest( USERNAME, PASSWORD );
assertTrue( authenticator.isAuthorized( request ) );
}
class MockXmlRpcRequest implements XmlRpcRequest
class MockXmlRpcRequest
implements XmlRpcRequest
{
private final XmlRpcHttpRequestConfigImpl configImpl;
public MockXmlRpcRequest(String username, String password)
public MockXmlRpcRequest( String username, String password )
{
configImpl = new XmlRpcHttpRequestConfigImpl();
configImpl.setBasicUserName(username);
configImpl.setBasicPassword(password);
configImpl.setBasicUserName( username );
configImpl.setBasicPassword( password );
}
public XmlRpcRequestConfig getConfig() {
public XmlRpcRequestConfig getConfig()
{
return configImpl;
}
public String getMethodName() {
throw new UnsupportedOperationException("Not supported yet.");
public String getMethodName()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public Object getParameter(int pIndex) {
throw new UnsupportedOperationException("Not supported yet.");
public Object getParameter( int pIndex )
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public int getParameterCount() {
throw new UnsupportedOperationException("Not supported yet.");
public int getParameterCount()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
}
class MockSecuritySystem implements SecuritySystem
class MockSecuritySystem
implements SecuritySystem
{
private final boolean authorized;
private final boolean authenticate;
private final String username;
private final String password;
public MockSecuritySystem(boolean authorized, boolean authenticate, String username, String password)
public MockSecuritySystem( boolean authorized, boolean authenticate, String username, String password )
{
this.authorized = authorized;
this.authenticate = authenticate;
@ -94,65 +105,87 @@ public class XmlRpcAuthenticatorTest extends TestCase
this.password = password;
}
public SecuritySession authenticate(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {
return new SecuritySession() {
public SecuritySession authenticate( AuthenticationDataSource dataSource )
throws AuthenticationException, UserNotFoundException, AccountLockedException
{
return new SecuritySession()
{
public AuthenticationResult getAuthenticationResult() {
throw new UnsupportedOperationException("Not supported yet.");
public AuthenticationResult getAuthenticationResult()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public User getUser() {
throw new UnsupportedOperationException("Not supported yet.");
public User getUser()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public boolean isAuthenticated() {
public boolean isAuthenticated()
{
throw new UnsupportedOperationException();
}
};
}
public AuthorizationResult authorize(SecuritySession session, Object arg1) throws AuthorizationException {
throw new UnsupportedOperationException("Not supported yet.");
public AuthorizationResult authorize( SecuritySession session, Object arg1 )
throws AuthorizationException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public AuthorizationResult authorize(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {
throw new UnsupportedOperationException("Not supported yet.");
public AuthorizationResult authorize( SecuritySession session, Object arg1, Object arg2 )
throws AuthorizationException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public String getAuthenticatorId() {
throw new UnsupportedOperationException("Not supported yet.");
public String getAuthenticatorId()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public String getAuthorizerId() {
throw new UnsupportedOperationException("Not supported yet.");
public String getAuthorizerId()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public KeyManager getKeyManager() {
throw new UnsupportedOperationException("Not supported yet.");
public KeyManager getKeyManager()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public UserSecurityPolicy getPolicy() {
throw new UnsupportedOperationException("Not supported yet.");
public UserSecurityPolicy getPolicy()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public String getUserManagementId() {
throw new UnsupportedOperationException("Not supported yet.");
public String getUserManagementId()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public UserManager getUserManager() {
throw new UnsupportedOperationException("Not supported yet.");
public UserManager getUserManager()
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public boolean isAuthenticated(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {
throw new UnsupportedOperationException("Not supported yet.");
public boolean isAuthenticated( AuthenticationDataSource dataSource )
throws AuthenticationException, UserNotFoundException, AccountLockedException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public boolean isAuthorized(SecuritySession session, Object arg1) throws AuthorizationException {
throw new UnsupportedOperationException("Not supported yet.");
public boolean isAuthorized( SecuritySession session, Object arg1 )
throws AuthorizationException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
public boolean isAuthorized(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {
throw new UnsupportedOperationException("Not supported yet.");
public boolean isAuthorized( SecuritySession session, Object arg1, Object arg2 )
throws AuthorizationException
{
throw new UnsupportedOperationException( "Not supported yet." );
}
}
}