Search in sources :

Example 96 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class XmldbApiSecurityTest method removeAccount.

@Override
protected void removeAccount(final String account_uid, final String uid, final String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + "/db", uid, pwd);
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        final Account acct = ums.getAccount(account_uid);
        if (acct != null) {
            ums.removeAccount(acct);
        }
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 97 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class XmldbApiSecurityTest method chmodRes.

@Override
protected void chmodRes(final String resourceUri, final String mode, final String uid, final String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + getCollectionUri(resourceUri), uid, pwd);
        final Resource resource = col.getResource(getResourceName(resourceUri));
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        ums.chmod(resource, mode);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : BinaryResource(org.xmldb.api.modules.BinaryResource) XMLResource(org.xmldb.api.modules.XMLResource) Resource(org.xmldb.api.base.Resource) Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 98 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class XmldbApiSecurityTest method removeGroup.

@Override
protected void removeGroup(String group_uid, String uid, String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + "/db", uid, pwd);
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        final Group grp = ums.getGroup(group_uid);
        if (grp != null) {
            ums.removeGroup(grp);
        }
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Example 99 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class BackupRestoreSecurityPrincipalsTest method createUser.

private void createUser(final String username, final String password) throws XMLDBException, PermissionDeniedException {
    final UserManagementService ums = (UserManagementService) server.getRoot().getService("UserManagementService", "1.0");
    final Account user = new UserAider(username);
    user.setPassword(password);
    // create the personal group
    final Group group = new GroupAider(username);
    group.setMetadataValue(EXistSchemaType.DESCRIPTION, "Personal group for " + username);
    group.addManager(ums.getAccount("admin"));
    ums.addGroup(group);
    // add the personal group as the primary group
    user.addGroup(username);
    // create the account
    ums.addAccount(user);
    // add the new account as a manager of their personal group
    ums.addGroupManager(username, group.getName());
}
Also used : UserManagementService(org.exist.xmldb.UserManagementService) UserAider(org.exist.security.internal.aider.UserAider) GroupAider(org.exist.security.internal.aider.GroupAider)

Example 100 with UserManagementService

use of org.exist.xmldb.UserManagementService in project exist by eXist-db.

the class XmldbApiSecurityTest method chownCol.

@Override
protected void chownCol(final String collectionUri, final String owner_uid, final String group_gid, final String uid, final String pwd) throws ApiException {
    Collection col = null;
    try {
        col = DatabaseManager.getCollection(getBaseUri() + collectionUri, uid, pwd);
        final UserManagementService ums = (UserManagementService) col.getService("UserManagementService", "1.0");
        ums.chown(ums.getAccount(owner_uid), group_gid);
    } catch (final XMLDBException xmldbe) {
        throw new ApiException(xmldbe);
    } finally {
        if (col != null) {
            try {
                col.close();
            } catch (final XMLDBException xmldbe) {
                throw new ApiException(xmldbe);
            }
        }
    }
}
Also used : Collection(org.xmldb.api.base.Collection) XMLDBException(org.xmldb.api.base.XMLDBException) UserManagementService(org.exist.xmldb.UserManagementService)

Aggregations

UserManagementService (org.exist.xmldb.UserManagementService)106 Collection (org.xmldb.api.base.Collection)91 Test (org.junit.Test)79 BinaryResource (org.xmldb.api.modules.BinaryResource)55 Resource (org.xmldb.api.base.Resource)52 XMLResource (org.xmldb.api.modules.XMLResource)51 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)26 XMLDBException (org.xmldb.api.base.XMLDBException)15 CollectionManagementService (org.xmldb.api.modules.CollectionManagementService)14 UserAider (org.exist.security.internal.aider.UserAider)9 GroupAider (org.exist.security.internal.aider.GroupAider)8 ResourceSet (org.xmldb.api.base.ResourceSet)8 EXistXPathQueryService (org.exist.xmldb.EXistXPathQueryService)7 EXistResource (org.exist.xmldb.EXistResource)6 Account (org.exist.security.Account)5 Before (org.junit.Before)3 BeforeClass (org.junit.BeforeClass)3 URISyntaxException (java.net.URISyntaxException)2 ExtendedResource (org.exist.xmldb.ExtendedResource)2 WindowAdapter (java.awt.event.WindowAdapter)1