mirror of
https://github.com/apache/archiva.git
synced 2025-02-26 12:45:51 +00:00
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:
parent
ac11c556bd
commit
4d43fd26f3
MRM-124/archiva-modules
archiva-base/archiva-xml-tools/src/test/java/org/apache/maven/archiva/xml
archiva-web/archiva-xmlrpc/archiva-xmlrpc-security/src
main/java/org/apache/maven/archiva/xmlrpc/security
test/java/org/apache/maven/archiva/xmlrpc/security
@ -33,8 +33,11 @@ public abstract class AbstractArchivaXmlTestCase
|
|||||||
extends TestCase
|
extends TestCase
|
||||||
{
|
{
|
||||||
protected static final String OSLASH = "\u00f8";
|
protected static final String OSLASH = "\u00f8";
|
||||||
|
|
||||||
protected static final String TRYGVIS = "Trygve Laugst" + OSLASH + "l";
|
protected static final String TRYGVIS = "Trygve Laugst" + OSLASH + "l";
|
||||||
|
|
||||||
protected static final String INFIN = "\u221e";
|
protected static final String INFIN = "\u221e";
|
||||||
|
|
||||||
protected static final String INFINITE_ARCHIVA = "The " + INFIN + " Archiva";
|
protected static final String INFINITE_ARCHIVA = "The " + INFIN + " Archiva";
|
||||||
|
|
||||||
protected File getExampleXml( String filename )
|
protected File getExampleXml( String filename )
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
package org.apache.maven.archiva.xmlrpc.security;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
@ -18,8 +19,6 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.apache.maven.archiva.xmlrpc.security;
|
|
||||||
|
|
||||||
import org.apache.maven.archiva.security.ArchivaRoleConstants;
|
import org.apache.maven.archiva.security.ArchivaRoleConstants;
|
||||||
import org.apache.xmlrpc.XmlRpcException;
|
import org.apache.xmlrpc.XmlRpcException;
|
||||||
import org.apache.xmlrpc.XmlRpcRequest;
|
import org.apache.xmlrpc.XmlRpcRequest;
|
||||||
@ -34,58 +33,63 @@
|
|||||||
import org.codehaus.plexus.redback.system.SecuritySystem;
|
import org.codehaus.plexus.redback.system.SecuritySystem;
|
||||||
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
||||||
|
|
||||||
public class XmlRpcAuthenticator implements AuthenticationHandler
|
public class XmlRpcAuthenticator
|
||||||
|
implements AuthenticationHandler
|
||||||
{
|
{
|
||||||
private final SecuritySystem securitySystem;
|
private final SecuritySystem securitySystem;
|
||||||
|
|
||||||
public XmlRpcAuthenticator(SecuritySystem securitySystem)
|
public XmlRpcAuthenticator( SecuritySystem securitySystem )
|
||||||
{
|
{
|
||||||
this.securitySystem = securitySystem;
|
this.securitySystem = securitySystem;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthorized(XmlRpcRequest pRequest) throws XmlRpcException {
|
public boolean isAuthorized( XmlRpcRequest pRequest )
|
||||||
if (pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl)
|
throws XmlRpcException
|
||||||
|
{
|
||||||
|
if ( pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl )
|
||||||
{
|
{
|
||||||
XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl)pRequest.getConfig();
|
XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl) pRequest.getConfig();
|
||||||
SecuritySession session = authenticate(new PasswordBasedAuthenticationDataSource(config.getBasicUserName(), config.getBasicPassword()));
|
SecuritySession session =
|
||||||
AuthorizationResult result = authorize(session);
|
authenticate( new PasswordBasedAuthenticationDataSource( config.getBasicUserName(),
|
||||||
|
config.getBasicPassword() ) );
|
||||||
|
AuthorizationResult result = authorize( session );
|
||||||
return result.isAuthorized();
|
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
|
throws XmlRpcException
|
||||||
{
|
{
|
||||||
try
|
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
|
throws XmlRpcException
|
||||||
{
|
{
|
||||||
try
|
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 );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,3 @@
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
* or more contributor license agreements. See the NOTICE file
|
* or more contributor license agreements. See the NOTICE file
|
||||||
@ -37,56 +36,68 @@
|
|||||||
import org.codehaus.plexus.redback.users.UserManager;
|
import org.codehaus.plexus.redback.users.UserManager;
|
||||||
import org.codehaus.plexus.redback.users.UserNotFoundException;
|
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 USERNAME = "username";
|
||||||
|
|
||||||
private static final String PASSWORD = "password";
|
private static final String PASSWORD = "password";
|
||||||
|
|
||||||
public void testAuthentication() throws Exception
|
public void testAuthentication()
|
||||||
|
throws Exception
|
||||||
{
|
{
|
||||||
MockSecuritySystem securitySystem = new MockSecuritySystem(true, true, USERNAME, PASSWORD);
|
MockSecuritySystem securitySystem = new MockSecuritySystem( true, true, USERNAME, PASSWORD );
|
||||||
XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator(securitySystem);
|
XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator( securitySystem );
|
||||||
MockXmlRpcRequest request = new MockXmlRpcRequest(USERNAME, PASSWORD);
|
MockXmlRpcRequest request = new MockXmlRpcRequest( USERNAME, PASSWORD );
|
||||||
|
|
||||||
assertTrue(authenticator.isAuthorized(request));
|
assertTrue( authenticator.isAuthorized( request ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockXmlRpcRequest implements XmlRpcRequest
|
class MockXmlRpcRequest
|
||||||
|
implements XmlRpcRequest
|
||||||
{
|
{
|
||||||
private final XmlRpcHttpRequestConfigImpl configImpl;
|
private final XmlRpcHttpRequestConfigImpl configImpl;
|
||||||
|
|
||||||
public MockXmlRpcRequest(String username, String password)
|
public MockXmlRpcRequest( String username, String password )
|
||||||
{
|
{
|
||||||
configImpl = new XmlRpcHttpRequestConfigImpl();
|
configImpl = new XmlRpcHttpRequestConfigImpl();
|
||||||
configImpl.setBasicUserName(username);
|
configImpl.setBasicUserName( username );
|
||||||
configImpl.setBasicPassword(password);
|
configImpl.setBasicPassword( password );
|
||||||
}
|
}
|
||||||
|
|
||||||
public XmlRpcRequestConfig getConfig() {
|
public XmlRpcRequestConfig getConfig()
|
||||||
|
{
|
||||||
return configImpl;
|
return configImpl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMethodName() {
|
public String getMethodName()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object getParameter(int pIndex) {
|
public Object getParameter( int pIndex )
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getParameterCount() {
|
public int getParameterCount()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class MockSecuritySystem implements SecuritySystem
|
class MockSecuritySystem
|
||||||
|
implements SecuritySystem
|
||||||
{
|
{
|
||||||
private final boolean authorized;
|
private final boolean authorized;
|
||||||
|
|
||||||
private final boolean authenticate;
|
private final boolean authenticate;
|
||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
|
|
||||||
private final String password;
|
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.authorized = authorized;
|
||||||
this.authenticate = authenticate;
|
this.authenticate = authenticate;
|
||||||
@ -94,65 +105,87 @@ public MockSecuritySystem(boolean authorized, boolean authenticate, String usern
|
|||||||
this.password = password;
|
this.password = password;
|
||||||
}
|
}
|
||||||
|
|
||||||
public SecuritySession authenticate(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {
|
public SecuritySession authenticate( AuthenticationDataSource dataSource )
|
||||||
return new SecuritySession() {
|
throws AuthenticationException, UserNotFoundException, AccountLockedException
|
||||||
|
{
|
||||||
|
return new SecuritySession()
|
||||||
|
{
|
||||||
|
|
||||||
public AuthenticationResult getAuthenticationResult() {
|
public AuthenticationResult getAuthenticationResult()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public User getUser() {
|
public User getUser()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthenticated() {
|
public boolean isAuthenticated()
|
||||||
|
{
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthorizationResult authorize(SecuritySession session, Object arg1) throws AuthorizationException {
|
public AuthorizationResult authorize( SecuritySession session, Object arg1 )
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throws AuthorizationException
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public AuthorizationResult authorize(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {
|
public AuthorizationResult authorize( SecuritySession session, Object arg1, Object arg2 )
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throws AuthorizationException
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthenticatorId() {
|
public String getAuthenticatorId()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAuthorizerId() {
|
public String getAuthorizerId()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public KeyManager getKeyManager() {
|
public KeyManager getKeyManager()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserSecurityPolicy getPolicy() {
|
public UserSecurityPolicy getPolicy()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUserManagementId() {
|
public String getUserManagementId()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserManager getUserManager() {
|
public UserManager getUserManager()
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthenticated(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {
|
public boolean isAuthenticated( AuthenticationDataSource dataSource )
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throws AuthenticationException, UserNotFoundException, AccountLockedException
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthorized(SecuritySession session, Object arg1) throws AuthorizationException {
|
public boolean isAuthorized( SecuritySession session, Object arg1 )
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throws AuthorizationException
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isAuthorized(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {
|
public boolean isAuthorized( SecuritySession session, Object arg1, Object arg2 )
|
||||||
throw new UnsupportedOperationException("Not supported yet.");
|
throws AuthorizationException
|
||||||
|
{
|
||||||
|
throw new UnsupportedOperationException( "Not supported yet." );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user