Java Code Examples for org.opensaml.xacml.ctx.ResponseType

The following examples show how to use org.opensaml.xacml.ctx.ResponseType. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentObject, XMLObject childObject) throws UnmarshallingException {
    XACMLAuthzDecisionStatementType xacmlauthzdecisionstatement = (XACMLAuthzDecisionStatementType) parentObject;

    if (childObject instanceof RequestType) {
        xacmlauthzdecisionstatement.setRequest((RequestType) childObject);
    } else if (childObject instanceof ResponseType) {
        xacmlauthzdecisionstatement.setResponse((ResponseType) childObject);
    } else {
        super.processChildElement(parentObject, childObject);
    }
}
 
Example 2
/** {@inheritDoc} */
protected void processChildElement(XMLObject parentXMLObject, XMLObject childXMLObject)
        throws UnmarshallingException {
    ResponseType response = (ResponseType) parentXMLObject;
    if (childXMLObject instanceof ResultType) {
        response.setResult((ResultType) childXMLObject);
    } else {
        super.processChildElement(parentXMLObject, childXMLObject);
    }
}
 
Example 3
Source Project: cxf   Source File: AbstractXACMLAuthorizingInterceptor.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Perform a (remote) authorization decision and return a boolean depending on the result
 */
protected boolean authorize(
    Principal principal, List<String> roles, Message message
) throws Exception {
    RequestType request = requestBuilder.createRequest(principal, roles, message);
    if (LOG.isLoggable(Level.FINE)) {
        Document doc = DOMUtils.createDocument();
        Element requestElement = OpenSAMLUtil.toDom(request, doc);
        LOG.log(Level.FINE, DOM2Writer.nodeToString(requestElement));
    }

    ResponseType response = performRequest(request, message);

    List<ResultType> results = response.getResults();

    if (results == null) {
        return false;
    }

    for (ResultType result : results) {
        // Handle any Obligations returned by the PDP
        handleObligations(request, principal, message, result);

        DECISION decision = result.getDecision() != null ? result.getDecision().getDecision() : DECISION.Deny;
        String code = "";
        String statusMessage = "";
        if (result.getStatus() != null) {
            StatusType status = result.getStatus();
            code = status.getStatusCode() != null ? status.getStatusCode().getValue() : "";
            statusMessage = status.getStatusMessage() != null ? status.getStatusMessage().getValue() : "";
        }
        if (LOG.isLoggable(Level.FINE)) {
            LOG.fine("XACML authorization result: " + decision + ", code: " + code + ", message: " + statusMessage);
        }
        return decision == DECISION.Permit;
    }

    return false;
}
 
Example 4
/** {@inheritDoc} */
public ResponseType getResponse() {
    return response;
}
 
Example 5
/** {@inheritDoc} */
public void setResponse(ResponseType response) {
    this.response = prepareForAssignment(this.response, response);
}
 
Example 6
Source Project: lams   Source File: ResponseTypeImplBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public ResponseType buildObject() {
    return buildObject(ResponseType.DEFAULT_ELEMENT_NAME);
}
 
Example 7
Source Project: lams   Source File: ResponseTypeImplBuilder.java    License: GNU General Public License v2.0 4 votes vote down vote up
/** {@inheritDoc} */
public ResponseType buildObject(String namespaceURI, String localName, String namespacePrefix) {
    return new ResponseTypeImpl(namespaceURI, localName, XACMLConstants.XACMLCONTEXT_PREFIX);
}
 
Example 8
Source Project: cxf   Source File: PolicyDecisionPointMockImpl.java    License: Apache License 2.0 4 votes vote down vote up
@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;
}
 
Example 9
Source Project: cxf   Source File: XACMLAuthorizingInterceptor.java    License: Apache License 2.0 4 votes vote down vote up
@Override
protected ResponseType performRequest(RequestType request, Message message) throws Exception {
    return this.pdp.evaluate(request);
}
 
Example 10
Source Project: cxf   Source File: DummyPDP.java    License: Apache License 2.0 4 votes vote down vote up
public ResponseType evaluate(RequestType request) {
    String role = getSubjectRole(request);
    DECISION decision = "manager".equals(role) ? DecisionType.DECISION.Permit : DecisionType.DECISION.Deny;
    return createResponse(decision);
}
 
Example 11
Source Project: cxf   Source File: DummyPDP.java    License: Apache License 2.0 4 votes vote down vote up
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;
}
 
Example 12
/**
 * Get's the {@link ResponseType} from the <code>XACMLAuthzDecisionStatement</code>.
 * 
 * @return the {@link ResponseType} inside the <code>XACMLAuthzDecisionStatement</code>
 */
public ResponseType getResponse();
 
Example 13
/**
 * Sets a {@link ResponseType} to the <code>XACMLAuthzDecisionStatement</code>.
 * 
 * @param response {@link ResponseType}
 */
public void setResponse(ResponseType response);
 
Example 14
Source Project: cxf   Source File: PolicyDecisionPoint.java    License: Apache License 2.0 2 votes vote down vote up
/**
 * Evaluate an XACML Request and return a Response
 * @param request an XACML Request as a RequestType
 * @return the XACML Response as a ResponseType
 */
ResponseType evaluate(RequestType request) throws Exception;
 
Example 15
protected abstract ResponseType performRequest(RequestType request, Message message) throws Exception;