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);
}
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());
}
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);
}
}
}
}
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);
}
}
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
}
}
Aggregations