当前位置: 首页>>代码示例>>Java>>正文


Java AbstractResult类代码示例

本文整理汇总了Java中org.wso2.balana.ctx.AbstractResult的典型用法代码示例。如果您正苦于以下问题:Java AbstractResult类的具体用法?Java AbstractResult怎么用?Java AbstractResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AbstractResult类属于org.wso2.balana.ctx包,在下文中一共展示了AbstractResult类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: write

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
/**
 * Returns <code>JsonObject</code> created by parsing the contents of a given
 * Balana <code>{@link ResponseCtx}</code>
 *
 * @param response <code>{@link ResponseCtx}</code>
 * @return <code>{@link JsonObject}</code> with parsed properties
 * @throws ResponseWriteException <code>{@link ResponseWriteException}</code>
 */
public static JsonObject write(ResponseCtx response) throws ResponseWriteException {
    JsonObject responseWrap = new JsonObject();

    //JsonObject jsonResponse = new JsonObject();
    JsonArray results = new JsonArray();

    //Loop all AbstractResult objects in ResponseCtx and add them as
    //Requests to JSON Response
    //There should be at least 1 request
    if (response.getResults().size() < 1) {
        throw new ResponseWriteException(40032, "XACML response should contain at least 1 Result");
    }

    for (AbstractResult result : response.getResults()) {
        results.add(abstractResultToJSONObject(result));
    }
    responseWrap.add(EntitlementEndpointConstants.RESPONSE, results);

    return responseWrap;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:29,代码来源:JSONResponseWriter.java

示例2: getResponse

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
/**
 * Helper method to get XACML decision
 *
 * @param requestAttributes XACML request attributes
 * @return whether permit or deny
 */
private boolean getResponse(List<AttributeDTO> requestAttributes) {

    ResponseCtx responseCtx;
    AbstractRequestCtx requestCtx = EntitlementUtil.createRequestContext(requestAttributes);

    responseCtx = EntitlementEngine.getInstance().evaluateByContext(requestCtx);

    if (responseCtx != null) {
        Set<AbstractResult> results = responseCtx.getResults();
        for (AbstractResult result : results) {
            if (result.getDecision() == AbstractResult.DECISION_PERMIT) {
                return true;
            }
        }
    }

    return false;
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:25,代码来源:PolicySearch.java

示例3: evaluate

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
/**
     * Tries to evaluate the policy by calling the combining algorithm on the given policies or
     * rules. The <code>match</code> method must always be called first, and must always return
     * MATCH, before this method is called.
     * 
     * @param context the representation of the request
     * 
     * @return the result of evaluation
     */
    public AbstractResult evaluate(EvaluationCtx context) {
        // if there is no finder, then we return NotApplicable
        if (finder == null){
            //return new Result(Result.DECISION_NOT_APPLICABLE, context.getResourceId().encode());
            return ResultFactory.getFactory().getResult(Result.DECISION_NOT_APPLICABLE, context);
        }

        PolicyFinderResult pfr = finder.findPolicy(reference, policyType, constraints,
                parentMetaData);

        // if we found nothing, then we return NotApplicable
        if (pfr.notApplicable()){
            //return new Result(Result.DECISION_NOT_APPLICABLE, context.getResourceId().encode());
            return ResultFactory.getFactory().getResult(Result.DECISION_NOT_APPLICABLE, context);
        }
        // if there was an error, we return that status data
        if (pfr.indeterminate()){
//            return new Result(Result.DECISION_INDETERMINATE, pfr.getStatus(), context
//                    .getResourceId().encode());
            return ResultFactory.getFactory().getResult(Result.DECISION_INDETERMINATE, pfr.getStatus(), context);
        }
        // we must have found a policy
        return pfr.getPolicy().evaluate(context);
    }
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:34,代码来源:PolicyReference.java

示例4: combine

import org.wso2.balana.ctx.AbstractResult; //导入依赖的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);
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:26,代码来源:DenyUnlessPermitPolicyAlg.java

示例5: combine

import org.wso2.balana.ctx.AbstractResult; //导入依赖的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);
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:26,代码来源:PermitUnlessDenyRuleAlg.java

示例6: combine

import org.wso2.balana.ctx.AbstractResult; //导入依赖的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);
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:26,代码来源:PermitUnlessDenyPolicyAlg.java

示例7: combine

import org.wso2.balana.ctx.AbstractResult; //导入依赖的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);
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:26,代码来源:DenyUnlessPermitRuleAlg.java

示例8: combine

import org.wso2.balana.ctx.AbstractResult; //导入依赖的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) {
    Iterator it = ruleElements.iterator();
    while (it.hasNext()) {
        Rule rule = ((RuleCombinerElement) (it.next())).getRule();
        AbstractResult result = rule.evaluate(context);
        int value = result.getDecision();

        // in the case of PERMIT, DENY, or INDETERMINATE, we always
        // just return that result, so only on a rule that doesn't
        // apply do we keep going...
        if (value != Result.DECISION_NOT_APPLICABLE) {
            return result;
        }
    }

    // if we got here, then none of the rules applied
    return ResultFactory.getFactory().getResult(Result.DECISION_NOT_APPLICABLE, context);
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:29,代码来源:FirstApplicableRuleAlg.java

示例9: evaluate

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
/**
 * Tries to evaluate the policy by calling the combining algorithm on the given policies or
 * rules. The <code>match</code> method must always be called first, and must always return
 * MATCH, before this method is called.
 *
 * @param context the representation of the request
 *
 * @return the result of evaluation
 */
public AbstractResult evaluate(EvaluationCtx context) {
    
    // evaluate
    AbstractResult result = combiningAlg.combine(context, parameters, childElements);

    // if we have no obligation expressions or advice expressions, we're done
    if (obligationExpressions.size() < 1 && adviceExpressions.size() < 1){
        return result;
    }

    // if we have obligations,
    // now, see if we should add any obligations to the set
    int effect = result.getDecision();

    if ((effect == Result.DECISION_INDETERMINATE) || (effect == Result.DECISION_NOT_APPLICABLE)) {
        // we didn't permit/deny, so we never return obligations
        return result;
    }
    
    // if any obligations or advices are defined, evaluates them and return
    processObligationAndAdvices(context, effect, result);
    return result;

}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:34,代码来源:AbstractPolicy.java

示例10: processObligationAndAdvices

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
/**
 * helper method to evaluate the obligations and advice expressions
 *
 * @param evaluationCtx context of a single policy evaluation
 * @param effect policy effect
 * @param result result of combining algorithm
 */
private void processObligationAndAdvices(EvaluationCtx evaluationCtx, int effect, AbstractResult result){

    if(obligationExpressions != null && obligationExpressions.size() > 0){
        Set<ObligationResult>  results = new HashSet<ObligationResult>();
        for(AbstractObligation obligationExpression : obligationExpressions){
            if(obligationExpression.getFulfillOn() == effect) {
                results.add(obligationExpression.evaluate(evaluationCtx));
            }
        }
        result.getObligations().addAll(results);
    }

    if(adviceExpressions != null && adviceExpressions.size() > 0){
        Set<Advice>  advices = new HashSet<Advice>();
        for(AdviceExpression adviceExpression : adviceExpressions){
            if(adviceExpression.getAppliesTo() == effect) {
                advices.add(adviceExpression.evaluate(evaluationCtx));
            }
        }
        result.getAdvices().addAll(advices);
    }
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:30,代码来源:AbstractPolicy.java

示例11: checkAccessByRequest

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
public static boolean checkAccessByRequest(String request){
	boolean access = false;
	
	PDP pdp = PDPHelper.getPDPNewInstance();

	String response = pdp.evaluate(request);

	if (debug) {
		System.out
				.println("XACML Response:");
		System.out.println(response);
	}

	try {
		ResponseCtx responseCtx = ResponseCtx
				.getInstance(XACMLHelper.getXacmlResponse(response));
		AbstractResult result = responseCtx.getResults().iterator().next();
		if (AbstractResult.DECISION_PERMIT == result.getDecision()) {
			access = true;
		}
	} catch (ParsingException e) {
		e.printStackTrace();
	}

	return access;
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:27,代码来源:PEPHelper.java

示例12: combine

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
@Override
public AbstractResult combine(EvaluationCtx context, List parameters, List ruleElements) {

    int noOfDenyRules = 0;
    int noOfPermitRules = 0;

    for (Object ruleElement : ruleElements) {
        
        Rule rule = ((RuleCombinerElement) (ruleElement)).getRule();
        AbstractResult result = rule.evaluate(context);

        int value = result.getDecision();
        if (value == Result.DECISION_DENY) {
            noOfDenyRules++;
        } else if (value == Result.DECISION_PERMIT) {
            noOfPermitRules++;
        }
    }

    if(noOfPermitRules > noOfDenyRules){
        return ResultFactory.getFactory().getResult(Result.DECISION_PERMIT, context);            
    } else {
        return ResultFactory.getFactory().getResult(Result.DECISION_DENY, context);     
    }
}
 
开发者ID:wso2,项目名称:balana,代码行数:26,代码来源:HighestEffectRuleAlg.java

示例13: testWriteWithObligations

import org.wso2.balana.ctx.AbstractResult; //导入依赖的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);
    }

}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:38,代码来源:TestJSONResponseWriter.java

示例14: testWriteWithAdvices

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
@Test
public void testWriteWithAdvices() 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<Advice> adviceResults = new ArrayList<>();
    Advice adviceResult = new Advice(new URI("channel_ko"), assignments);
    adviceResults.add(adviceResult);

    List<String> codes = new ArrayList<>();
    codes.add("urn:oasis:names:tc:xacml:1.0:status:ok");
    AbstractResult abstractResult = new Result(1, new Status(codes), null, adviceResults, 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 json response", e);
    }

}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:38,代码来源:TestJSONResponseWriter.java

示例15: encode

import org.wso2.balana.ctx.AbstractResult; //导入依赖的package包/类
/**
 * Encodes this <code>ObligationExpression</code> into its XML form and writes this out to the provided
 * <code>StringBuilder<code>
 *
 * @param builder string stream into which the XML-encoded data is written
 */
public void encode(StringBuilder builder) {

    builder.append("<ObligationExpression ObligationId=\"").append(obligationId.toString()).
            append("\" FulfillOn=\"").append(AbstractResult.DECISIONS[fulfillOn]).append("\">\n");
    for (AttributeAssignmentExpression assignment : expressions) {
        assignment.encode(builder);
    }
    builder.append("</ObligationExpression>");
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:16,代码来源:ObligationExpression.java


注:本文中的org.wso2.balana.ctx.AbstractResult类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。