Search in sources :

Example 6 with User

use of org.apache.qpid.server.model.User 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());
}
Also used : User(org.apache.qpid.server.model.User) HashMap(java.util.HashMap) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 7 with User

use of org.apache.qpid.server.model.User 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());
}
Also used : User(org.apache.qpid.server.model.User) AuthenticationResult(org.apache.qpid.server.security.auth.AuthenticationResult)

Example 8 with User

use of org.apache.qpid.server.model.User in project qpid-broker-j by apache.

the class PlainPasswordDatabaseAuthenticationManagerTest method testRemoveUser.

public void testRemoveUser() {
    _passwordFile = TestFileUtils.createTempFile(this, ".user.password", "user:password");
    Map<String, Object> providerAttrs = new HashMap<>();
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.TYPE, PROVIDER_TYPE);
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.PATH, _passwordFile.getAbsolutePath());
    providerAttrs.put(PlainPasswordDatabaseAuthenticationManager.NAME, getTestName());
    AuthenticationProvider provider = _objectFactory.create(AuthenticationProvider.class, providerAttrs, _broker);
    assertThat(provider.getChildren(User.class).size(), is(equalTo(1)));
    User user = (User) provider.getChildByName(User.class, "user");
    user.delete();
    assertThat(provider.getChildren(User.class).size(), is(equalTo(0)));
}
Also used : User(org.apache.qpid.server.model.User) HashMap(java.util.HashMap) PasswordCredentialManagingAuthenticationProvider(org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider) AuthenticationProvider(org.apache.qpid.server.model.AuthenticationProvider)

Aggregations

User (org.apache.qpid.server.model.User)8 HashMap (java.util.HashMap)6 AuthenticationProvider (org.apache.qpid.server.model.AuthenticationProvider)3 PasswordCredentialManagingAuthenticationProvider (org.apache.qpid.server.model.PasswordCredentialManagingAuthenticationProvider)3 AuthenticationResult (org.apache.qpid.server.security.auth.AuthenticationResult)2 Principal (java.security.Principal)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 AccountNotFoundException (javax.security.auth.login.AccountNotFoundException)1 AbstractConfiguredObject (org.apache.qpid.server.model.AbstractConfiguredObject)1 ConfiguredObject (org.apache.qpid.server.model.ConfiguredObject)1 UsernamePrincipal (org.apache.qpid.server.security.auth.UsernamePrincipal)1