use of org.exist.security.internal.aider.UserAider in project exist by eXist-db.
the class Deployment method checkUserSettings.
private void checkUserSettings(final DBBroker broker, final RequestedPerms requestedPerms) throws PackageException {
final org.exist.security.SecurityManager secman = broker.getBrokerPool().getSecurityManager();
try {
if (requestedPerms.group.filter(g -> !secman.hasGroup(g)).isPresent()) {
secman.addGroup(broker, new GroupAider(requestedPerms.group.get()));
}
if (!secman.hasAccount(requestedPerms.user)) {
final UserAider aider = new UserAider(requestedPerms.user);
aider.setPassword(requestedPerms.password);
requestedPerms.group.ifPresent(aider::addGroup);
secman.addAccount(broker, aider);
}
} catch (final PermissionDeniedException | EXistException e) {
throw new PackageException("Failed to create user: " + requestedPerms.user, e);
}
}
use of org.exist.security.internal.aider.UserAider in project exist by eXist-db.
the class LDAPRealm method createAccountInDatabase.
private Account createAccountInDatabase(final LdapContext ctx, final String username, final SearchResult ldapUser, final String primaryGroupName) throws AuthenticationException {
try {
return executeAsSystemUser(ctx, (ctx2, broker) -> {
if (LOG.isDebugEnabled()) {
LOG.debug("Saving account '{}'.", username);
}
// get (or create) the primary group if it doesnt exist
final Group primaryGroup = getGroup(ctx, broker, primaryGroupName);
// get (or create) member groups
/*LDAPSearchContext search = ensureContextFactory().getSearch();
String userDistinguishedName = (String)ldapUser.getAttributes().get(search.getSearchAccount().getSearchAttribute(LDAPSearchAttributeKey.DN)).get();
List<String> memberOf_groupNames = findGroupnamesForUserDistinguishedName(invokingUser, userDistinguishedName);
List<Group> memberOf_groups = new ArrayList<Group>();
for(String memberOf_groupName : memberOf_groupNames) {
memberOf_groups.add(getGroup(invokingUser, memberOf_groupName));
}*/
// create the user account
final UserAider userAider = new UserAider(ID, username, primaryGroup);
// add the member groups
for (final Group memberOf_group : getGroupMembershipForLdapUser(ctx, broker, ldapUser)) {
userAider.addGroup(memberOf_group);
}
// store any requested metadata
for (final SimpleEntry<AXSchemaType, String> metadata : getMetadataForLdapUser(ldapUser)) {
userAider.setMetadataValue(metadata.getKey(), metadata.getValue());
}
final Account account = getSecurityManager().addAccount(userAider);
return account;
});
} catch (final Exception e) {
if (LOG.isDebugEnabled()) {
LOG.debug(e);
}
throw new AuthenticationException(AuthenticationException.UNNOWN_EXCEPTION, e.getMessage(), e);
}
}
use of org.exist.security.internal.aider.UserAider in project exist by eXist-db.
the class RpcConnection method updateAccount.
@Override
public boolean updateAccount(final String name, String passwd, final String passwdDigest, final List<String> groups, final Boolean enabled, final Integer umask, final Map<String, String> metadata) throws EXistException, PermissionDeniedException {
if (passwd.length() == 0) {
passwd = null;
}
final UserAider account = new UserAider(name);
account.setEncodedPassword(passwd);
account.setPasswordDigest(passwdDigest);
for (final String g : groups) {
account.addGroup(g);
}
if (enabled != null) {
account.setEnabled(enabled);
}
if (umask != null) {
account.setUserMask(umask);
}
if (metadata != null) {
for (final Map.Entry<String, String> m : metadata.entrySet()) {
if (AXSchemaType.valueOfNamespace(m.getKey()) != null) {
account.setMetadataValue(AXSchemaType.valueOfNamespace(m.getKey()), m.getValue());
} else if (EXistSchemaType.valueOfNamespace(m.getKey()) != null) {
account.setMetadataValue(EXistSchemaType.valueOfNamespace(m.getKey()), m.getValue());
}
}
}
final SecurityManager manager = factory.getBrokerPool().getSecurityManager();
withDb((broker, transaction) -> manager.updateAccount(account));
return true;
}
use of org.exist.security.internal.aider.UserAider in project exist by eXist-db.
the class RemoteUserManagementService method getAccounts.
@Override
public Account[] getAccounts() throws XMLDBException {
final Object[] users = (Object[]) collection.execute("getAccounts", Collections.EMPTY_LIST);
final UserAider[] u = new UserAider[users.length];
for (int i = 0; i < u.length; i++) {
final Map tab = (Map) users[i];
int uid = -1;
try {
uid = (Integer) tab.get("uid");
} catch (final NumberFormatException e) {
}
u[i] = new UserAider(uid, (String) tab.get("realmId"), (String) tab.get("name"));
final Object[] groups = (Object[]) tab.get("groups");
for (Object group : groups) {
u[i].addGroup((String) group);
}
u[i].setEnabled(Boolean.parseBoolean((String) tab.get("enabled")));
u[i].setUserMask((Integer) tab.get("umask"));
final Map<String, String> metadata = (Map<String, String>) tab.get("metadata");
for (final Map.Entry<String, String> m : metadata.entrySet()) {
if (AXSchemaType.valueOfNamespace(m.getKey()) != null) {
u[i].setMetadataValue(AXSchemaType.valueOfNamespace(m.getKey()), m.getValue());
} else if (EXistSchemaType.valueOfNamespace(m.getKey()) != null) {
u[i].setMetadataValue(EXistSchemaType.valueOfNamespace(m.getKey()), m.getValue());
}
}
}
return u;
}
use of org.exist.security.internal.aider.UserAider in project exist by eXist-db.
the class RemoteUserManagementService method lockResource.
@Override
public void lockResource(final Resource res, final User u) throws XMLDBException {
final Account account = new UserAider(u.getName());
lockResource(res, account);
}
Aggregations