use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class UserDialog method createUser.
// GEN-LAST:event_btnCreateActionPerformed
protected void createUser() {
// 0 - determine the primary group
final GroupAider primaryGroup;
if (getPrimaryGroup() == null) {
if (cbPersonalGroup.isSelected()) {
primaryGroup = new GroupAider(txtUsername.getText());
} else {
final String firstGroup = memberOfGroupsModel.firstElement();
if (firstGroup != null) {
primaryGroup = new GroupAider(firstGroup);
} else {
JOptionPane.showMessageDialog(this, "Could not determine primary group for user '" + txtUsername.getText() + "'. User must create personal group or belong to at least one existing group", "Create User Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
} else {
primaryGroup = new GroupAider(getPrimaryGroup());
}
// 1 - create personal group
GroupAider groupAider = null;
if (cbPersonalGroup.isSelected()) {
groupAider = new GroupAider(txtUsername.getText());
groupAider.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + txtUsername.getText());
try {
getUserManagementService().addGroup(groupAider);
} catch (final XMLDBException xmldbe) {
JOptionPane.showMessageDialog(this, "Could not create personal group '" + txtUsername.getText() + "': " + xmldbe.getMessage(), "Create User Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
// 2 - create the user
final UserAider userAider = new UserAider(txtUsername.getText());
userAider.setMetadataValue(AXSchemaType.FULLNAME, txtFullName.getText());
userAider.setMetadataValue(EXistSchemaType.DESCRIPTION, txtDescription.getText());
userAider.setPassword(txtPassword.getText());
userAider.setEnabled(!cbDisabled.isSelected());
userAider.setUserMask(UmaskSpinnerModel.octalUmaskToInt((String) spnUmask.getValue()));
// add the personal group to the user
if (cbPersonalGroup.isSelected()) {
userAider.addGroup(txtUsername.getText());
}
// add any other groups to the user
final Iterator<String> itMemberOfGroups = memberOfGroupsModel.iterator();
while (itMemberOfGroups.hasNext()) {
final String memberOfGroup = itMemberOfGroups.next();
userAider.addGroup(memberOfGroup);
}
// set the primary group
try {
userAider.setPrimaryGroup(primaryGroup);
} catch (final PermissionDeniedException pde) {
JOptionPane.showMessageDialog(this, "Could not set primary group '" + getPrimaryGroup() + "' of user '" + txtUsername.getText() + "': " + pde.getMessage(), "Create User Error", JOptionPane.ERROR_MESSAGE);
return;
}
try {
getUserManagementService().addAccount(userAider);
} catch (final XMLDBException xmldbe) {
JOptionPane.showMessageDialog(this, "Could not create user '" + txtUsername.getText() + "': " + xmldbe.getMessage(), "Create User Error", JOptionPane.ERROR_MESSAGE);
return;
}
// 3 - if created personal group, then add us as the manager
if (cbPersonalGroup.isSelected()) {
try {
groupAider.addManager(userAider);
getUserManagementService().updateGroup(groupAider);
} catch (final XMLDBException | PermissionDeniedException xmldbe) {
JOptionPane.showMessageDialog(this, "Could not set user '" + txtUsername.getText() + "' as manager of personal group '" + txtUsername.getText() + "': " + xmldbe.getMessage(), "Create User Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
}
use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class GroupDialog method createGroup.
// GEN-LAST:event_btnCreateActionPerformed
protected void createGroup() {
// 1 - create the group
Group group = null;
try {
final GroupAider groupAider = new GroupAider(txtGroupName.getText());
groupAider.setMetadataValue(EXistSchemaType.DESCRIPTION, txtDescription.getText());
getUserManagementService().addGroup(groupAider);
// get the created group
group = getUserManagementService().getGroup(txtGroupName.getText());
} catch (final XMLDBException xmldbe) {
JOptionPane.showMessageDialog(this, "Could not create group '" + txtGroupName.getText() + "': " + xmldbe.getMessage(), "Create Group Error", JOptionPane.ERROR_MESSAGE);
return;
}
// 2 - add the users to the group and set managers
for (int i = 0; i < getGroupMembersTableModel().getRowCount(); i++) {
final String member = (String) getGroupMembersTableModel().getValueAt(i, 0);
try {
getUserManagementService().addAccountToGroup(member, group.getName());
final boolean isManager = (Boolean) getGroupMembersTableModel().getValueAt(i, 1);
if (isManager) {
getUserManagementService().addGroupManager(member, group.getName());
}
} catch (final XMLDBException xmldbe) {
JOptionPane.showMessageDialog(this, "Could not add user '" + member + "' to group '" + group.getName() + "': " + xmldbe.getMessage(), "Create Group Error", JOptionPane.ERROR_MESSAGE);
return;
}
}
setVisible(false);
dispose();
}
use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class AbstractSecurityManagerRoundtripTest method checkGroupManagerStability.
@Test
public void checkGroupManagerStability() throws XMLDBException, PermissionDeniedException, IOException {
UserManagementService ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
final String commonGroupName = "commonGroup";
Group commonGroup = new GroupAider(commonGroupName);
final String userName = "testUserA";
final Group userGroup = new GroupAider(userName);
// set users primary group as personal group
final Account userAccount = new UserAider(userName, userGroup);
try {
// create a user with personal group
ums.addGroup(userGroup);
ums.addAccount(userAccount);
// add user1 as a manager of common group
ums.addGroup(commonGroup);
commonGroup.addManager(userAccount);
ums.updateGroup(commonGroup);
/**
* RESTART THE SERVER **
*/
restartServer();
/**
***********************
*/
ums = (UserManagementService) getRoot().getService("UserManagementService", "1.0");
// get the common group
commonGroup = ums.getGroup(commonGroupName);
assertNotNull(commonGroup);
// assert that user1 is still a manager of the common group
final List<Account> commonGroupManagers = commonGroup.getManagers();
assertNotNull(commonGroupManagers);
assertEquals(1, commonGroupManagers.size());
assertEquals(commonGroupManagers.get(0).getName(), userName);
} finally {
// cleanup
try {
ums.removeGroup(commonGroup);
} catch (Exception e) {
}
try {
ums.removeAccount(userAccount);
} catch (Exception e) {
}
try {
ums.removeGroup(userGroup);
} catch (Exception e) {
}
}
}
use of org.exist.security.internal.aider.GroupAider in project exist by eXist-db.
the class AbstractSecurityManagerRoundtripTest method checkPrimaryGroupRemainsDBA.
@Test
public void checkPrimaryGroupRemainsDBA() 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);
// set users primary group as DBA
Account user = new UserAider(userName, ums.getGroup(SecurityManager.DBA_GROUP));
try {
ums.addGroup(group1);
ums.addGroup(group2);
ums.addAccount(user);
ums.getAccount(userName);
user.addGroup(group1);
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(SecurityManager.DBA_GROUP, defaultGroup.getName());
String[] groups = user.getGroups();
assertNotNull(groups);
assertEquals(3, groups.length);
assertEquals(SecurityManager.DBA_GROUP, groups[0]);
assertEquals(group1Name, groups[1]);
assertEquals(group2Name, groups[2]);
} 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 FnDocSecurityTest 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);
}
Aggregations