use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class AddGroupTask method execute.
/* (non-Javadoc)
* @see org.apache.tools.ant.Task#execute()
*/
public void execute() throws BuildException {
super.execute();
if (name == null) {
throw (new BuildException("Must specify a group name"));
}
try {
final GroupAider group = new GroupAider(name);
log("Adding group " + name, Project.MSG_INFO);
service.addGroup(group);
} catch (final XMLDBException e) {
final String msg = "XMLDB exception caught: " + e.getMessage();
if (failonerror) {
throw (new BuildException(msg, e));
} else {
log(msg, e, Project.MSG_ERR);
}
}
}
use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class SecurityManagerTest method setup.
@BeforeClass
public static void setup() throws EXistException, PermissionDeniedException {
final BrokerPool brokerPool = existEmbeddedServer.getBrokerPool();
final SecurityManager securityManager = brokerPool.getSecurityManager();
// create the personal group
final Group group = new GroupAider(TEST_GROUP_NAME);
group.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + TEST_GROUP_NAME);
try (final DBBroker broker = brokerPool.get(Optional.of(securityManager.getSystemSubject()))) {
securityManager.addGroup(broker, group);
// create the account
final Account user = new UserAider(TEST_USER_NAME);
user.setPassword(TEST_USER_NAME);
user.addGroup(TEST_GROUP_NAME);
securityManager.addAccount(user);
// add the new account as a manager of their personal group
final Group personalGroup = securityManager.getGroup(TEST_GROUP_NAME);
personalGroup.addManager(securityManager.getAccount(TEST_USER_NAME));
securityManager.updateGroup(personalGroup);
}
}
use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class FnCollectionSecurityTest method createUser.
private static void createUser(final SecurityManager securityManager, final DBBroker broker, final String username) throws PermissionDeniedException, EXistException {
final UserAider user = new UserAider(username);
user.setPassword(username);
Group group = new GroupAider(username);
group.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + username);
group.addManager(user);
securityManager.addGroup(broker, group);
// add the personal group as the primary group
user.addGroup(username);
securityManager.addAccount(user);
// add the new account as a manager of their personal group
group = securityManager.getGroup(username);
group.addManager(securityManager.getAccount(username));
securityManager.updateGroup(group);
}
use of org.exist.security.internal.aider.GroupAider 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.security.internal.aider.GroupAider 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);
}
}
}
Aggregations