+package org.apache.maven.archiva.xmlrpc.security;\r
\r
/*\r
* Licensed to the Apache Software Foundation (ASF) under one\r
* under the License.\r
*/\r
\r
-package org.apache.maven.archiva.xmlrpc.security;\r
-\r
import org.apache.maven.archiva.security.ArchivaRoleConstants;\r
import org.apache.xmlrpc.XmlRpcException;\r
import org.apache.xmlrpc.XmlRpcRequest;\r
import org.codehaus.plexus.redback.system.SecuritySystem;\r
import org.codehaus.plexus.redback.users.UserNotFoundException;\r
\r
-public class XmlRpcAuthenticator implements AuthenticationHandler\r
+public class XmlRpcAuthenticator\r
+ implements AuthenticationHandler\r
{\r
private final SecuritySystem securitySystem;\r
\r
- public XmlRpcAuthenticator(SecuritySystem securitySystem)\r
+ public XmlRpcAuthenticator( SecuritySystem securitySystem )\r
{\r
this.securitySystem = securitySystem;\r
}\r
\r
- public boolean isAuthorized(XmlRpcRequest pRequest) throws XmlRpcException {\r
- if (pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl)\r
+ public boolean isAuthorized( XmlRpcRequest pRequest )\r
+ throws XmlRpcException\r
+ {\r
+ if ( pRequest.getConfig() instanceof XmlRpcHttpRequestConfigImpl )\r
{\r
- XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl)pRequest.getConfig();\r
- SecuritySession session = authenticate(new PasswordBasedAuthenticationDataSource(config.getBasicUserName(), config.getBasicPassword()));\r
- AuthorizationResult result = authorize(session);\r
+ XmlRpcHttpRequestConfigImpl config = (XmlRpcHttpRequestConfigImpl) pRequest.getConfig();\r
+ SecuritySession session =\r
+ authenticate( new PasswordBasedAuthenticationDataSource( config.getBasicUserName(),\r
+ config.getBasicPassword() ) );\r
+ AuthorizationResult result = authorize( session );\r
return result.isAuthorized();\r
}\r
\r
- throw new XmlRpcException("Unsupported transport (must be http)");\r
+ throw new XmlRpcException( "Unsupported transport (must be http)" );\r
}\r
- \r
- private SecuritySession authenticate(PasswordBasedAuthenticationDataSource authenticationDataSource)\r
+\r
+ private SecuritySession authenticate( PasswordBasedAuthenticationDataSource authenticationDataSource )\r
throws XmlRpcException\r
{\r
try\r
{\r
- return securitySystem.authenticate(authenticationDataSource);\r
+ return securitySystem.authenticate( authenticationDataSource );\r
}\r
- catch (AccountLockedException e)\r
+ catch ( AccountLockedException e )\r
{\r
- throw new XmlRpcException(401, e.getMessage(), e);\r
+ throw new XmlRpcException( 401, e.getMessage(), e );\r
}\r
- catch (AuthenticationException e)\r
+ catch ( AuthenticationException e )\r
{\r
- throw new XmlRpcException(401, e.getMessage(), e);\r
+ throw new XmlRpcException( 401, e.getMessage(), e );\r
}\r
- catch (UserNotFoundException e)\r
+ catch ( UserNotFoundException e )\r
{\r
- throw new XmlRpcException(401, e.getMessage(), e);\r
+ throw new XmlRpcException( 401, e.getMessage(), e );\r
}\r
}\r
- \r
- private AuthorizationResult authorize(SecuritySession session)\r
+\r
+ private AuthorizationResult authorize( SecuritySession session )\r
throws XmlRpcException\r
{\r
try\r
{\r
- return securitySystem.authorize(session, ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE);\r
+ return securitySystem.authorize( session, ArchivaRoleConstants.GLOBAL_REPOSITORY_MANAGER_ROLE );\r
}\r
- catch (AuthorizationException e)\r
+ catch ( AuthorizationException e )\r
{\r
- throw new XmlRpcException(401, e.getMessage(), e);\r
+ throw new XmlRpcException( 401, e.getMessage(), e );\r
}\r
}\r
}\r
-\r
/*\r
* Licensed to the Apache Software Foundation (ASF) under one\r
* or more contributor license agreements. See the NOTICE file\r
import org.codehaus.plexus.redback.users.UserManager;\r
import org.codehaus.plexus.redback.users.UserNotFoundException;\r
\r
-public class XmlRpcAuthenticatorTest extends TestCase\r
+public class XmlRpcAuthenticatorTest\r
+ extends TestCase\r
{\r
private static final String USERNAME = "username";\r
+\r
private static final String PASSWORD = "password";\r
\r
- public void testAuthentication() throws Exception\r
+ public void testAuthentication()\r
+ throws Exception\r
{\r
- MockSecuritySystem securitySystem = new MockSecuritySystem(true, true, USERNAME, PASSWORD);\r
- XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator(securitySystem);\r
- MockXmlRpcRequest request = new MockXmlRpcRequest(USERNAME, PASSWORD);\r
- \r
- assertTrue(authenticator.isAuthorized(request));\r
+ MockSecuritySystem securitySystem = new MockSecuritySystem( true, true, USERNAME, PASSWORD );\r
+ XmlRpcAuthenticator authenticator = new XmlRpcAuthenticator( securitySystem );\r
+ MockXmlRpcRequest request = new MockXmlRpcRequest( USERNAME, PASSWORD );\r
+\r
+ assertTrue( authenticator.isAuthorized( request ) );\r
}\r
\r
- class MockXmlRpcRequest implements XmlRpcRequest\r
+ class MockXmlRpcRequest\r
+ implements XmlRpcRequest\r
{\r
private final XmlRpcHttpRequestConfigImpl configImpl;\r
- \r
- public MockXmlRpcRequest(String username, String password)\r
+\r
+ public MockXmlRpcRequest( String username, String password )\r
{\r
configImpl = new XmlRpcHttpRequestConfigImpl();\r
- configImpl.setBasicUserName(username);\r
- configImpl.setBasicPassword(password);\r
+ configImpl.setBasicUserName( username );\r
+ configImpl.setBasicPassword( password );\r
}\r
\r
- public XmlRpcRequestConfig getConfig() {\r
+ public XmlRpcRequestConfig getConfig()\r
+ {\r
return configImpl;\r
}\r
\r
- public String getMethodName() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public String getMethodName()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public Object getParameter(int pIndex) {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public Object getParameter( int pIndex )\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public int getParameterCount() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public int getParameterCount()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
}\r
\r
- class MockSecuritySystem implements SecuritySystem\r
+ class MockSecuritySystem\r
+ implements SecuritySystem\r
{\r
private final boolean authorized;\r
+\r
private final boolean authenticate;\r
+\r
private final String username;\r
+\r
private final String password;\r
\r
- public MockSecuritySystem(boolean authorized, boolean authenticate, String username, String password)\r
+ public MockSecuritySystem( boolean authorized, boolean authenticate, String username, String password )\r
{\r
this.authorized = authorized;\r
this.authenticate = authenticate;\r
this.password = password;\r
}\r
\r
- public SecuritySession authenticate(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {\r
- return new SecuritySession() {\r
+ public SecuritySession authenticate( AuthenticationDataSource dataSource )\r
+ throws AuthenticationException, UserNotFoundException, AccountLockedException\r
+ {\r
+ return new SecuritySession()\r
+ {\r
\r
- public AuthenticationResult getAuthenticationResult() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public AuthenticationResult getAuthenticationResult()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public User getUser() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public User getUser()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public boolean isAuthenticated() {\r
+ public boolean isAuthenticated()\r
+ {\r
throw new UnsupportedOperationException();\r
}\r
};\r
}\r
\r
- public AuthorizationResult authorize(SecuritySession session, Object arg1) throws AuthorizationException {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public AuthorizationResult authorize( SecuritySession session, Object arg1 )\r
+ throws AuthorizationException\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public AuthorizationResult authorize(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public AuthorizationResult authorize( SecuritySession session, Object arg1, Object arg2 )\r
+ throws AuthorizationException\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public String getAuthenticatorId() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public String getAuthenticatorId()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public String getAuthorizerId() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public String getAuthorizerId()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public KeyManager getKeyManager() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public KeyManager getKeyManager()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public UserSecurityPolicy getPolicy() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public UserSecurityPolicy getPolicy()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public String getUserManagementId() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public String getUserManagementId()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public UserManager getUserManager() {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public UserManager getUserManager()\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public boolean isAuthenticated(AuthenticationDataSource dataSource) throws AuthenticationException, UserNotFoundException, AccountLockedException {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public boolean isAuthenticated( AuthenticationDataSource dataSource )\r
+ throws AuthenticationException, UserNotFoundException, AccountLockedException\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public boolean isAuthorized(SecuritySession session, Object arg1) throws AuthorizationException {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public boolean isAuthorized( SecuritySession session, Object arg1 )\r
+ throws AuthorizationException\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
\r
- public boolean isAuthorized(SecuritySession session, Object arg1, Object arg2) throws AuthorizationException {\r
- throw new UnsupportedOperationException("Not supported yet.");\r
+ public boolean isAuthorized( SecuritySession session, Object arg1, Object arg2 )\r
+ throws AuthorizationException\r
+ {\r
+ throw new UnsupportedOperationException( "Not supported yet." );\r
}\r
}\r
}\r