Search in sources :

Example 6 with SchemaType

use of org.exist.security.SchemaType in project exist by eXist-db.

the class GetPrincipalMetadataFunction method getPrincipalMetadataKeys.

private Sequence getPrincipalMetadataKeys(final Principal principal) throws XPathException {
    final Set<SchemaType> metadataKeys = principal.getMetadataKeys();
    final Sequence seq = new ValueSequence(metadataKeys.size());
    for (final SchemaType schemaType : metadataKeys) {
        seq.add(new AnyURIValue(schemaType.getNamespace()));
    }
    return seq;
}
Also used : AnyURIValue(org.exist.xquery.value.AnyURIValue) ValueSequence(org.exist.xquery.value.ValueSequence) ValueSequence(org.exist.xquery.value.ValueSequence) Sequence(org.exist.xquery.value.Sequence) AXSchemaType(org.exist.security.AXSchemaType) EXistSchemaType(org.exist.security.EXistSchemaType) SchemaType(org.exist.security.SchemaType)

Example 7 with SchemaType

use of org.exist.security.SchemaType in project exist by eXist-db.

the class SecurityManagerImpl method addGroup.

@Override
public Group addGroup(final DBBroker broker, final Group group) throws PermissionDeniedException, EXistException {
    if (group.getRealmId() == null) {
        throw new ConfigurationException("Group must have realm id.");
    }
    if (group.getName() == null || group.getName().isEmpty()) {
        throw new ConfigurationException("Group must have name.");
    }
    final int id;
    if (group.getId() != Group.UNDEFINED_ID) {
        id = group.getId();
    } else {
        id = groupsById.getNextPrincipalId();
    }
    final AbstractRealm registeredRealm = (AbstractRealm) findRealmForRealmId(group.getRealmId());
    if (registeredRealm.hasGroupLocal(group.getName())) {
        throw new ConfigurationException("The group '" + group.getName() + "' at realm '" + group.getRealmId() + "' already exists.");
    }
    final GroupImpl newGroup = new GroupImpl(broker, registeredRealm, id, group.getName(), group.getManagers());
    for (final SchemaType metadataKey : group.getMetadataKeys()) {
        final String metadataValue = group.getMetadataValue(metadataKey);
        newGroup.setMetadataValue(metadataKey, metadataValue);
    }
    try (final ManagedLock<ReadWriteLock> lock = ManagedLock.acquire(groupLocks.getLock(newGroup), LockMode.WRITE_LOCK)) {
        registerGroup(newGroup);
        registeredRealm.registerGroup(newGroup);
        newGroup.save(broker);
        return newGroup;
    }
}
Also used : ConfigurationException(org.exist.config.ConfigurationException) ReadWriteLock(java.util.concurrent.locks.ReadWriteLock) ReentrantReadWriteLock(java.util.concurrent.locks.ReentrantReadWriteLock) SchemaType(org.exist.security.SchemaType) AbstractRealm(org.exist.security.AbstractRealm)

Example 8 with SchemaType

use of org.exist.security.SchemaType in project exist by eXist-db.

the class AccountImpl method instantiate.

private void instantiate(final Account from_user) throws PermissionDeniedException {
    // copy metadata
    for (final SchemaType metadataKey : from_user.getMetadataKeys()) {
        final String metadataValue = from_user.getMetadataValue(metadataKey);
        setMetadataValue(metadataKey, metadataValue);
    }
    // copy umask
    setUserMask(from_user.getUserMask());
    if (from_user instanceof AccountImpl) {
        final AccountImpl user = (AccountImpl) from_user;
        groups = new ArrayList<>(user.groups);
        password = user.password;
        digestPassword = user.digestPassword;
        hasDbaRole = user.hasDbaRole;
        _cred = user._cred;
    } else if (from_user instanceof UserAider) {
        final UserAider user = (UserAider) from_user;
        final String[] groups = user.getGroups();
        for (final String group : groups) {
            addGroup(group);
        }
        setPassword(user.getPassword());
        digestPassword = user.getDigestPassword();
    } else {
        addGroup(from_user.getDefaultGroup());
    // TODO: groups
    }
}
Also used : UserAider(org.exist.security.internal.aider.UserAider) SchemaType(org.exist.security.SchemaType)

Example 9 with SchemaType

use of org.exist.security.SchemaType in project exist by eXist-db.

the class RemoteUserManagementService method updateGroup.

@Override
public void updateGroup(final Group group) throws XMLDBException {
    try {
        final List<Object> params = new ArrayList<>();
        params.add(group.getName());
        final String[] managers = new String[group.getManagers().size()];
        for (int i = 0; i < managers.length; i++) {
            managers[i] = group.getManagers().get(i).getName();
        }
        params.add(managers);
        final Map<String, String> metadata = new HashMap<>();
        for (final SchemaType key : group.getMetadataKeys()) {
            metadata.put(key.getNamespace(), group.getMetadataValue(key));
        }
        params.add(metadata);
        collection.execute("updateGroup", params);
    } catch (final PermissionDeniedException pde) {
        throw new XMLDBException(ErrorCodes.PERMISSION_DENIED, pde.getMessage(), pde);
    }
}
Also used : XMLDBException(org.xmldb.api.base.XMLDBException) PermissionDeniedException(org.exist.security.PermissionDeniedException) AXSchemaType(org.exist.security.AXSchemaType) EXistSchemaType(org.exist.security.EXistSchemaType) SchemaType(org.exist.security.SchemaType)

Example 10 with SchemaType

use of org.exist.security.SchemaType in project exist by eXist-db.

the class RemoteUserManagementService method addAccount.

@Override
public void addAccount(final Account user) throws XMLDBException {
    final List<Object> params = new ArrayList<>();
    params.add(user.getName());
    params.add(user.getPassword() == null ? "" : user.getPassword());
    params.add(user.getDigestPassword() == null ? "" : user.getDigestPassword());
    final String[] gl = user.getGroups();
    params.add(gl);
    params.add(user.isEnabled());
    params.add(user.getUserMask());
    final Map<String, String> metadata = new HashMap<>();
    for (final SchemaType key : user.getMetadataKeys()) {
        metadata.put(key.getNamespace(), user.getMetadataValue(key));
    }
    params.add(metadata);
    collection.execute("addAccount", params);
}
Also used : AXSchemaType(org.exist.security.AXSchemaType) EXistSchemaType(org.exist.security.EXistSchemaType) SchemaType(org.exist.security.SchemaType)

Aggregations

SchemaType (org.exist.security.SchemaType)10 AXSchemaType (org.exist.security.AXSchemaType)8 EXistSchemaType (org.exist.security.EXistSchemaType)7 Group (org.exist.security.Group)3 PermissionDeniedException (org.exist.security.PermissionDeniedException)2 Field (java.lang.reflect.Field)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)1 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)1 NamingException (javax.naming.NamingException)1 SearchResult (javax.naming.directory.SearchResult)1 LdapContext (javax.naming.ldap.LdapContext)1 EXistException (org.exist.EXistException)1 ConfigurationException (org.exist.config.ConfigurationException)1 AbstractRealm (org.exist.security.AbstractRealm)1 Account (org.exist.security.Account)1 AuthenticationException (org.exist.security.AuthenticationException)1 SecurityManager (org.exist.security.SecurityManager)1 Subject (org.exist.security.Subject)1 UserAider (org.exist.security.internal.aider.UserAider)1