org.wso2.balana.ParsingException Java Examples

The following examples show how to use org.wso2.balana.ParsingException. 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
Source File: DNSNameAttribute.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Creates the new <code>DNSNameAttribute</code> with the optional port range component.
 * 
 * @param hostname the host name component of the address
 * @param range the port range
 * 
 * @throws ParsingException if the hostname is invalid
 */
public DNSNameAttribute(String hostname, PortRange range) throws ParsingException {
    super(identifierURI);

    // shouldn't happen, but just in case...
    if (earlyException != null)
        throw earlyException;

    // verify that the hostname is valid before we store it
    if (!isValidHostName(hostname))
        System.out.println("FIXME: throw error about bad hostname");

    // see if it started with a '*' character
    if (hostname.charAt(0) == '*')
        this.isSubdomain = true;

    this.hostname = hostname;
    this.range = range;
}
 
Example #2
Source File: BaseAttributeFactory.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a value based on the given data type and text-encoded value. Used primarily by code
 * that does an XPath query to get an attribute value, and then needs to turn the resulting
 * value into an Attribute class.
 * 
 * @param dataType the type of the attribute
 * @param value the text-encoded representation of an attribute's value
 * @param params additional parameters that need to creates a value
 * @return a new <code>AttributeValue</code>
 * 
 * @throws UnknownIdentifierException if the data type isn't known to the factory
 * @throws ParsingException if the text is invalid or can't be parsed by the appropriate proxy
 */
public AttributeValue createValue(URI dataType, String value, String[] params)
        throws UnknownIdentifierException, ParsingException {
    String type = dataType.toString();
    AttributeProxy proxy = (AttributeProxy) (attributeMap.get(type));

    if (proxy != null) {
        try {
            return proxy.getInstance(value, params);
        } catch (Exception e) {
            throw new ParsingException("couldn't create " + type + " attribute from input: "
                    + value);
        }
    } else {
        throw new UnknownIdentifierException("Attributes of type " + type
                + " aren't supported.");
    }
}
 
Example #3
Source File: BaseAttributeFactory.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a value based on the given DOM root node and data type.
 * 
 * @param root the DOM root of an attribute value
 * @param type the type of the attribute
 * 
 * @return a new <code>AttributeValue</code>
 * 
 * @throws UnknownIdentifierException if the type isn't known to the factory
 * @throws ParsingException if the node is invalid or can't be parsed by the appropriate proxy
 */
public AttributeValue createValue(Node root, String type) throws UnknownIdentifierException,
        ParsingException {

    AttributeValue attributeValue;
    AttributeProxy proxy = (AttributeProxy) (attributeMap.get(type));

    if (proxy != null) {
        try {
            attributeValue =  proxy.getInstance(root);
        } catch (Exception e) {
            throw new ParsingException("couldn't create " + type
                    + " attribute based on DOM node");
        }
    } else {
        throw new UnknownIdentifierException("Attributes of type " + type
                + " aren't supported.");
    }

    if (attributeValue == null) {
        throw new ParsingException("Could not create " + type + " attribute based on DOM node");
    }

    return attributeValue;
}
 
Example #4
Source File: RequestCtxFactory.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 *  Returns instance of <code>AbstractRequestCtx</code> based one the XACML version.
 *
 * @param request  the String to parse for the <code>AbstractRequestCtx</code>
 * @return <code>AbstractRequestCtx</code> object
 * @throws ParsingException  if the request is invalid
 */
public AbstractRequestCtx getRequestCtx(String request) throws ParsingException {

    Node root = getXacmlRequest(request);
    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);
    }
}
 
Example #5
Source File: RequestCtxFactory.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 *  Returns instance of <code>AbstractRequestCtx</code> based one the XACML version.
 *
 * Creates a new <code>RequestCtx</code> by parsing XML from an input stream. Note that this a
 * convenience method, and it will not do schema validation by default. You should be parsing
 * the data yourself, and then providing the root node to the other <code>getInstance</code>
 * method. If you use this convenience method, you probably want to turn on validation by
 * setting the context schema file (see the programmer guide for more information on this).
 *
 * @param input input a stream providing the XML data
 * @return <code>AbstractRequestCtx</code> object
 * @throws ParsingException  if the DOM node is invalid
 */
public AbstractRequestCtx getRequestCtx(InputStream input) throws ParsingException {

    Node root  = InputParser.parseInput(input, "Request");
    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);
    }
}
 
Example #6
Source File: VariableDefinition.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new instance of the <code>VariableDefinition</code> class based on a DOM node. The
 * node must be the root of an XML VariableDefinitionType.
 * 
 * @param root the DOM root of a VariableDefinitionType XML type
 * @param metaData the meta-data associated with the containing policy
 * @param manager <code>VariableManager</code> used to connect references to this definition
 * 
 * @throws ParsingException if the VariableDefinitionType is invalid
 */
public static VariableDefinition getInstance(Node root, PolicyMetaData metaData,
        VariableManager manager) throws ParsingException {
    String variableId = root.getAttributes().getNamedItem("VariableId").getNodeValue();

    // get the first element, which is the expression node
    NodeList nodes = root.getChildNodes();
    Node xprNode = nodes.item(0);
    int i = 1;
    while (xprNode.getNodeType() != Node.ELEMENT_NODE)
        xprNode = nodes.item(i++);

    // use that node to get the expression
    Expression xpr = ExpressionHandler.parseExpression(xprNode, metaData, manager);

    return new VariableDefinition(variableId, xpr);
}
 
Example #7
Source File: StatusDetail.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Private helper routine that converts text into a node
 * 
 * @param node
 * @return
 * @throws ParsingException
 */
private String nodeToText(Node node) throws ParsingException {

    StringWriter sw = new StringWriter();
    try {
        TransformerFactory factory = TransformerFactory.newInstance();
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
        Transformer transformer = factory.newTransformer();
        transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
        transformer.setOutputProperty(OutputKeys.INDENT, "yes");
        transformer.transform(new DOMSource(node), new StreamResult(sw));
    } catch (TransformerException te) {
        throw new ParsingException("invalid XML for status detail");
    }
    return sw.toString();
}
 
Example #8
Source File: ObligationExpressions.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * creates a <code>ObligationExpressions</code> based on its DOM node.
 *
 * @param root root the node to parse for the ObligationExpressions
 * @param metaData meta-date associated with the policy
 * @return  a new <code>ObligationExpressions</code> constructed by parsing
 * @throws ParsingException if the DOM node is invalid
 */
public static ObligationExpressions getInstance(Node root, PolicyMetaData metaData) throws ParsingException {

    Set<ObligationExpression> obligationExpressions = new HashSet<ObligationExpression>();

    NodeList children = root.getChildNodes();

    for(int i = 0; i < children.getLength(); i ++){
        Node child = children.item(i);
        if("ObligationExpression".equals(DOMHelper.getLocalName(child))){
            obligationExpressions.add(ObligationExpression.getInstance(child, metaData));    
        }
    }

    if(obligationExpressions.isEmpty()){
        throw new ParsingException("ObligationExpressions must contain at least one " +
                "ObligationExpression");            
    }

    return new ObligationExpressions(obligationExpressions);
}
 
Example #9
Source File: RequestCtxFactory.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 *  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);
    }
}
 
Example #10
Source File: VariableManager.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Private helper method to get the type of an expression, but only if that expression is an
 * Apply. Basically, if there is a circular reference, then we'll need to know the types before
 * we're done parsing one of the definitions. But, a circular reference that requires
 * type-checking can only happen if the definition's expression is an Apply. So, we look here,
 * and if it's an Apply, we get the type information and store that for later use, just in case.
 * <p>
 * Note that we could wait until later to try this, or we could check first to see if there will
 * be a circular reference. Comparatively, however, this isn't too expensive, and it makes the
 * system much simpler. Still, it's worth re-examining this to see if there's a way that makes
 * more sense.
 */
private void discoverApplyType(Node root, VariableState state) {
    // get the first element, which is the expression node
    NodeList nodes = root.getChildNodes();
    Node xprNode = nodes.item(0);
    int i = 1;
    while (xprNode.getNodeType() != Node.ELEMENT_NODE)
        xprNode = nodes.item(i++);

    // now see if the node is an Apply
    if (DOMHelper.getLocalName(xprNode).equals("Apply")) {
        try {
            // get the function in the Apply...
            Function function = ExpressionHandler.getFunction(xprNode, metaData,
                    FunctionFactory.getGeneralInstance());

            // ...and store the type information in the variable state
            state.type = function.getReturnType();
            state.returnsBag = function.returnsBag();
        } catch (ParsingException pe) {
            // we can just ignore this...if there really is an error,
            // then it will come up during parsing in a code path that
            // can handle the error cleanly
        }
    }
}
 
Example #11
Source File: CombinerParameter.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a new instance of the <code>CombinerParameter</code> class based on a DOM node. The
 * node must be the root of an XML CombinerParameterType.
 * 
 * @param root the DOM root of a CombinerParameterType XML type
 * 
 * @throws ParsingException if the CombinerParameterType is invalid
 * @return an instance of <code>CombinerParameter</code>
 */
public static CombinerParameter getInstance(Node root) throws ParsingException {
    // get the name, which is a required attribute
    String name = root.getAttributes().getNamedItem("ParameterName").getNodeValue();

    // get the attribute value, the only child of this element
    AttributeFactory attrFactory = Balana.getInstance().getAttributeFactory();
    AttributeValue value = null;

    try {
        value = attrFactory.createValue(root.getFirstChild());
    } catch (UnknownIdentifierException uie) {
        throw new ParsingException(uie.getMessage(), uie);
    }

    return new CombinerParameter(name, value);
}
 
Example #12
Source File: StatusDetail.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Constructor that uses a <code>List</code> of <code>MissingAttributeDetail</code>s to define the status
 * detail. This is a common form of detail data, and can be used for things like providing the
 * information included with the missing-attribute status code.
 * 
 * @param missingAttributeDetails a <code>List</code> of <code>MissingAttributeDetail</code>s
 * 
 * @throws IllegalArgumentException if there is a problem encoding the <code>MissingAttributeDetail</code>s
 */
public StatusDetail(List<MissingAttributeDetail> missingAttributeDetails)
                                                            throws IllegalArgumentException {

    this.missingAttributeDetails = missingAttributeDetails;
    try {
        detailText = "<StatusDetail>\n";

        for (MissingAttributeDetail attribute : missingAttributeDetails) {
            detailText += attribute.getEncoded() + "\n";
        }

        detailText += "</StatusDetail>";
    } catch (ParsingException pe) {
        // really, this should never happen, since we just made sure that
        // we're working with valid text, but it's possible that encoding
        // the attribute could have caused problems...

        throw new IllegalArgumentException("Invalid MissingAttributeDetail data, caused by " +
                                                                            pe.getMessage());
    }
}
 
Example #13
Source File: BaseFunctionFactory.java    From balana with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to get an instance of the specified abstract function.
 * 
 * @param identity the name of the function
 * @param root the DOM root containing info used to create the function
 * @param xpathVersion the version specified in the contianing policy, or null if no version was
 *            specified
 * 
 * @throws UnknownIdentifierException if the name isn't known
 * @throws FunctionTypeException if the name is known to map to a concrete function, and should
 *             therefore be created through createFunction
 * @throws ParsingException if the function can't be created with the given inputs
 */
public Function createAbstractFunction(String identity, Node root, String xpathVersion)
        throws UnknownIdentifierException, ParsingException, FunctionTypeException {
    Object entry = functionMap.get(identity);

    if (entry != null) {
        if (entry instanceof FunctionProxy) {
            try {
                return ((FunctionProxy) entry).getInstance(root, xpathVersion);
            } catch (Exception e) {
                throw new ParsingException(
                        "couldn't create abstract" + " function " + identity, e);
            }
        } else {
            // this is actually a concrete function, which means that
            // the other create method should have been called
            throw new FunctionTypeException("function is concrete");
        }
    } else {
        // we couldn't find a match
        throw new UnknownIdentifierException("abstract functions of " + "type " + identity
                + " are not supported by " + "this factory");
    }
}
 
Example #14
Source File: Status.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new instance of <code>Status</code> based on the given DOM root node. A
 * <code>ParsingException</code> is thrown if the DOM root doesn't represent a valid StatusType.
 * 
 * @param root the DOM root of a StatusType
 *
 * @return a new <code>Status</code>
 * 
 * @throws ParsingException if the node is invalid
 */
public static Status getInstance(Node root) throws ParsingException {

    List<String> code = null;
    String message = null;
    StatusDetail detail = null;

    NodeList nodes = root.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        String name = DOMHelper.getLocalName(node);

        if (name.equals("StatusCode")) {
            code = parseStatusCode(node);
        } else if (name.equals("StatusMessage")) {
            message = node.getFirstChild().getNodeValue();
        } else if (name.equals("StatusDetail")) {
            detail = StatusDetail.getInstance(node);
        }
    }

    if(code == null){
        throw new ParsingException("Missing required element StatusCode in StatusType");
    }

    return new Status(code, message, detail);
}
 
Example #15
Source File: PolicyReader.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param doc
 * @return
 * @throws ParsingException
 */
private AbstractPolicy handleDocument(Document doc) throws ParsingException {
    // handle the policy, if it's a known type
    Element root = doc.getDocumentElement();
    String name = root.getLocalName();
    // see what type of policy this is
    if (name.equals("Policy")) {
        return Policy.getInstance(root);
    } else if (name.equals("PolicySet")) {
        return PolicySet.getInstance(root, policyFinder);
    } else {
        // this isn't a root type that we know how to handle
        throw new ParsingException("Unknown root document type: " + name);
    }
}
 
Example #16
Source File: BalanaPRP.java    From mobi with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public List<BalanaPolicy> findPolicies(Request request) throws ProcessingException, PolicySyntaxException {
    try {
        AbstractRequestCtx requestCtx = RequestCtxFactory.getFactory().getRequestCtx(request.toString());
        EvaluationCtx context = EvaluationCtxFactory.getFactory().getEvaluationCtx(requestCtx, config);
        return findMatchingPolicies(context);
    } catch (ParsingException e) {
        throw new MobiException(e);
    }
}
 
Example #17
Source File: EvaluationCtxFactory.java    From balana with Apache License 2.0 5 votes vote down vote up
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);
    }
}
 
Example #18
Source File: PAPPolicyReader.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param doc
 * @return
 * @throws org.wso2.balana.ParsingException
 */
private AbstractPolicy handleDocument(Document doc) throws ParsingException {
    // handle the policy, if it's a known type
    Element root = doc.getDocumentElement();
    String name = root.getLocalName();
    // see what type of policy this is
    if (name.equals("Policy")) {
        return Policy.getInstance(root);
    } else if (name.equals("PolicySet")) {
        return PolicySet.getInstance(root, policyFinder);
    } else {
        // this isn't a root type that we know how to handle
        throw new ParsingException("Unknown root document type: " + name);
    }
}
 
Example #19
Source File: StatusDetail.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Private constructor that just sets the root node. This interface is provided publically
 * through the getInstance method.
 *
 * @param root  the DOM root of StatusDetail element
 */
private StatusDetail(Node root) {
    try{
        detailText = nodeToText(root);
    } catch (ParsingException e) {
        // just ignore as this is not a must to convert this to text
    }
}
 
Example #20
Source File: PolicyReader.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * @param doc
 * @return
 * @throws ParsingException
 */
private AbstractPolicy handleDocument(Document doc) throws ParsingException {
    // handle the policy, if it's a known type
    Element root = doc.getDocumentElement();
    String name = root.getLocalName();
    // see what type of policy this is
    if (name.equals("Policy")) {
        return Policy.getInstance(root);
    } else if (name.equals("PolicySet")) {
        return PolicySet.getInstance(root, policyFinder);
    } else {
        // this isn't a root type that we know how to handle
        throw new ParsingException("Unknown root document type: " + name);
    }
}
 
Example #21
Source File: PDPController.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Evaluates the request which was created based on KMarket sample.
 *
 * @param request is going to be converted to XACML Request.
 * @return        result of the Policy Decision Point.
 * */
@PostMapping("/evaluate")
public ResponseObject evaluate(@RequestBody RequestObject request)
{
    int totalAmount = 0;
    Utilities.initData();
    Utilities.initBalana();

    totalAmount = Utilities.calculateTotal(request.getProductName(), request.getNumberOfProducts());
    String xacmlRequest = Utilities.createXACMLRequest(
            request.getUsername(), request.getProductName(), request.getNumberOfProducts(), totalAmount);

    PDP pdp = Utilities.getPDPNewInstance();
    String xacmlResponse = pdp.evaluate(xacmlRequest); //evaluates XACML request here.
    String responseMessage = "";

    try {
        ResponseCtx responseCtx = ResponseCtx.getInstance(Utilities.getXacmlResponse(xacmlResponse));
        AbstractResult result  = responseCtx.getResults().iterator().next();
        if(AbstractResult.DECISION_PERMIT == result.getDecision()){
            responseMessage = "\n" + request.getUsername() + " is authorized to perform this purchase\n\n";
        } else {
            //if it is not PERMIT, DENY is going to be returned to client user.
            responseMessage += "\n" + request.getUsername() + " is NOT authorized to perform this purchase\n";
            List<Advice> advices = result.getAdvices();
            for(Advice advice : advices){
                List<AttributeAssignment> assignments = advice.getAssignments();
                for(AttributeAssignment assignment : assignments){
                    responseMessage += "Advice :  " + assignment.getContent() +"\n\n";
                }
            }
        }
    } catch (ParsingException e) {
        e.printStackTrace();
    }
    return new ResponseObject(responseMessage);
}
 
Example #22
Source File: BooleanAttribute.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a <code>BooleanAttribute</code> that represents the xs:boolean value indicated by the
 * string provided.
 * 
 * @param value a string representing the desired value
 * @return a <code>BooleanAttribute</code> representing the appropriate value (null if there is
 *         a parsing error)
 */
public static BooleanAttribute getInstance(String value) throws ParsingException {
    // Shouldn't happen, but just in case...
    if (earlyException != null)
        throw earlyException;

    if (value.equals("true"))
        return trueInstance;
    if (value.equals("false"))
        return falseInstance;

    throw new ParsingException("Boolean string must be true or false");
}
 
Example #23
Source File: PAPPolicyReader.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
/**
 * @param doc
 * @return
 * @throws org.wso2.balana.ParsingException
 */
private AbstractPolicy handleDocument(Document doc) throws ParsingException {
    // handle the policy, if it's a known type
    Element root = doc.getDocumentElement();
    String name = root.getLocalName();
    // see what type of policy this is
    if (name.equals("Policy")) {
        return Policy.getInstance(root);
    } else if (name.equals("PolicySet")) {
        return PolicySet.getInstance(root, policyFinder);
    } else {
        // this isn't a root type that we know how to handle
        throw new ParsingException("Unknown root document type: " + name);
    }
}
 
Example #24
Source File: RequestCtx.java    From balana with Apache License 2.0 5 votes vote down vote up
private static Set<Attribute> parseAttributes(Node root) throws ParsingException {
    Set<Attribute> set = new HashSet<Attribute>();

    // the Environment section is just a list of Attributes
    NodeList nodes = root.getChildNodes();
    for (int i = 0; i < nodes.getLength(); i++) {
        Node node = nodes.item(i);
        if (DOMHelper.getLocalName(node).equals("Attribute"))
            set.add(Attribute.getInstance(node, XACMLConstants.XACML_VERSION_2_0));
    }

    return set;
}
 
Example #25
Source File: HexBinaryAttribute.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new <code>HexBinaryAttribute</code> that represents the xsi:hexBinary value
 * indicated by the string provided.
 * 
 * @param value a string representing the desired value
 * @return a new <code>HexBinaryAttribute</code> representing the desired value
 * @exception ParsingException if a parsing error occurs
 */
public static HexBinaryAttribute getInstance(String value) throws ParsingException {
    byte[] bytes = hexToBin(value);

    if (bytes == null)
        throw new ParsingException("Couldn't parse purported " + "hex string: " + value);

    return new HexBinaryAttribute(bytes);
}
 
Example #26
Source File: AttributeSelectorFactory.java    From balana with Apache License 2.0 5 votes vote down vote up
public AbstractAttributeSelector getAbstractSelector(Node root, PolicyMetaData metaData)
                                                                    throws ParsingException {

    if(metaData.getXACMLVersion() == XACMLConstants.XACML_VERSION_3_0){
        return org.wso2.balana.attr.xacml3.AttributeSelector.getInstance(root, metaData);
    } else {
        return org.wso2.balana.attr.AttributeSelector.getInstance(root, metaData);
    }
}
 
Example #27
Source File: AttributeDesignatorFactory.java    From balana with Apache License 2.0 5 votes vote down vote up
public AbstractDesignator getAbstractDesignator(Node root, PolicyMetaData metaData)
                                                                    throws ParsingException {

    if(metaData.getXACMLVersion() == XACMLConstants.XACML_VERSION_3_0){
        return AttributeDesignator.getInstance(root);
    } else {
        return org.wso2.balana.attr.AttributeDesignator.getInstance(root);
    }
}
 
Example #28
Source File: Base64BinaryAttribute.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new <code>Base64BinaryAttribute</code> that represents the xsi:base64Binary value
 * indicated by the string provided.
 * 
 * @param value a string representing the desired value
 * @return a new <code>Base64BinaryAttribute</code> representing the desired value
 * @exception ParsingException if a parsing error occurs
 */
public static Base64BinaryAttribute getInstance(String value) throws ParsingException {
    byte[] bytes = null;

    try {
        bytes = Base64.decode(value, false);
    } catch (IOException e) {
        throw new ParsingException("Couldn't parse purported " + "Base64 string: " + value, e);
    }

    return new Base64BinaryAttribute(bytes);
}
 
Example #29
Source File: IPAddressAttribute.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new <code>IPAddressAttribute</code> that represents the name indicated by the
 * <code>String</code> provided.
 * 
 * @param value a string representing the address
 * 
 * @return a new <code>IPAddressAttribute</code>
 * 
 * @throws ParsingException if any of the address components is invalid
 */
public static IPAddressAttribute getInstance(String value) throws ParsingException {
    try {
        // an IPv6 address starts with a '['
        if (value.indexOf('[') == 0)
            return IPv6AddressAttribute.getV6Instance(value);
        else
            return IPv4AddressAttribute.getV4Instance(value);
    } catch (UnknownHostException uhe) {
        throw new ParsingException("Failed to parse an IPAddress", uhe);
    }
}
 
Example #30
Source File: DNSNameAttribute.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a new <code>DNSNameAttribute</code> that represents the name indicated by the
 * <code>String</code> provided.
 * 
 * @param value a string representing the name
 * 
 * @return a new <code>DNSNameAttribute</code>
 * 
 * @throws ParsingException if the hostname is invalid
 */
public static DNSNameAttribute getInstance(String value) throws ParsingException {
    int portSep = value.indexOf(':');

    if (portSep == -1) {
        // there is no port range, so just use the name
        return new DNSNameAttribute(value);
    } else {
        // split the name and the port range
        String hostname = value.substring(0, portSep);
        PortRange range = PortRange.getInstance(value.substring(portSep + 1, value.length()));
        return new DNSNameAttribute(hostname, range);
    }
}