Search in sources :

Example 21 with UserAider

use of org.exist.security.internal.aider.UserAider 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);
}
Also used : UserAider(org.exist.security.internal.aider.UserAider) GroupAider(org.exist.security.internal.aider.GroupAider)

Example 22 with UserAider

use of org.exist.security.internal.aider.UserAider 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 23 with UserAider

use of org.exist.security.internal.aider.UserAider in project exist by eXist-db.

the class XmldbApiSecurityTest method createAccount.

@Override
protected void createAccount(String account_uid, String account_pwd, 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 group = ums.getGroup(group_uid);
        final Account user = new UserAider(account_uid, group);
        user.setPassword(account_pwd);
        ums.addAccount(user);
    } 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) UserAider(org.exist.security.internal.aider.UserAider)

Example 24 with UserAider

use of org.exist.security.internal.aider.UserAider in project exist by eXist-db.

the class RealmImpl method createAdminAndGuestIfNotExist.

private void createAdminAndGuestIfNotExist(final DBBroker broker) throws EXistException, PermissionDeniedException {
    // Admin account
    if (getSecurityManager().getAccount(ADMIN_ACCOUNT_ID) == null) {
        final UserAider actAdmin = new UserAider(ADMIN_ACCOUNT_ID, getId(), SecurityManager.DBA_USER);
        actAdmin.setPassword(DEFAULT_ADMIN_PASSWORD);
        actAdmin.setMetadataValue(AXSchemaType.FULLNAME, SecurityManager.DBA_USER);
        actAdmin.setMetadataValue(EXistSchemaType.DESCRIPTION, "System Administrator");
        actAdmin.addGroup(SecurityManager.DBA_GROUP);
        getSecurityManager().addAccount(broker, actAdmin);
    }
    // Guest account
    if (getSecurityManager().getAccount(GUEST_ACCOUNT_ID) == null) {
        final UserAider actGuest = new UserAider(GUEST_ACCOUNT_ID, getId(), SecurityManager.GUEST_USER);
        actGuest.setMetadataValue(AXSchemaType.FULLNAME, SecurityManager.GUEST_USER);
        actGuest.setMetadataValue(EXistSchemaType.DESCRIPTION, "Anonymous User");
        actGuest.setPassword(DEFAULT_GUEST_PASSWORD);
        actGuest.addGroup(SecurityManager.GUEST_GROUP);
        getSecurityManager().addAccount(broker, actGuest);
    }
}
Also used : UserAider(org.exist.security.internal.aider.UserAider)

Example 25 with UserAider

use of org.exist.security.internal.aider.UserAider 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)

Aggregations

UserAider (org.exist.security.internal.aider.UserAider)28 GroupAider (org.exist.security.internal.aider.GroupAider)15 UserManagementService (org.exist.xmldb.UserManagementService)9 Account (org.exist.security.Account)5 XMLDBException (org.xmldb.api.base.XMLDBException)5 EXistException (org.exist.EXistException)4 PermissionDeniedException (org.exist.security.PermissionDeniedException)4 SecurityManager (org.exist.security.SecurityManager)4 DBBroker (org.exist.storage.DBBroker)4 Test (org.junit.Test)4 Collection (org.xmldb.api.base.Collection)4 IOException (java.io.IOException)2 NamingException (javax.naming.NamingException)2 AbstractAccount (org.exist.security.AbstractAccount)2 AuthenticationException (org.exist.security.AuthenticationException)2 LockedDocumentMap (org.exist.storage.lock.LockedDocumentMap)2 EXistCollectionManagementService (org.exist.xmldb.EXistCollectionManagementService)2 Before (org.junit.Before)2 BinaryResource (org.xmldb.api.modules.BinaryResource)2 Either (com.evolvedbinary.j8fu.Either)1