Search in sources :

Example 1 with XMLObjectBuilderFactory

use of org.opensaml.core.xml.XMLObjectBuilderFactory in project testcases by coheigea.

the class MockPDPImpl method evaluate.

@POST
public Source evaluate(Source request) {
    RequestType requestType = requestSourceToRequestType(request);
    XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
    @SuppressWarnings("unchecked") XACMLObjectBuilder<ResponseType> responseTypeBuilder = (XACMLObjectBuilder<ResponseType>) builderFactory.getBuilder(ResponseType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<ResultType> resultTypeBuilder = (XACMLObjectBuilder<ResultType>) builderFactory.getBuilder(ResultType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<DecisionType> decisionTypeBuilder = (XACMLObjectBuilder<DecisionType>) builderFactory.getBuilder(DecisionType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<StatusType> statusTypeBuilder = (XACMLObjectBuilder<StatusType>) builderFactory.getBuilder(StatusType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<StatusCodeType> statusCodeTypeBuilder = (XACMLObjectBuilder<StatusCodeType>) builderFactory.getBuilder(StatusCodeType.DEFAULT_ELEMENT_NAME);
    DecisionType decisionType = decisionTypeBuilder.buildObject();
    String role = getSubjectRole(requestType);
    if ("boss".equals(role)) {
        decisionType.setDecision(DecisionType.DECISION.Permit);
    } else {
        decisionType.setDecision(DecisionType.DECISION.Deny);
    }
    ResultType result = resultTypeBuilder.buildObject();
    result.setDecision(decisionType);
    StatusType status = statusTypeBuilder.buildObject();
    StatusCodeType statusCode = statusCodeTypeBuilder.buildObject();
    statusCode.setValue("urn:oasis:names:tc:xacml:1.0:status:ok");
    status.setStatusCode(statusCode);
    result.setStatus(status);
    ResponseType response = responseTypeBuilder.buildObject();
    response.getResults().add(result);
    return responseType2Source(response);
}
Also used : XACMLObjectBuilder(org.opensaml.xacml.XACMLObjectBuilder) ResultType(org.opensaml.xacml.ctx.ResultType) DecisionType(org.opensaml.xacml.ctx.DecisionType) ResponseType(org.opensaml.xacml.ctx.ResponseType) StatusType(org.opensaml.xacml.ctx.StatusType) XMLObjectBuilderFactory(org.opensaml.core.xml.XMLObjectBuilderFactory) StatusCodeType(org.opensaml.xacml.ctx.StatusCodeType) RequestType(org.opensaml.xacml.ctx.RequestType) POST(javax.ws.rs.POST)

Example 2 with XMLObjectBuilderFactory

use of org.opensaml.core.xml.XMLObjectBuilderFactory in project cxf by apache.

the class DummyPDP method createResponse.

private ResponseType createResponse(DECISION decision) {
    XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
    @SuppressWarnings("unchecked") XACMLObjectBuilder<ResponseType> responseTypeBuilder = (XACMLObjectBuilder<ResponseType>) builderFactory.getBuilder(ResponseType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<ResultType> resultTypeBuilder = (XACMLObjectBuilder<ResultType>) builderFactory.getBuilder(ResultType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<DecisionType> decisionTypeBuilder = (XACMLObjectBuilder<DecisionType>) builderFactory.getBuilder(DecisionType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<StatusType> statusTypeBuilder = (XACMLObjectBuilder<StatusType>) builderFactory.getBuilder(StatusType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<StatusCodeType> statusCodeTypeBuilder = (XACMLObjectBuilder<StatusCodeType>) builderFactory.getBuilder(StatusCodeType.DEFAULT_ELEMENT_NAME);
    ResultType result = resultTypeBuilder.buildObject();
    DecisionType decisionType = decisionTypeBuilder.buildObject();
    decisionType.setDecision(decision);
    result.setDecision(decisionType);
    StatusType status = statusTypeBuilder.buildObject();
    StatusCodeType statusCode = statusCodeTypeBuilder.buildObject();
    statusCode.setValue("urn:oasis:names:tc:xacml:1.0:status:ok");
    status.setStatusCode(statusCode);
    result.setStatus(status);
    ResponseType response = responseTypeBuilder.buildObject();
    response.getResults().add(result);
    return response;
}
Also used : XACMLObjectBuilder(org.opensaml.xacml.XACMLObjectBuilder) ResultType(org.opensaml.xacml.ctx.ResultType) DecisionType(org.opensaml.xacml.ctx.DecisionType) ResponseType(org.opensaml.xacml.ctx.ResponseType) StatusType(org.opensaml.xacml.ctx.StatusType) XMLObjectBuilderFactory(org.opensaml.core.xml.XMLObjectBuilderFactory) StatusCodeType(org.opensaml.xacml.ctx.StatusCodeType)

Example 3 with XMLObjectBuilderFactory

use of org.opensaml.core.xml.XMLObjectBuilderFactory in project cxf by apache.

the class PolicyDecisionPointMockImpl method evaluate.

@Override
public ResponseType evaluate(RequestType requestType) {
    XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
    @SuppressWarnings("unchecked") XACMLObjectBuilder<ResponseType> responseTypeBuilder = (XACMLObjectBuilder<ResponseType>) builderFactory.getBuilder(ResponseType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<ResultType> resultTypeBuilder = (XACMLObjectBuilder<ResultType>) builderFactory.getBuilder(ResultType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<DecisionType> decisionTypeBuilder = (XACMLObjectBuilder<DecisionType>) builderFactory.getBuilder(DecisionType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<StatusType> statusTypeBuilder = (XACMLObjectBuilder<StatusType>) builderFactory.getBuilder(StatusType.DEFAULT_ELEMENT_NAME);
    @SuppressWarnings("unchecked") XACMLObjectBuilder<StatusCodeType> statusCodeTypeBuilder = (XACMLObjectBuilder<StatusCodeType>) builderFactory.getBuilder(StatusCodeType.DEFAULT_ELEMENT_NAME);
    DecisionType decisionType = decisionTypeBuilder.buildObject();
    String role = getSubjectRole(requestType);
    if ("manager".equals(role)) {
        decisionType.setDecision(DecisionType.DECISION.Permit);
    } else {
        decisionType.setDecision(DecisionType.DECISION.Deny);
    }
    ResultType result = resultTypeBuilder.buildObject();
    result.setDecision(decisionType);
    StatusType status = statusTypeBuilder.buildObject();
    StatusCodeType statusCode = statusCodeTypeBuilder.buildObject();
    statusCode.setValue("urn:oasis:names:tc:xacml:1.0:status:ok");
    status.setStatusCode(statusCode);
    result.setStatus(status);
    ResponseType response = responseTypeBuilder.buildObject();
    response.getResults().add(result);
    return response;
}
Also used : XACMLObjectBuilder(org.opensaml.xacml.XACMLObjectBuilder) ResultType(org.opensaml.xacml.ctx.ResultType) DecisionType(org.opensaml.xacml.ctx.DecisionType) ResponseType(org.opensaml.xacml.ctx.ResponseType) StatusType(org.opensaml.xacml.ctx.StatusType) XMLObjectBuilderFactory(org.opensaml.core.xml.XMLObjectBuilderFactory) StatusCodeType(org.opensaml.xacml.ctx.StatusCodeType)

Example 4 with XMLObjectBuilderFactory

use of org.opensaml.core.xml.XMLObjectBuilderFactory in project cxf by apache.

the class CustomClaimsHandler method retrieveClaimValues.

public ProcessedClaimCollection retrieveClaimValues(ClaimCollection claims, ClaimsParameters parameters) {
    if (claims != null && !claims.isEmpty()) {
        ProcessedClaimCollection claimCollection = new ProcessedClaimCollection();
        for (Claim requestClaim : claims) {
            ProcessedClaim claim = new ProcessedClaim();
            claim.setClaimType(requestClaim.getClaimType());
            if (ClaimTypes.FIRSTNAME.toString().equals(requestClaim.getClaimType())) {
                if (requestClaim instanceof CustomRequestClaim) {
                    CustomRequestClaim customClaim = (CustomRequestClaim) requestClaim;
                    String customName = customClaim.getValues().get(0) + "@" + customClaim.getScope();
                    claim.addValue(customName);
                } else {
                    claim.addValue("alice");
                }
            } else if (ClaimTypes.LASTNAME.toString().equals(requestClaim.getClaimType())) {
                claim.addValue("doe");
            } else if (ClaimTypes.EMAILADDRESS.toString().equals(requestClaim.getClaimType())) {
                claim.addValue("alice@cxf.apache.org");
            } else if (ClaimTypes.STREETADDRESS.toString().equals(requestClaim.getClaimType())) {
                claim.addValue("1234 1st Street");
            } else if (ClaimTypes.MOBILEPHONE.toString().equals(requestClaim.getClaimType())) {
                // Test custom (Integer) attribute value
                XMLObjectBuilderFactory builderFactory = XMLObjectProviderRegistrySupport.getBuilderFactory();
                @SuppressWarnings("unchecked") XMLObjectBuilder<XSInteger> xsIntegerBuilder = (XMLObjectBuilder<XSInteger>) builderFactory.getBuilder(XSInteger.TYPE_NAME);
                XSInteger attributeValue = xsIntegerBuilder.buildObject(AttributeValue.DEFAULT_ELEMENT_NAME, XSInteger.TYPE_NAME);
                attributeValue.setValue(185912592);
                claim.addValue(attributeValue);
            } else if (ROLE_CLAIM.equals(requestClaim.getClaimType())) {
                if (requestClaim.getValues().size() > 0) {
                    for (Object requestedRole : requestClaim.getValues()) {
                        if (isUserInRole(parameters.getPrincipal(), requestedRole.toString())) {
                            claim.addValue(requestedRole);
                        }
                    }
                    if (claim.getValues().isEmpty()) {
                        continue;
                    }
                } else {
                    // If no specific role was requested return DUMMY role for user
                    claim.addValue(role);
                }
            }
            claimCollection.add(claim);
        }
        return claimCollection;
    }
    return null;
}
Also used : ProcessedClaimCollection(org.apache.cxf.sts.claims.ProcessedClaimCollection) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) XSInteger(org.opensaml.core.xml.schema.XSInteger) XMLObjectBuilder(org.opensaml.core.xml.XMLObjectBuilder) XMLObjectBuilderFactory(org.opensaml.core.xml.XMLObjectBuilderFactory) CustomRequestClaim(org.apache.cxf.sts.common.CustomClaimParser.CustomRequestClaim) CustomRequestClaim(org.apache.cxf.sts.common.CustomClaimParser.CustomRequestClaim) ProcessedClaim(org.apache.cxf.sts.claims.ProcessedClaim) Claim(org.apache.cxf.rt.security.claims.Claim)

Aggregations

XMLObjectBuilderFactory (org.opensaml.core.xml.XMLObjectBuilderFactory)4 XACMLObjectBuilder (org.opensaml.xacml.XACMLObjectBuilder)3 DecisionType (org.opensaml.xacml.ctx.DecisionType)3 ResponseType (org.opensaml.xacml.ctx.ResponseType)3 ResultType (org.opensaml.xacml.ctx.ResultType)3 StatusCodeType (org.opensaml.xacml.ctx.StatusCodeType)3 StatusType (org.opensaml.xacml.ctx.StatusType)3 POST (javax.ws.rs.POST)1 Claim (org.apache.cxf.rt.security.claims.Claim)1 ProcessedClaim (org.apache.cxf.sts.claims.ProcessedClaim)1 ProcessedClaimCollection (org.apache.cxf.sts.claims.ProcessedClaimCollection)1 CustomRequestClaim (org.apache.cxf.sts.common.CustomClaimParser.CustomRequestClaim)1 XMLObjectBuilder (org.opensaml.core.xml.XMLObjectBuilder)1 XSInteger (org.opensaml.core.xml.schema.XSInteger)1 RequestType (org.opensaml.xacml.ctx.RequestType)1