Search in sources :

Example 1 with Group

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);
    }
}
Also used : Group(org.exist.security.Group) XMLDBException(org.xmldb.api.base.XMLDBException)

Example 2 with Group

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);
        }
    }
}
Also used : Group(org.exist.security.Group) XMLDBException(org.xmldb.api.base.XMLDBException) BuildException(org.apache.tools.ant.BuildException)

Example 3 with Group

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);
    }
}
Also used : Group(org.exist.security.Group) Account(org.exist.security.Account) AbstractAccount(org.exist.security.AbstractAccount) AuthenticationException(org.exist.security.AuthenticationException) UserAider(org.exist.security.internal.aider.UserAider) NamingException(javax.naming.NamingException) PermissionDeniedException(org.exist.security.PermissionDeniedException) EXistException(org.exist.EXistException) AuthenticationException(org.exist.security.AuthenticationException) AXSchemaType(org.exist.security.AXSchemaType)

Example 4 with Group

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);
            }
        }
    }
}
Also used : Group(org.exist.security.Group) AuthenticationException(org.exist.security.AuthenticationException) NamingException(javax.naming.NamingException) LdapContext(javax.naming.ldap.LdapContext)

Example 5 with Group

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;
    });
}
Also used : Account(org.exist.security.Account) Group(org.exist.security.Group) SecurityManager(org.exist.security.SecurityManager)

Aggregations

Group (org.exist.security.Group)23 Account (org.exist.security.Account)9 PermissionDeniedException (org.exist.security.PermissionDeniedException)9 AuthenticationException (org.exist.security.AuthenticationException)6 SecurityManager (org.exist.security.SecurityManager)6 XMLDBException (org.xmldb.api.base.XMLDBException)6 EXistException (org.exist.EXistException)5 NamingException (javax.naming.NamingException)4 AXSchemaType (org.exist.security.AXSchemaType)4 SchemaType (org.exist.security.SchemaType)4 GroupAider (org.exist.security.internal.aider.GroupAider)4 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 SearchResult (javax.naming.directory.SearchResult)2 LdapContext (javax.naming.ldap.LdapContext)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 ConfigurationException (org.exist.config.ConfigurationException)2 AbstractAccount (org.exist.security.AbstractAccount)2 Permission (org.exist.security.Permission)2 Subject (org.exist.security.Subject)2