Search in sources :

Example 1 with User

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

the class PrincipalDatabaseAuthenticationManager method createUser.

@Override
public boolean createUser(String username, String password, Map<String, String> attributes) {
    Map<String, Object> userAttrs = new HashMap<>();
    userAttrs.put(User.NAME, username);
    userAttrs.put(User.PASSWORD, password);
    User user = createChild(User.class, userAttrs);
    return user != null;
}
Also used : User(org.apache.qpid.server.model.User) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) ConfiguredObject(org.apache.qpid.server.model.ConfiguredObject) AbstractConfiguredObject(org.apache.qpid.server.model.AbstractConfiguredObject)

Example 2 with User

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

the class PlainPasswordDatabaseAuthenticationManagerTest method testAddUser.

public void testAddUser() {
    _passwordFile = TestFileUtils.createTempFile(this, ".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(0)));
    Map<String, Object> userAttrs = new HashMap<>();
    userAttrs.put(User.TYPE, PROVIDER_TYPE);
    userAttrs.put(User.NAME, "user");
    userAttrs.put(User.PASSWORD, "password");
    User user = (User) provider.createChild(User.class, userAttrs);
    assertThat(provider.getChildren(User.class).size(), is(equalTo(1)));
    assertThat(user.getName(), is(equalTo("user")));
}
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)

Example 3 with User

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

the class PlainPasswordDatabaseAuthenticationManagerTest method testExistingPasswordFile.

public void testExistingPasswordFile() {
    _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());
    @SuppressWarnings("unchecked") 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");
    assertThat(user.getName(), is(equalTo("user")));
}
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)

Example 4 with User

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

the class PrincipalDatabaseAuthenticationManager method setPassword.

@Override
public void setPassword(String username, String password) throws AccountNotFoundException {
    Principal principal = new UsernamePrincipal(username, this);
    User user = _userMap.get(principal);
    if (user != null) {
        user.setPassword(password);
    }
}
Also used : UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) User(org.apache.qpid.server.model.User) UsernamePrincipal(org.apache.qpid.server.security.auth.UsernamePrincipal) Principal(java.security.Principal)

Example 5 with User

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

the class ManagedAuthenticationManagerTestBase method testCreateUser.

public void testCreateUser() throws ExecutionException, InterruptedException {
    assertEquals("No users should be present before the test starts", 0, _authManager.getChildren(User.class).size());
    assertTrue(_authManager.createUser(getTestName(), "password", Collections.<String, String>emptyMap()));
    assertEquals("Manager should have exactly one user child", 1, _authManager.getChildren(User.class).size());
    User user = _authManager.getChildren(User.class).iterator().next();
    assertEquals(getTestName(), user.getName());
    if (!isPlain()) {
        // password shouldn't actually be the given string, but instead salt and the hashed value
        assertFalse("Password shouldn't actually be the given string, but instead salt and the hashed value", "password".equals(user.getPassword()));
    }
    final Map<String, Object> childAttrs = new HashMap<String, Object>();
    childAttrs.put(User.NAME, getTestName());
    childAttrs.put(User.PASSWORD, "password");
    try {
        user = _authManager.addChildAsync(User.class, childAttrs).get();
        fail("Should not be able to create a second user with the same name");
    } catch (IllegalArgumentException e) {
    // pass
    }
    try {
        _authManager.deleteUser(getTestName());
    } catch (AccountNotFoundException e) {
        fail("AccountNotFoundException thrown when none was expected: " + e.getMessage());
    }
    try {
        _authManager.deleteUser(getTestName());
        fail("AccountNotFoundException not thrown when was expected");
    } catch (AccountNotFoundException e) {
    // pass
    }
}
Also used : User(org.apache.qpid.server.model.User) HashMap(java.util.HashMap) AccountNotFoundException(javax.security.auth.login.AccountNotFoundException)

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