use of org.exist.security.Principal in project exist by eXist-db.
the class GetPrincipalMetadataFunction method eval.
@Override
public Sequence eval(final Sequence[] args, final Sequence contextSequence) throws XPathException {
Sequence result = Sequence.EMPTY_SEQUENCE;
final DBBroker broker = getContext().getBroker();
final Subject currentUser = broker.getCurrentSubject();
if (args.length == 0) {
if (isCalledAs(qnGetAccountMetadataKeys.getLocalPart())) {
result = getAllAccountMetadataKeys();
} else if (isCalledAs(qnGetGroupMetadataKeys.getLocalPart())) {
result = getAllGroupMetadataKeys();
} else {
throw new XPathException("Unknown function");
}
} else {
final SecurityManager securityManager = broker.getBrokerPool().getSecurityManager();
final String strPrincipal = args[0].getStringValue();
final Principal principal;
if (isCalledAs(qnGetAccountMetadataKeys.getLocalPart()) || isCalledAs(qnGetAccountMetadata.getLocalPart())) {
if (!currentUser.hasDbaRole() && !currentUser.getUsername().equals(strPrincipal)) {
throw new XPathException("You must be a DBA to retrieve metadata about other users, otherwise you may only retrieve metadata about yourself.");
}
principal = securityManager.getAccount(strPrincipal);
} else if (isCalledAs(qnGetGroupMetadataKeys.getLocalPart()) || isCalledAs(qnGetGroupMetadata.getLocalPart())) {
if (!currentUser.hasDbaRole() && !currentUser.hasGroup(strPrincipal)) {
throw new XPathException("You must be a DBA to retrieve metadata about other groups, otherwise you may only retrieve metadata about groups you are a member of.");
}
principal = securityManager.getGroup(strPrincipal);
} else {
throw new XPathException("Unknown function");
}
if (principal == null) {
result = Sequence.EMPTY_SEQUENCE;
} else {
if (isCalledAs(qnGetAccountMetadataKeys.getLocalPart()) || isCalledAs(qnGetGroupMetadataKeys.getLocalPart())) {
result = getPrincipalMetadataKeys(principal);
} else if (isCalledAs(qnGetAccountMetadata.getLocalPart()) || isCalledAs(qnGetGroupMetadata.getLocalPart())) {
final String metadataAttributeNamespace = args[1].getStringValue();
result = getPrincipalMetadata(principal, metadataAttributeNamespace);
} else {
throw new XPathException("Unknown function");
}
}
}
return result;
}
Aggregations