use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class BackupRestoreSecurityPrincipalsTest method createUser.
private void createUser(final String username, final String password) throws XMLDBException, PermissionDeniedException {
final UserManagementService ums = (UserManagementService) server.getRoot().getService("UserManagementService", "1.0");
final Account user = new UserAider(username);
user.setPassword(password);
// create the personal group
final Group group = new GroupAider(username);
group.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + username);
group.addManager(ums.getAccount("admin"));
ums.addGroup(group);
// add the personal group as the primary group
user.addGroup(username);
// create the account
ums.addAccount(user);
// add the new account as a manager of their personal group
ums.addGroupManager(username, group.getName());
}
use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class PermissionsFunctionChmodTest method prepareDb.
@BeforeClass
public static void prepareDb() throws EXistException, PermissionDeniedException, IOException, TriggerException {
final BrokerPool pool = existWebServer.getBrokerPool();
final SecurityManager sm = pool.getSecurityManager();
try (final DBBroker broker = pool.get(Optional.of(sm.getSystemSubject()));
final Txn transaction = pool.getTransactionManager().beginTransaction()) {
final Collection collection = broker.getOrCreateCollection(transaction, TestConstants.TEST_COLLECTION_URI);
PermissionFactory.chmod(broker, collection, Optional.of(511), Optional.empty());
broker.saveCollection(transaction, collection);
createUser(broker, sm, USER1_NAME, USER1_PWD);
createUser(broker, sm, USER2_NAME, USER2_PWD);
final Group otherGroup = new GroupAider(OTHER_GROUP_NAME);
sm.addGroup(broker, otherGroup);
final Account user1 = sm.getAccount(USER1_NAME);
user1.addGroup(OTHER_GROUP_NAME);
sm.updateAccount(user1);
final Account user2 = sm.getAccount(USER2_NAME);
user2.addGroup(OTHER_GROUP_NAME);
sm.updateAccount(user2);
transaction.commit();
}
}
use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class RemoteUserManagementService method getAccount.
@Override
public Account getAccount(final String name) throws XMLDBException {
try {
final List<Object> params = new ArrayList<>();
params.add(name);
final Map tab = (Map) collection.execute("getAccount", params);
if (tab == null || tab.isEmpty()) {
return null;
}
final UserAider u;
if (tab.get("default-group-id") != null) {
final GroupAider defaultGroup = new GroupAider((Integer) tab.get("default-group-id"), (String) tab.get("default-group-realmId"), (String) tab.get("default-group-name"));
u = new UserAider((String) tab.get("realmId"), (String) tab.get("name"), defaultGroup);
} else {
u = new UserAider((String) tab.get("realmId"), (String) tab.get("name"));
}
final Object[] groups = (Object[]) tab.get("groups");
for (final Object group : groups) {
u.addGroup((String) group);
}
u.setEnabled(Boolean.parseBoolean((String) tab.get("enabled")));
u.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.setMetadataValue(AXSchemaType.valueOfNamespace(m.getKey()), m.getValue());
} else if (EXistSchemaType.valueOfNamespace(m.getKey()) != null) {
u.setMetadataValue(EXistSchemaType.valueOfNamespace(m.getKey()), m.getValue());
}
}
return u;
} catch (final XMLDBException e) {
return null;
}
}
Aggregations