本文整理汇总了Java中org.wso2.balana.ObligationResult类的典型用法代码示例。如果您正苦于以下问题:Java ObligationResult类的具体用法?Java ObligationResult怎么用?Java ObligationResult使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ObligationResult类属于org.wso2.balana包,在下文中一共展示了ObligationResult类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: combine
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List policyElements) {
List<ObligationResult> denyObligations = new ArrayList<ObligationResult>();
List<Advice> denyAdvices = new ArrayList<Advice>();
for (Object policyElement : policyElements) {
AbstractPolicy policy = ((PolicyCombinerElement) (policyElement)).getPolicy();
AbstractResult result = policy.evaluate(context);
int value = result.getDecision();
// if there was a value of PERMIT, then regardless of what else
// we've seen, we always return PERMIT
if (value == AbstractResult.DECISION_PERMIT) {
return result;
} else if(value == AbstractResult.DECISION_DENY){
denyObligations.addAll(result.getObligations());
denyAdvices.addAll(result.getAdvices());
}
}
// if there is not any value of PERMIT. The return DENY
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_DENY, denyObligations,
denyAdvices, context);
}
示例2: combine
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List ruleElements) {
List<ObligationResult> permitObligations = new ArrayList<ObligationResult>();
List<Advice> permitAdvices= new ArrayList<Advice>();
for (Object ruleElement : ruleElements) {
Rule rule = ((RuleCombinerElement) (ruleElement)).getRule();
AbstractResult result = rule.evaluate(context);
int value = result.getDecision();
// if there was a value of DENY, then regardless of what else
// we've seen, we always return DENY
if (value == AbstractResult.DECISION_DENY) {
return result;
} else if(value == AbstractResult.DECISION_PERMIT){
permitObligations.addAll(result.getObligations());
permitAdvices.addAll(result.getAdvices());
}
}
// if there is not any value of DENY. The return PERMIT
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_PERMIT,
permitObligations, permitAdvices, context);
}
示例3: combine
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List policyElements) {
List<ObligationResult> permitObligations = new ArrayList<ObligationResult>();
List<Advice> permitAdvices= new ArrayList<Advice>();
for (Object policyElement : policyElements) {
AbstractPolicy policy = ((PolicyCombinerElement) (policyElement)).getPolicy();
AbstractResult result = policy.evaluate(context);
int value = result.getDecision();
// if there was a value of DENY, then regardless of what else
// we've seen, we always return DENY
if (value == AbstractResult.DECISION_DENY) {
return result;
} else if(value == AbstractResult.DECISION_PERMIT){
permitObligations.addAll(result.getObligations());
permitAdvices.addAll(result.getAdvices());
}
}
// if there is not any value of DENY. The return PERMIT
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_PERMIT,
permitObligations, permitAdvices, context);
}
示例4: combine
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List ruleElements) {
List<ObligationResult> denyObligations = new ArrayList<ObligationResult>();
List<Advice> denyAdvices = new ArrayList<Advice>();
for (Object ruleElement : ruleElements) {
Rule rule = ((RuleCombinerElement) (ruleElement)).getRule();
AbstractResult result = rule.evaluate(context);
int value = result.getDecision();
// if there was a value of PERMIT, then regardless of what else
// we've seen, we always return PERMIT
if (value == AbstractResult.DECISION_PERMIT) {
return result;
} else if(value == AbstractResult.DECISION_DENY){
denyObligations.addAll(result.getObligations());
denyAdvices.addAll(result.getAdvices());
}
}
// if there is not any value of PERMIT. The return DENY
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_DENY, denyObligations,
denyAdvices, context);
}
示例5: testWriteWithObligations
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
@Test
public void testWriteWithObligations() throws URISyntaxException {
List<AttributeAssignment> assignments = new ArrayList<>();
String content = "Error: Channel request is not WEB.";
URI type = new URI("http://www.w3.org/2001/XMLSchema#string");
URI attributeId = new URI("urn:oasis:names:tc:xacml:3.0:example:attribute:text");
AttributeAssignment attributeAssignment = new AttributeAssignment(attributeId, type, null, content, null);
assignments.add(attributeAssignment);
List<ObligationResult> obligationResults = new ArrayList<>();
ObligationResult obligationResult = new Obligation(assignments, new URI("channel_ko"));
obligationResults.add(obligationResult);
List<String> codes = new ArrayList<>();
codes.add("urn:oasis:names:tc:xacml:1.0:status:ok");
AbstractResult abstractResult = new Result(1, new Status(codes), obligationResults, null, null);
ResponseCtx responseCtx = new ResponseCtx(abstractResult);
JSONResponseWriter jsonResponseWriter = new JSONResponseWriter();
try {
JsonObject jsonObject = jsonResponseWriter.write(responseCtx);
assertNotNull("Failed to build the XACML json response", jsonObject.toString());
assertFalse("Failed to build the XACML json response", jsonObject.entrySet().isEmpty());
for(Map.Entry<String, JsonElement> jsonElementEntry: jsonObject.entrySet()) {
if (jsonElementEntry.getKey().equals("Response")) {
JsonArray jsonArray = (JsonArray) jsonElementEntry.getValue();
assertEquals("Failed to build the XACML json response with correct evaluation",
jsonArray.get(0).getAsJsonObject().get("Decision").getAsString(), "Deny");
}
}
} catch (ResponseWriteException e) {
assertNull("Failed to build the XACML response", e);
}
}
示例6: getResult
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
/**
* Returns instance of <code>AbstractResult</code> based one the XACML version.
* Constructs a <code>AbstractResult</code> object with decision and evaluation ctx
*
* @param decision decision the decision effect to include in this result.
* @param obligationResults a list of <code>ObligationResult</code> objects
* @param advices a list of <code>Advice</code> objects
* @param evaluationCtx context of a single policy evaluation
* @return <code>AbstractResult</code> object
*/
public AbstractResult getResult(int decision, List<ObligationResult> obligationResults,
List<Advice> advices, EvaluationCtx evaluationCtx) {
if(evaluationCtx.getXacmlVersion() == XACMLConstants.XACML_VERSION_3_0){
return new Result(decision, null, obligationResults,
advices, evaluationCtx);
} else {
return new org.wso2.balana.ctx.xacml2.Result(decision, null, obligationResults);
}
}
示例7: combine
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List policyElements) {
List<ObligationResult> denyObligations = new ArrayList<ObligationResult>();
List<Advice> denyAdvices = new ArrayList<Advice>();
for (Object policyElement : policyElements) {
AbstractPolicy policy = ((PolicyCombinerElement) (policyElement)).getPolicy();
MatchResult match = policy.match(context);
if (match.getResult() == MatchResult.MATCH) {
AbstractResult result = policy.evaluate(context);
int value = result.getDecision();
// if there was a value of PERMIT, then regardless of what else
// we've seen, we always return PERMIT
if (value == AbstractResult.DECISION_PERMIT) {
return result;
} else if(value == AbstractResult.DECISION_DENY){
denyObligations.addAll(result.getObligations());
denyAdvices.addAll(result.getAdvices());
}
}
}
// if there is not any value of PERMIT. The return DENY
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_DENY, denyObligations,
denyAdvices, context);
}
示例8: combine
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List policyElements) {
List<ObligationResult> permitObligations = new ArrayList<ObligationResult>();
List<Advice> permitAdvices= new ArrayList<Advice>();
for (Object policyElement : policyElements) {
AbstractPolicy policy = ((PolicyCombinerElement) (policyElement)).getPolicy();
MatchResult match = policy.match(context);
if (match.getResult() == MatchResult.MATCH) {
AbstractResult result = policy.evaluate(context);
int value = result.getDecision();
// if there was a value of DENY, then regardless of what else
// we've seen, we always return DENY
if (value == AbstractResult.DECISION_DENY) {
return result;
} else if (value == AbstractResult.DECISION_PERMIT) {
permitObligations.addAll(result.getObligations());
permitAdvices.addAll(result.getAdvices());
}
}
}
// if there is not any value of DENY. The return PERMIT
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_PERMIT,
permitObligations, permitAdvices, context);
}
示例9: abstractResultToJSONObject
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
/**
* Private method to convert a given Balana <code>{@link AbstractResult}</code> to a <code>{@link JsonObject}</code>
*
* @param result <code>{@link AbstractResult}</code>
* @return <code>{@link JsonObject}</code>
* @throws ResponseWriteException <code>{@link ResponseWriteException}</code>
*/
private static JsonObject abstractResultToJSONObject(AbstractResult result) throws ResponseWriteException {
JsonObject jsonResult = new JsonObject();
//Decision property is mandatory, if not set throw error
if (result.getDecision() == -1) {
throw new ResponseWriteException(40031, "XACML Result should contain the Decision");
}
jsonResult.addProperty(EntitlementEndpointConstants.DECISION,
AbstractResult.DECISIONS[result.getDecision()]);
//If Status object is present, convert it
if (result.getStatus() != null) {
jsonResult.add(EntitlementEndpointConstants.STATUS, statusToJSONObject(result.getStatus()));
}
//If Obligations are present
if (result.getObligations() != null && !result.getObligations().isEmpty()) {
//can only get ObligationResult objects from balana
JsonArray obligations = new JsonArray();
for (ObligationResult obligation : result.getObligations()) {
if (obligation instanceof Obligation) {
obligations.add(obligationToJsonObject((Obligation) obligation));
} else {
obligations.add(new JsonPrimitive(obligation.encode()));
}
}
jsonResult.add(EntitlementEndpointConstants.OBLIGATIONS, obligations);
}
//Do the same with attributes
if (result.getAdvices() != null && !result.getAdvices().isEmpty()) {
//can only get ObligationResult objects from balana
JsonArray advices = new JsonArray();
for (Advice advice : result.getAdvices()) {
advices.add(adviceToJsonObject(advice));
}
jsonResult.add(EntitlementEndpointConstants.ASSOCIATED_ADVICE, advices);
}
/**
* Todo: Category, PolicyIdentifierList
*/
return jsonResult;
}
示例10: combine
import org.wso2.balana.ObligationResult; //导入依赖的package包/类
/**
* Applies the combining rule to the set of rules based on the evaluation context.
*
* @param context the context from the request
* @param parameters a (possibly empty) non-null <code>List</code> of
* <code>CombinerParameter<code>s
* @param ruleElements the rules to combine
*
* @return the result of running the combining algorithm
*/
public AbstractResult combine(EvaluationCtx context, List parameters, List ruleElements) {
boolean atLeastOneError = false;
boolean potentialPermit = false;
boolean atLeastOneDeny = false;
AbstractResult firstIndeterminateResult = null;
List<ObligationResult> denyObligations = new ArrayList<ObligationResult>();
List<Advice> denyAdvices = new ArrayList<Advice>();
Iterator it = ruleElements.iterator();
while (it.hasNext()) {
Rule rule = ((RuleCombinerElement) (it.next())).getRule();
AbstractResult result = rule.evaluate(context);
int value = result.getDecision();
// if there was a value of PERMIT, then regardless of what
// else we've seen, we always return PERMIT
if (value == AbstractResult.DECISION_PERMIT){
return result;
}
// if it was INDETERMINATE, then we couldn't figure something
// out, so we keep track of these cases...
if (value == AbstractResult.DECISION_INDETERMINATE ||
value == AbstractResult.DECISION_INDETERMINATE_DENY ||
value == AbstractResult.DECISION_INDETERMINATE_PERMIT ||
value == AbstractResult.DECISION_INDETERMINATE_DENY_OR_PERMIT) {
atLeastOneError = true;
// there are no rules about what to do if multiple cases
// cause errors, so we'll just return the first one
if (firstIndeterminateResult == null){
firstIndeterminateResult = result;
}
// if the Rule's effect is PERMIT, then we can't let this
// alg return DENY, since this Rule might have permitted
// if it could do its stuff
if (rule.getEffect() == AbstractResult.DECISION_PERMIT){
potentialPermit = true;
}
} else {
// keep track of whether we had at least one rule that
// actually pertained to the request
if (value == AbstractResult.DECISION_DENY)
atLeastOneDeny = true;
denyAdvices.addAll(result.getAdvices());
denyObligations.addAll(result.getObligations());
}
}
// we didn't explicitly PERMIT, but we might have had some Rule
// been evaluated, so we have to return INDETERMINATE
if (potentialPermit){
return firstIndeterminateResult;
}
// some Rule said DENY, so since nothing could have permitted,
// we return DENY
if (atLeastOneDeny){
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_DENY, denyObligations,
denyAdvices, context);
}
// we didn't find anything that said DENY, but if we had a
// problem with one of the Rules, then we're INDETERMINATE
if (atLeastOneError){
return firstIndeterminateResult;
}
// if we hit this point, then none of the rules actually applied
// to us, so we return NOT_APPLICABLE
return ResultFactory.getFactory().getResult(AbstractResult.DECISION_NOT_APPLICABLE, context);
}