org.wso2.balana.Balana Java Examples

The following examples show how to use org.wso2.balana.Balana. 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: JSONRequestParser.java    From carbon-identity-framework with Apache License 2.0 6 votes vote down vote up
/**
 * Private methods constructing a Balana <code>{@link AttributeValue}</code> from given parameters
 *
 * @param value          <code>String</code> with the actual value of the Attribute
 * @param dataType       <code>URI</code> of the DataType of the value
 * @param parentDataType <code>URI</code> of the DataType of <code>{@link Attribute}</code> this belongs to
 * @return <code>{@link AttributeValue}</code>
 * @throws UnknownIdentifierException
 */
private static AttributeValue getAttributeValue(String value, URI dataType, URI parentDataType)
        throws UnknownIdentifierException {
    URI type = dataType;
    AttributeValue attributeValue = null;

    //check if dataType attribute is set, if not use the parent data type
    if (dataType == null) {
        type = parentDataType;
    }

    try {
        attributeValue = Balana.getInstance().getAttributeFactory().createValue(type, value);
    } catch (Exception e) {
        throw new UnknownIdentifierException();
    }
    return attributeValue;
}
 
Example #2
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 #3
Source File: EntitlementUtil.java    From carbon-identity-framework with Apache License 2.0 5 votes vote down vote up
public static Attributes getAttributes(AttributeDTO attributeDataDTO) {

        try {
            AttributeValue value = Balana.getInstance().getAttributeFactory().
                    createValue(new URI(attributeDataDTO.getAttributeDataType()),
                            attributeDataDTO.getAttributeValue());
            Attribute attribute = new Attribute(new URI(attributeDataDTO.getAttributeId()),
                    null, null, value, XACMLConstants.XACML_VERSION_3_0);
            Set<Attribute> set = new HashSet<Attribute>();
            set.add(attribute);
            String category = attributeDataDTO.getCategory();
            // We are only creating XACML 3.0 requests Therefore covert order XACML categories to new uris
            if (PDPConstants.SUBJECT_ELEMENT.equals(category)) {
                category = PDPConstants.SUBJECT_CATEGORY_URI;
            } else if (PDPConstants.RESOURCE_ELEMENT.equals(category)) {
                category = PDPConstants.RESOURCE_CATEGORY_URI;
            } else if (PDPConstants.ACTION_ELEMENT.equals(category)) {
                category = PDPConstants.ACTION_CATEGORY_URI;
            } else if (PDPConstants.ENVIRONMENT_ELEMENT.equals(category)) {
                category = PDPConstants.ENVIRONMENT_CATEGORY_URI;
            }
            return new Attributes(new URI(category), set);
        } catch (Exception e) {
            log.debug(e);
            //ignore and return null;
        }

        return null;
    }
 
Example #4
Source File: EntitlementUtil.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
public static Attributes getAttributes(AttributeDTO attributeDataDTO) {

        try {
            AttributeValue value = Balana.getInstance().getAttributeFactory().
                    createValue(new URI(attributeDataDTO.getAttributeDataType()),
                            attributeDataDTO.getAttributeValue());
            Attribute attribute = new Attribute(new URI(attributeDataDTO.getAttributeId()),
                    null, null, value, XACMLConstants.XACML_VERSION_3_0);
            Set<Attribute> set = new HashSet<Attribute>();
            set.add(attribute);
            String category = attributeDataDTO.getCategory();
            // We are only creating XACML 3.0 requests Therefore covert order XACML categories to new uris
            if (PDPConstants.SUBJECT_ELEMENT.equals(category)) {
                category = PDPConstants.SUBJECT_CATEGORY_URI;
            } else if (PDPConstants.RESOURCE_ELEMENT.equals(category)) {
                category = PDPConstants.RESOURCE_CATEGORY_URI;
            } else if (PDPConstants.ACTION_ELEMENT.equals(category)) {
                category = PDPConstants.ACTION_CATEGORY_URI;
            } else if (PDPConstants.ENVIRONMENT_ELEMENT.equals(category)) {
                category = PDPConstants.ENVIRONMENT_CATEGORY_URI;
            }
            return new Attributes(new URI(category), set);
        } catch (Exception e) {
            log.debug(e);
            //ignore and return null;
        }

        return null;
    }
 
Example #5
Source File: Utilities.java    From balana with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize the balana instance..
 * */
protected static void initBalana(){
    try{
        // using file based policy repository. so set the policy location as system property
        String policyLocation = (new File(".")).getCanonicalPath() + File.separator + "resources";
        System.setProperty(FileBasedPolicyFinderModule.POLICY_DIR_PROPERTY, policyLocation);
    } catch (IOException e) {
        System.err.println("Can not locate policy repository");
    }
    // create default instance of Balana
    balana = Balana.getInstance();
}
 
Example #6
Source File: KMarketAccessControl.java    From balana with Apache License 2.0 5 votes vote down vote up
private static void initBalana(){

        try{
            // using file based policy repository. so set the policy location as system property
            String policyLocation = (new File(".")).getCanonicalPath() + File.separator + "resources";
            System.setProperty(FileBasedPolicyFinderModule.POLICY_DIR_PROPERTY, policyLocation);
        } catch (IOException e) {
            System.err.println("Can not locate policy repository");
        }
        // create default instance of Balana
        balana = Balana.getInstance();
    }
 
Example #7
Source File: BalanaPDP.java    From mobi with GNU Affero General Public License v3.0 4 votes vote down vote up
@Activate
public void setUp() throws Exception {
    this.balana = Balana.getInstance();
    this.jaxbContext = JAXBContext.newInstance("com.mobi.security.policy.api.xacml.jaxb",
            com.mobi.security.policy.api.xacml.jaxb.ObjectFactory.class.getClassLoader());
}