use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.
the class ManagedAuthenticationManagerTestBase method testAddChildAndThenDelete.
public void testAddChildAndThenDelete() throws ExecutionException, InterruptedException {
// No children should be present before the test starts
assertEquals("No users should be present before the test starts", 0, _authManager.getChildren(User.class).size());
assertEquals("No users should be present before the test starts", 0, _authManager.getUsers().size());
final Map<String, Object> childAttrs = new HashMap<String, Object>();
childAttrs.put(User.NAME, getTestName());
childAttrs.put(User.PASSWORD, "password");
User user = _authManager.addChildAsync(User.class, childAttrs).get();
assertNotNull("User should be created but addChild returned null", user);
assertEquals(getTestName(), user.getName());
if (!isPlain()) {
// password shouldn't actually be the given string, but instead hashed value
assertFalse("Password shouldn't actually be the given string, but instead hashed value", "password".equals(user.getPassword()));
}
AuthenticationResult authResult = _authManager.authenticate(getTestName(), "password");
assertEquals("User should authenticate with given password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
assertEquals("Manager should have exactly one user child", 1, _authManager.getChildren(User.class).size());
assertEquals("Manager should have exactly one user child", 1, _authManager.getUsers().size());
user.delete();
assertEquals("No users should be present after child deletion", 0, _authManager.getChildren(User.class).size());
authResult = _authManager.authenticate(getTestName(), "password");
assertEquals("User should no longer authenticate with given password", AuthenticationResult.AuthenticationStatus.ERROR, authResult.getStatus());
}
use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.
the class ManagedAuthenticationManagerTestBase method testUpdateUser.
public void testUpdateUser() {
assertTrue(_authManager.createUser(getTestName(), "password", Collections.<String, String>emptyMap()));
assertTrue(_authManager.createUser(getTestName() + "_2", "password", Collections.<String, String>emptyMap()));
assertEquals("Manager should have exactly two user children", 2, _authManager.getChildren(User.class).size());
AuthenticationResult authResult = _authManager.authenticate(getTestName(), "password");
assertEquals("User should authenticate with given password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
authResult = _authManager.authenticate(getTestName() + "_2", "password");
assertEquals("User should authenticate with given password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
for (User user : _authManager.getChildren(User.class)) {
if (user.getName().equals(getTestName())) {
user.setAttributes(Collections.singletonMap(User.PASSWORD, "newpassword"));
}
}
authResult = _authManager.authenticate(getTestName(), "newpassword");
assertEquals("User should authenticate with updated password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
authResult = _authManager.authenticate(getTestName() + "_2", "password");
assertEquals("User should authenticate with original password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
authResult = _authManager.authenticate(getTestName(), "password");
assertEquals("User not authenticate with original password", AuthenticationResult.AuthenticationStatus.ERROR, authResult.getStatus());
for (User user : _authManager.getChildren(User.class)) {
if (user.getName().equals(getTestName())) {
user.setPassword("newerpassword");
}
}
authResult = _authManager.authenticate(getTestName(), "newerpassword");
assertEquals("User should authenticate with updated password", AuthenticationResult.AuthenticationStatus.SUCCESS, authResult.getStatus());
}
use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.
the class ManagedAuthenticationManagerTestBase method testAuthenticateValidCredentials.
public void testAuthenticateValidCredentials() throws Exception {
_authManager.createUser(TEST_USER_NAME, TEST_USER_PASSWORD, Collections.<String, String>emptyMap());
AuthenticationResult result = _authManager.authenticate(TEST_USER_NAME, TEST_USER_PASSWORD);
assertEquals("Unexpected result status", AuthenticationResult.AuthenticationStatus.SUCCESS, result.getStatus());
assertEquals("Unexpected result principal", TEST_USER_NAME, result.getMainPrincipal().getName());
}
use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.
the class PrincipalDatabaseAuthenticationManagerTest method testNonSaslAuthenticationErrored.
public void testNonSaslAuthenticationErrored() throws Exception {
setupMocks();
when(_principalDatabase.verifyPassword("guest", "wrongpassword".toCharArray())).thenReturn(false);
AuthenticationResult result = _manager.authenticate("guest", "wrongpassword");
assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
assertEquals(AuthenticationStatus.ERROR, result.getStatus());
}
use of org.apache.qpid.server.security.auth.AuthenticationResult in project qpid-broker-j by apache.
the class PrincipalDatabaseAuthenticationManagerTest method testSaslAuthenticationError.
/**
* Tests that the authenticate method correctly interprets an
* authentication error.
*/
public void testSaslAuthenticationError() throws Exception {
setupMocks();
when(_saslNegotiator.handleResponse(any(byte[].class))).thenReturn(new AuthenticationResult(AuthenticationStatus.ERROR));
AuthenticationResult result = _saslNegotiator.handleResponse("12345".getBytes());
assertEquals("Principals was not expected size", 0, result.getPrincipals().size());
assertEquals(AuthenticationStatus.ERROR, result.getStatus());
}
Aggregations