use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class AbstractSecurityManagerRoundtripTest method checkGroupMembership.
@Test
public void checkGroupMembership() throws XMLDBException, PermissionDeniedException, EXistException, IOException, DatabaseConfigurationException {
UserManagementService ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
final String group1Name = "testGroup1";
final String group2Name = "testGroup2";
final String userName = "testUser";
Group group1 = new GroupAider(group1Name);
Group group2 = new GroupAider(group2Name);
Account user = new UserAider(userName, group1);
try {
ums.addGroup(group1);
ums.addGroup(group2);
ums.addAccount(user);
ums.getAccount(userName);
user.addGroup(group2);
ums.updateAccount(user);
/**
* RESTART THE SERVER **
*/
restartServer();
/**
***********************
*/
ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
user = ums.getAccount(userName);
assertNotNull(user);
Group defaultGroup = user.getDefaultGroup();
assertNotNull(defaultGroup);
assertEquals(group1Name, defaultGroup.getName());
String[] groups = user.getGroups();
assertNotNull(groups);
assertEquals(2, groups.length);
assertEquals(group1Name, groups[0]);
assertEquals(group2Name, groups[1]);
} finally {
// cleanup
final Account u1 = ums.getAccount(userName);
if (u1 != null) {
ums.removeAccount(u1);
}
final Group g1 = ums.getGroup(group1Name);
if (g1 != null) {
ums.removeGroup(g1);
}
final Group g2 = ums.getGroup(group2Name);
if (g2 != null) {
ums.removeGroup(g2);
}
}
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class AbstractSecurityManagerRoundtripTest method checkPrimaryGroupStability.
@Test
public void checkPrimaryGroupStability() throws XMLDBException, PermissionDeniedException, EXistException, IOException, DatabaseConfigurationException {
UserManagementService ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
final String group1Name = "testGroupA";
final String group2Name = "testGroupB";
final String userName = "testUserA";
Group group1 = new GroupAider(group1Name);
Group group2 = new GroupAider(group2Name);
// set users primary group as group1
Account user = new UserAider(userName, group1);
try {
ums.addGroup(group1);
ums.addGroup(group2);
ums.addAccount(user);
ums.getAccount(userName);
user.addGroup(group2Name);
ums.updateAccount(user);
/**
* RESTART THE SERVER **
*/
restartServer();
/**
***********************
*/
ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
user = ums.getAccount(userName);
assertNotNull(user);
Group defaultGroup = user.getDefaultGroup();
assertNotNull(defaultGroup);
assertEquals(group1Name, defaultGroup.getName());
String[] groups = user.getGroups();
assertNotNull(groups);
assertEquals(2, groups.length);
assertEquals(group1Name, groups[0]);
assertEquals(group2Name, groups[1]);
} finally {
// cleanup
final Account u1 = ums.getAccount(userName);
if (u1 != null) {
ums.removeAccount(u1);
}
final Group g1 = ums.getGroup(group1Name);
if (g1 != null) {
ums.removeGroup(g1);
}
final Group g2 = ums.getGroup(group2Name);
if (g2 != null) {
ums.removeGroup(g2);
}
}
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class GetParameterTest method beforeClass.
@BeforeClass
public static void beforeClass() throws XMLDBException {
root = DatabaseManager.getCollection("xmldb:exist://localhost:" + existWebServer.getPort() + "/xmlrpc/db", "admin", "");
BinaryResource res = (BinaryResource) root.createResource(XQUERY_FILENAME, "BinaryResource");
((EXistResource) res).setMimeType("application/xquery");
res.setContent(XQUERY);
root.storeResource(res);
UserManagementService ums = (UserManagementService) root.getService("UserManagementService", "1.0");
ums.chmod(res, 0777);
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XmldbApiSecurityTest method addCollectionUserAce.
@Override
protected void addCollectionUserAce(final String collectionUri, final String user_uid, final String mode, final boolean allow, final String uid, final String pwd) throws ApiException {
Collection parentCol = null;
Collection subCol = null;
try {
final String parentColUri = collectionUri.substring(0, collectionUri.lastIndexOf('/'));
final String subColName = collectionUri.substring(collectionUri.lastIndexOf('/') + 1);
parentCol = DatabaseManager.getCollection(getBaseUri() + parentColUri, uid, pwd);
final UserManagementService ums = (UserManagementService) parentCol.getService("UserManagementService", "1.0");
final Permission subColPermissions = ums.getSubCollectionPermissions(parentCol, subColName);
subCol = DatabaseManager.getCollection(getBaseUri() + collectionUri, uid, pwd);
final List<ACEAider> aces = new ArrayList<>();
final ACEAider ace = new ACEAider(allow ? ACLPermission.ACE_ACCESS_TYPE.ALLOWED : ACLPermission.ACE_ACCESS_TYPE.DENIED, ACLPermission.ACE_TARGET.USER, user_uid, SimpleACLPermission.aceSimpleSymbolicModeToInt(mode));
aces.add(ace);
ums.setPermissions(subCol, subColPermissions.getOwner().getName(), subColPermissions.getGroup().getName(), subColPermissions.getMode(), aces);
} catch (final XMLDBException | PermissionDeniedException e) {
throw new ApiException(e);
} finally {
if (subCol != null) {
try {
subCol.close();
} catch (final XMLDBException xmldbe) {
throw new ApiException(xmldbe);
}
}
if (parentCol != null) {
try {
parentCol.close();
} catch (final XMLDBException xmldbe) {
throw new ApiException(xmldbe);
}
}
}
}
use of org.exist.xmldb.UserManagementService in project exist by eXist-db.
the class XmldbApiSecurityTest method chownRes.
@Override
protected void chownRes(final String resourceUri, final String owner_uid, final String group_gid, final String uid, final String pwd) throws ApiException {
Collection col = null;
try {
col = DatabaseManager.getCollection(getBaseUri() + getCollectionUri(resourceUri), uid, pwd);
final Resource resource = col.getResource(getResourceName(resourceUri));
final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
ums.chown(resource, ums.getAccount(owner_uid), group_gid);
} catch (final XMLDBException xmldbe) {
throw new ApiException(xmldbe);
} finally {
if (col != null) {
try {
col.close();
} catch (final XMLDBException xmldbe) {
throw new ApiException(xmldbe);
}
}
}
}
Aggregations