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;
}
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")));
}
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")));
}
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);
}
}
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
}
}
Aggregations