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


Java RequestCtx类代码示例

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


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

示例1: getRequestCtx

import org.wso2.balana.ctx.xacml3.RequestCtx; //导入依赖的package包/类
/**
 *  Returns instance of <code>AbstractRequestCtx</code> based one the XACML version.
 *
 * @param root  the node to parse for the <code>AbstractRequestCtx</code>
 * @return <code>AbstractRequestCtx</code> object
 * @throws org.wso2.balana.ParsingException  if the DOM node is invalid
 */
public AbstractRequestCtx getRequestCtx(Node root) throws ParsingException {

    String requestCtxNs = root.getNamespaceURI();

    if(requestCtxNs != null){
        if(XACMLConstants.REQUEST_CONTEXT_3_0_IDENTIFIER.equals(requestCtxNs.trim())){
            return RequestCtx.getInstance(root);
        } else if(XACMLConstants.REQUEST_CONTEXT_1_0_IDENTIFIER.equals(requestCtxNs.trim()) ||
                XACMLConstants.REQUEST_CONTEXT_2_0_IDENTIFIER.equals(requestCtxNs.trim())) {
            return org.wso2.balana.ctx.xacml2.RequestCtx.getInstance(root);
        } else {
            throw new ParsingException("Invalid namespace in XACML request");
        }
    } else {
        log.warn("No Namespace defined in XACML request and Assume as XACML 3.0");
        return RequestCtx.getInstance(root);
    }
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:26,代码来源:RequestCtxFactory.java

示例2: getDecision

import org.wso2.balana.ctx.xacml3.RequestCtx; //导入依赖的package包/类
/**
 * API endpoint for evaluating XACML XML policies
 *
 * @return XML Policy result String
 */
@POST
@Path("pdp")
@Produces({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@Consumes({MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML})
@ApiOperation(value = "Get response by evaluating JSON/XML XACML request", response = String.class)
@ApiResponses(value = {
        @ApiResponse(code = 200, message = "XACML JSON/XML Response"),
        @ApiResponse(code = 40010, message = EntitlementEndpointConstants.ERROR_UNAUTHORIZED_MESSAGE,
                response = ExceptionBean.class),
        @ApiResponse(code = 40020, message = EntitlementEndpointConstants.ERROR_REQUEST_PARSE_MESSAGE,
                response = ExceptionBean.class),
        @ApiResponse(code = 40010, message = EntitlementEndpointConstants.ERROR_RESPONSE_READ_MESSAGE,
                response = ExceptionBean.class)
})
public String getDecision(@ApiParam(value = "Request Media Type", required = true)
                          @HeaderParam(EntitlementEndpointConstants.ACCEPT_HEADER) String format,
                          @ApiParam(value = "Authentication Type", required = true)
                          @HeaderParam(EntitlementEndpointConstants.AUTHENTICATION_TYPE_HEADER) String authMechanism,
                          @ApiParam(value = "Add HTTP Basic Authorization", required = true)
                          @HeaderParam(EntitlementEndpointConstants.AUTHORIZATION_HEADER) String authorization,
                          @ApiParam(value = "Response Media Type", required = true)
                          @HeaderParam(EntitlementEndpointConstants.CONTENT_TYPE_HEADER) String contentType,
                          @ApiParam(value = "XACML JSON/XML Request", required = true)
                                  String xacmlRequest) throws Exception {

    if (log.isDebugEnabled()) {
        log.debug("recieved :" + xacmlRequest);
    }
    EntitlementEngine entitlementEngine = EntitlementEngine.getInstance();

    if (contentType.equals(EntitlementEndpointConstants.APPLICATION_JSON)) {
        RequestCtx requestCtx = JSONRequestParser.parse(xacmlRequest);
        ResponseCtx responseCtx = entitlementEngine.evaluate(requestCtx, xacmlRequest);
        return gson.toJson(JSONResponseWriter.write(responseCtx));
    } else {
        return entitlementEngine.evaluate(xacmlRequest);
    }

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

示例3: getEvaluationCtx

import org.wso2.balana.ctx.xacml3.RequestCtx; //导入依赖的package包/类
public EvaluationCtx getEvaluationCtx(AbstractRequestCtx requestCtx, PDPConfig pdpConfig)
                                                                    throws ParsingException {

    if(XACMLConstants.XACML_VERSION_3_0 == requestCtx.getXacmlVersion()){
        return new XACML3EvaluationCtx((RequestCtx)requestCtx, pdpConfig);
    } else {
        return new XACML2EvaluationCtx((org.wso2.balana.ctx.xacml2.RequestCtx) requestCtx, pdpConfig);
    }
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:10,代码来源:EvaluationCtxFactory.java

示例4: evaluateContext

import org.wso2.balana.ctx.xacml3.RequestCtx; //导入依赖的package包/类
/**
 * A private helper routine that resolves a policy for the given context, and then tries to
 * evaluate based on the policy
    *
    * @param context  context
    * @return a response
    */
private AbstractResult evaluateContext(EvaluationCtx context) {
	// first off, try to find a policy
	PolicyFinderResult finderResult = policyFinder.findPolicy(context);

	// see if there weren't any applicable policies
	if (finderResult.notApplicable()){
           return ResultFactory.getFactory().getResult(AbstractResult.DECISION_NOT_APPLICABLE, context);
       }
	// see if there were any errors in trying to get a policy
	if (finderResult.indeterminate()){
           return ResultFactory.getFactory().getResult(AbstractResult.DECISION_INDETERMINATE,
                   finderResult.getStatus(), context);
       }

	// we found a valid policy,

       // list all found policies if XACML 3.0
       if(context instanceof XACML3EvaluationCtx && ((RequestCtx)context.getRequestCtx()).
                                                                           isReturnPolicyIdList()){
           Set<PolicyReference> references = new HashSet<PolicyReference>();
           processPolicyReferences(finderResult.getPolicy(), references);
           ((XACML3EvaluationCtx) context).setPolicyReferences(references);
       }

       // so we can do the evaluation
	return finderResult.getPolicy().evaluate(context);
}
 
开发者ID:FTSRG,项目名称:mondo-collab-framework,代码行数:35,代码来源:PDP.java

示例5: evaluateContext

import org.wso2.balana.ctx.xacml3.RequestCtx; //导入依赖的package包/类
/**
 * A private helper routine that resolves a policy for the given context, and then tries to
 * evaluate based on the policy
 *
 * @param context context
 * @return a response
 */
private AbstractResult evaluateContext(EvaluationCtx context) {
    // first off, try to find a policy
    PolicyFinderResult finderResult = policyFinder.findPolicy(context);

    // see if there weren't any applicable policies
    if (finderResult.notApplicable()) {
        return ResultFactory.getFactory().getResult(AbstractResult.DECISION_NOT_APPLICABLE, context);
    }
    // see if there were any errors in trying to get a policy
    if (finderResult.indeterminate()) {
        return ResultFactory.getFactory().getResult(AbstractResult.DECISION_INDETERMINATE,
                finderResult.getStatus(), context);
    }

    // we found a valid policy,

    // list all found policies if XACML 3.0
    if (context instanceof XACML3EvaluationCtx && ((RequestCtx) context.getRequestCtx()).
            isReturnPolicyIdList()) {
        Set<PolicyReference> references = new HashSet<PolicyReference>();
        processPolicyReferences(finderResult.getPolicy(), references);
        ((XACML3EvaluationCtx) context).setPolicyReferences(references);
    }

    // so we can do the evaluation
    return finderResult.getPolicy().evaluate(context);
}
 
开发者ID:wso2,项目名称:balana,代码行数:35,代码来源:PDP.java

示例6: testParse

import org.wso2.balana.ctx.xacml3.RequestCtx; //导入依赖的package包/类
@Test
public void testParse() {
    AttributeValue attributeValue = new StringAttribute("http://127.0.0.1");
    List<AttributeValue> attributeValues = new ArrayList<>();
    attributeValues.add(attributeValue);

    Attribute attribute = new Attribute(URI.create("urn:oasis:names:tc:xacml:1.0:resource:resource-id"),
            null, null, null, attributeValues, false, XACMLConstants.XACML_VERSION_3_0);
    Set<Attribute> attributeSet = new HashSet<>();
    attributeSet.add(attribute);

    Attributes category = new Attributes(URI.create(EntitlementEndpointConstants.CATEGORY_RESOURCE_URI),
            attributeSet);
    Set<Attributes> categories = new HashSet<>();
    categories.add(category);

    RequestCtx requestCtx = new RequestCtx(categories, null);


    String jsonRequest = "{\n" +
            "  \"Request\":{\n" +
            "    \"Action\":{\n" +
            "      \"Attribute\":[{\n" +
            "        \"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:action:action-id\",\n" +
            "        \"Value\":\"read\"\n" +
            "      }]\n" +
            "    },\n" +
            "    \"Resource\":{\n" +
            "      \"Attribute\":[{\n" +
            "        \"AttributeId\":\"urn:oasis:names:tc:xacml:1.0:resource:resource-id\",\n" +
            "        \"Value\":\"http://127.0.0.1/service/very_secure/\"\n" +
            "      }]\n" +
            "    }\n" +
            "  }\n" +
            "}";

    String jsonRequest2 = "{\"Request\":\n" +
            "{\n" +
            "\"AccessSubject\":{\n" +
            "            \"Content\": \"PD94bWwgdmVyc2lvbj0iMS4wIj8+DQo8Y2F0YWxvZz48Ym9vayBpZD0iYmsxMDEiPjxhdXRob3I+R2FtYmFyZGVsbGEsIE1hdHRoZXc8L2F1dGhvcj48dGl0bGU+WE1MIERldmVsb3BlcidzIEd1aWRlPC90aXRsZT48Z2VucmU+Q29tcHV0ZXI8L2dlbnJlPjxwcmljZT40NC45NTwvcHJpY2U+PHB1Ymxpc2hfZGF0ZT4yMDAwLTEwLTAxPC9wdWJsaXNoX2RhdGU+PGRlc2NyaXB0aW9uPkFuIGluLWRlcHRoIGxvb2sgYXQgY3JlYXRpbmcgYXBwbGljYXRpb25zIHdpdGggWE1MLjwvZGVzY3JpcHRpb24+PC9ib29rPjwvY2F0YWxvZz4=\"\n" +
            "}\n" +
            "}}";

    try {
        RequestCtx requestCtx1 = JSONRequestParser.parse(jsonRequest);
    } catch (Exception e) {
        log.error("Exception in JSON Parser Test");
    }


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


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