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