use of org.exist.security.Group in project exist by eXist-db.
the class UserManagerDialog method miEditGroupActionPerformed.
// GEN-LAST:event_tblUsersMouseClicked
private void miEditGroupActionPerformed(java.awt.event.ActionEvent evt) {
// GEN-FIRST:event_miEditGroupActionPerformed
final String selectedGroup = getSelectedGroup();
try {
final Group group = userManagementService.getGroup(selectedGroup);
showEditGroupDialog(group);
} catch (final XMLDBException xmldbe) {
JOptionPane.showMessageDialog(this, "Could not edit group '" + selectedGroup + "': " + xmldbe.getMessage(), "User Manager Error", JOptionPane.ERROR_MESSAGE);
}
}
use of org.exist.security.Group in project exist by eXist-db.
the class RemoveGroupTask method execute.
/* (non-Javadoc)
* @see org.apache.tools.ant.Task#execute()
*/
public void execute() throws BuildException {
super.execute();
if (name == null) {
throw (new BuildException("You have to specify a name"));
}
log("Removing group " + name, Project.MSG_INFO);
try {
final Group group = service.getGroup(name);
if (group != null) {
service.removeGroup(group);
} else {
log("Group " + name + " does not exist.", Project.MSG_INFO);
}
} 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.Group 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.Group in project exist by eXist-db.
the class LDAPRealm method getGroup.
public final synchronized Group getGroup(final Subject invokingUser, final DBBroker broker, String name) {
name = ensureCase(name);
final Group grp = getGroup(name);
if (grp != null) {
return grp;
} else {
// if the group is not cached, we should try and find it in LDAP and cache it if it exists
LdapContext ctx = null;
try {
ctx = getContext(invokingUser);
return getGroup(ctx, broker, name);
} catch (final NamingException ne) {
LOG.error(new AuthenticationException(AuthenticationException.UNNOWN_EXCEPTION, ne.getMessage()));
return null;
} finally {
if (ctx != null) {
LdapUtils.closeContext(ctx);
}
}
}
}
use of org.exist.security.Group in project exist by eXist-db.
the class RpcConnection method addGroupManager.
@Override
public void addGroupManager(final String manager, final String groupName) throws EXistException, PermissionDeniedException {
withDb((broker, transaction) -> {
final SecurityManager sm = broker.getBrokerPool().getSecurityManager();
final Account account = sm.getAccount(manager);
final Group group = sm.getGroup(groupName);
group.addManager(account);
sm.updateGroup(group);
return null;
});
}
Aggregations