Java Code Examples for com.sun.xml.internal.ws.policy.privateutil.PolicyUtils

The following examples show how to use com.sun.xml.internal.ws.policy.privateutil.PolicyUtils. 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
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
public StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("reference data {").append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("referenced policy model URI = '").append(referencedModelUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
    if (digest == null) {
        buffer.append(innerIndent).append("no digest specified").append(PolicyUtils.Text.NEW_LINE);
    } else {
        buffer.append(innerIndent).append("digest algorith URI = '").append(digestAlgorithmUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
        buffer.append(innerIndent).append("digest = '").append(digest).append('\'').append(PolicyUtils.Text.NEW_LINE);
    }
    buffer.append(indent).append('}');

    return buffer;
}
 
Example 2
Source Project: TencentKona-8   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = NamespaceVersion.getLatestVersion();
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 3
Source Project: TencentKona-8   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param nsVersion Policy namespace version to be used when marshalling the policy expression
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final NamespaceVersion nsVersion, final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = nsVersion;
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 4
private boolean readExternalFile(final String fileUrl) {
    InputStream ios = null;
    XMLStreamReader reader = null;
    try {
        final URL xmlURL = new URL(fileUrl);
        ios = xmlURL.openStream();
        reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
        while (reader.hasNext()) {
            if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
                readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
            }
            reader.next();
        }
        return true;
    } catch (IOException ioe) {
        return false;
    } catch (XMLStreamException xmlse) {
        return false;
    } finally {
        PolicyUtils.IO.closeResource(reader);
        PolicyUtils.IO.closeResource(ios);
    }
}
 
Example 5
Source Project: TencentKona-8   Source File: AssertionSet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("assertion set {").append(PolicyUtils.Text.NEW_LINE);

    if (assertions.isEmpty()) {
        buffer.append(innerIndent).append("no assertions").append(PolicyUtils.Text.NEW_LINE);
    } else {
        for (PolicyAssertion assertion : assertions) {
            assertion.toString(indentLevel + 1, buffer).append(PolicyUtils.Text.NEW_LINE);
        }
    }

    buffer.append(indent).append('}');

    return buffer;
}
 
Example 6
Source Project: jdk8u60   Source File: PolicyReferenceData.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
public StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("reference data {").append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("referenced policy model URI = '").append(referencedModelUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
    if (digest == null) {
        buffer.append(innerIndent).append("no digest specified").append(PolicyUtils.Text.NEW_LINE);
    } else {
        buffer.append(innerIndent).append("digest algorith URI = '").append(digestAlgorithmUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
        buffer.append(innerIndent).append("digest = '").append(digest).append('\'').append(PolicyUtils.Text.NEW_LINE);
    }
    buffer.append(indent).append('}');

    return buffer;
}
 
Example 7
Source Project: jdk8u60   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = NamespaceVersion.getLatestVersion();
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 8
Source Project: jdk8u60   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param nsVersion Policy namespace version to be used when marshalling the policy expression
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final NamespaceVersion nsVersion, final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = nsVersion;
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 9
private boolean readExternalFile(final String fileUrl) {
    InputStream ios = null;
    XMLStreamReader reader = null;
    try {
        final URL xmlURL = new URL(fileUrl);
        ios = xmlURL.openStream();
        reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
        while (reader.hasNext()) {
            if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
                readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
            }
            reader.next();
        }
        return true;
    } catch (IOException ioe) {
        return false;
    } catch (XMLStreamException xmlse) {
        return false;
    } finally {
        PolicyUtils.IO.closeResource(reader);
        PolicyUtils.IO.closeResource(ios);
    }
}
 
Example 10
Source Project: jdk8u60   Source File: AssertionSet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("assertion set {").append(PolicyUtils.Text.NEW_LINE);

    if (assertions.isEmpty()) {
        buffer.append(innerIndent).append("no assertions").append(PolicyUtils.Text.NEW_LINE);
    } else {
        for (PolicyAssertion assertion : assertions) {
            assertion.toString(indentLevel + 1, buffer).append(PolicyUtils.Text.NEW_LINE);
        }
    }

    buffer.append(indent).append('}');

    return buffer;
}
 
Example 11
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
public StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("reference data {").append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("referenced policy model URI = '").append(referencedModelUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
    if (digest == null) {
        buffer.append(innerIndent).append("no digest specified").append(PolicyUtils.Text.NEW_LINE);
    } else {
        buffer.append(innerIndent).append("digest algorith URI = '").append(digestAlgorithmUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
        buffer.append(innerIndent).append("digest = '").append(digest).append('\'').append(PolicyUtils.Text.NEW_LINE);
    }
    buffer.append(indent).append('}');

    return buffer;
}
 
Example 12
Source Project: openjdk-jdk8u   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = NamespaceVersion.getLatestVersion();
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 13
Source Project: openjdk-jdk8u   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param nsVersion Policy namespace version to be used when marshalling the policy expression
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final NamespaceVersion nsVersion, final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = nsVersion;
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 14
private boolean readExternalFile(final String fileUrl) {
    InputStream ios = null;
    XMLStreamReader reader = null;
    try {
        final URL xmlURL = new URL(fileUrl);
        ios = xmlURL.openStream();
        reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
        while (reader.hasNext()) {
            if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
                readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
            }
            reader.next();
        }
        return true;
    } catch (IOException ioe) {
        return false;
    } catch (XMLStreamException xmlse) {
        return false;
    } finally {
        PolicyUtils.IO.closeResource(reader);
        PolicyUtils.IO.closeResource(ios);
    }
}
 
Example 15
Source Project: openjdk-jdk8u   Source File: AssertionSet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("assertion set {").append(PolicyUtils.Text.NEW_LINE);

    if (assertions.isEmpty()) {
        buffer.append(innerIndent).append("no assertions").append(PolicyUtils.Text.NEW_LINE);
    } else {
        for (PolicyAssertion assertion : assertions) {
            assertion.toString(indentLevel + 1, buffer).append(PolicyUtils.Text.NEW_LINE);
        }
    }

    buffer.append(indent).append('}');

    return buffer;
}
 
Example 16
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
public StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("reference data {").append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("referenced policy model URI = '").append(referencedModelUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
    if (digest == null) {
        buffer.append(innerIndent).append("no digest specified").append(PolicyUtils.Text.NEW_LINE);
    } else {
        buffer.append(innerIndent).append("digest algorith URI = '").append(digestAlgorithmUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
        buffer.append(innerIndent).append("digest = '").append(digest).append('\'').append(PolicyUtils.Text.NEW_LINE);
    }
    buffer.append(indent).append('}');

    return buffer;
}
 
Example 17
Source Project: openjdk-jdk8u-backup   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = NamespaceVersion.getLatestVersion();
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 18
Source Project: openjdk-jdk8u-backup   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param nsVersion Policy namespace version to be used when marshalling the policy expression
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final NamespaceVersion nsVersion, final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = nsVersion;
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 19
private boolean readExternalFile(final String fileUrl) {
    InputStream ios = null;
    XMLStreamReader reader = null;
    try {
        final URL xmlURL = new URL(fileUrl);
        ios = xmlURL.openStream();
        reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
        while (reader.hasNext()) {
            if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
                readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
            }
            reader.next();
        }
        return true;
    } catch (IOException ioe) {
        return false;
    } catch (XMLStreamException xmlse) {
        return false;
    } finally {
        PolicyUtils.IO.closeResource(reader);
        PolicyUtils.IO.closeResource(ios);
    }
}
 
Example 20
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("assertion set {").append(PolicyUtils.Text.NEW_LINE);

    if (assertions.isEmpty()) {
        buffer.append(innerIndent).append("no assertions").append(PolicyUtils.Text.NEW_LINE);
    } else {
        for (PolicyAssertion assertion : assertions) {
            assertion.toString(indentLevel + 1, buffer).append(PolicyUtils.Text.NEW_LINE);
        }
    }

    buffer.append(indent).append('}');

    return buffer;
}
 
Example 21
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
public StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("reference data {").append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("referenced policy model URI = '").append(referencedModelUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
    if (digest == null) {
        buffer.append(innerIndent).append("no digest specified").append(PolicyUtils.Text.NEW_LINE);
    } else {
        buffer.append(innerIndent).append("digest algorith URI = '").append(digestAlgorithmUri).append('\'').append(PolicyUtils.Text.NEW_LINE);
        buffer.append(innerIndent).append("digest = '").append(digest).append('\'').append(PolicyUtils.Text.NEW_LINE);
    }
    buffer.append(indent).append('}');

    return buffer;
}
 
Example 22
Source Project: openjdk-jdk9   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = NamespaceVersion.getLatestVersion();
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 23
Source Project: openjdk-jdk9   Source File: Policy.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * Constructor that should be overridden by child implementation. The constructor allows for easy toString() output
 * customization.
 *
 * @param nsVersion Policy namespace version to be used when marshalling the policy expression
 * @param toStringName a general name of the object (such as 'policy' or 'nested policy') that will be used in the
 * toString() method to identify the object.
 * @param sets represents the collection of policy alternatives of the policy object created. During the creation of
 * the new policy object, the content of the alternatives collection is copied into an internal policy object structure,
 * thus any subsequent operations on the collection will have no impact on the newly constructed policy object. The
 * collection may be {@code null} or empty. In such case a 'NULL' policy object is constructed.
 */
Policy(final NamespaceVersion nsVersion, final String toStringName, final Collection<AssertionSet> sets) {
    this.nsVersion = nsVersion;
    this.toStringName = toStringName;

    if (sets == null || sets.isEmpty()) {
        this.assertionSets = NULL_POLICY_ASSERTION_SETS;
        this.vocabulary = EMPTY_VOCABULARY;
        this.immutableVocabulary = EMPTY_VOCABULARY;
    } else {
        this.assertionSets = new LinkedList<AssertionSet>();
        this.vocabulary = new TreeSet<QName>(PolicyUtils.Comparison.QNAME_COMPARATOR);
        this.immutableVocabulary = Collections.unmodifiableCollection(this.vocabulary);

        addAll(sets);
    }
}
 
Example 24
private boolean readExternalFile(final String fileUrl) {
    InputStream ios = null;
    XMLStreamReader reader = null;
    try {
        final URL xmlURL = new URL(fileUrl);
        ios = xmlURL.openStream();
        reader = XmlUtil.newXMLInputFactory(true).createXMLStreamReader(ios);
        while (reader.hasNext()) {
            if (reader.isStartElement() && NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {
                readSinglePolicy(policyReader.readPolicyElement(reader, fileUrl), false);
            }
            reader.next();
        }
        return true;
    } catch (IOException ioe) {
        return false;
    } catch (XMLStreamException xmlse) {
        return false;
    } finally {
        PolicyUtils.IO.closeResource(reader);
        PolicyUtils.IO.closeResource(ios);
    }
}
 
Example 25
Source Project: openjdk-jdk9   Source File: AssertionSet.java    License: GNU General Public License v2.0 6 votes vote down vote up
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("assertion set {").append(PolicyUtils.Text.NEW_LINE);

    if (assertions.isEmpty()) {
        buffer.append(innerIndent).append("no assertions").append(PolicyUtils.Text.NEW_LINE);
    } else {
        for (PolicyAssertion assertion : assertions) {
            assertion.toString(indentLevel + 1, buffer).append(PolicyUtils.Text.NEW_LINE);
        }
    }

    buffer.append(indent).append('}');

    return buffer;
}
 
Example 26
Source Project: TencentKona-8   Source File: PolicySubject.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);

    buffer.append(indent).append("policy subject {").append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("subject = '").append(subject).append('\'').append(PolicyUtils.Text.NEW_LINE);
    for (Policy policy : policies) {
        policy.toString(indentLevel + 1, buffer).append(PolicyUtils.Text.NEW_LINE);
    }
    buffer.append(indent).append('}');

    return buffer;
}
 
Example 27
/**
 * Method creates policy alternatives according to provided model. The model structure is modified in the process.
 *
 * @return created policy alternatives resulting from policy source model.
 */
private Collection<AssertionSet> createPolicyAlternatives(final PolicySourceModel model) throws PolicyException {
    // creating global method variables
    final ContentDecomposition decomposition = new ContentDecomposition();

    // creating processing queue and starting the processing iterations
    final Queue<RawPolicy> policyQueue = new LinkedList<RawPolicy>();
    final Queue<Collection<ModelNode>> contentQueue = new LinkedList<Collection<ModelNode>>();

    final RawPolicy rootPolicy = new RawPolicy(model.getRootNode(), new LinkedList<RawAlternative>());
    RawPolicy processedPolicy = rootPolicy;
    do {
        Collection<ModelNode> processedContent = processedPolicy.originalContent;
        do {
            decompose(processedContent, decomposition);
            if (decomposition.exactlyOneContents.isEmpty()) {
                final RawAlternative alternative = new RawAlternative(decomposition.assertions);
                processedPolicy.alternatives.add(alternative);
                if (!alternative.allNestedPolicies.isEmpty()) {
                    policyQueue.addAll(alternative.allNestedPolicies);
                }
            } else { // we have a non-empty collection of exactly ones
                final Collection<Collection<ModelNode>> combinations = PolicyUtils.Collections.combine(decomposition.assertions, decomposition.exactlyOneContents, false);
                if (combinations != null && !combinations.isEmpty()) {
                    // processed alternative was split into some new alternatives, which we need to process
                    contentQueue.addAll(combinations);
                }
            }
        } while ((processedContent = contentQueue.poll()) != null);
    } while ((processedPolicy = policyQueue.poll()) != null);

    // normalize nested policies to contain single alternative only
    final Collection<AssertionSet> assertionSets = new LinkedList<AssertionSet>();
    for (RawAlternative rootAlternative : rootPolicy.alternatives) {
        final Collection<AssertionSet> normalizedAlternatives = normalizeRawAlternative(rootAlternative);
        assertionSets.addAll(normalizedAlternatives);
    }

    return assertionSets;
}
 
Example 28
private List<AssertionSet> normalizeRawAlternative(final RawAlternative alternative) throws AssertionCreationException, PolicyException {
    final List<PolicyAssertion> normalizedContentBase = new LinkedList<PolicyAssertion>();
    final Collection<List<PolicyAssertion>> normalizedContentOptions = new LinkedList<List<PolicyAssertion>>();
    if (!alternative.nestedAssertions.isEmpty()) {
        final Queue<RawAssertion> nestedAssertionsQueue = new LinkedList<RawAssertion>(alternative.nestedAssertions);
        RawAssertion rawAssertion;
        while((rawAssertion = nestedAssertionsQueue.poll()) != null) {
            final List<PolicyAssertion> normalized = normalizeRawAssertion(rawAssertion);
            // if there is only a single result, we can add it direclty to the content base collection
            // more elements in the result indicate that we will have to create combinations
            if (normalized.size() == 1) {
                normalizedContentBase.addAll(normalized);
            } else {
                normalizedContentOptions.add(normalized);
            }
        }
    }

    final List<AssertionSet> options = new LinkedList<AssertionSet>();
    if (normalizedContentOptions.isEmpty()) {
        // we do not have any options to combine => returning this assertion
        options.add(AssertionSet.createAssertionSet(normalizedContentBase));
    } else {
        // we have some options to combine => creating assertion options based on content combinations
        final Collection<Collection<PolicyAssertion>> contentCombinations = PolicyUtils.Collections.combine(normalizedContentBase, normalizedContentOptions, true);
        for (Collection<PolicyAssertion> contentOption : contentCombinations) {
            options.add(AssertionSet.createAssertionSet(contentOption));
        }
    }
    return options;
}
 
Example 29
/**
 * Returns a string representation of the object. In general, the <code>toString</code> method
 * returns a string that "textually represents" this object.
 *
 * @return  a string representation of the object.
 */
@Override
public String toString() {
    final String innerIndent = PolicyUtils.Text.createIndent(1);
    final StringBuffer buffer = new StringBuffer(60);

    buffer.append("Policy source model {").append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("policy id = '").append(policyId).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("policy name = '").append(policyName).append('\'').append(PolicyUtils.Text.NEW_LINE);
    rootNode.toString(1, buffer).append(PolicyUtils.Text.NEW_LINE).append('}');

    return buffer.toString();
}
 
Example 30
Source Project: TencentKona-8   Source File: AssertionData.java    License: GNU General Public License v2.0 5 votes vote down vote up
/**
 * A helper method that appends indented string representation of this instance to the input string buffer.
 *
 * @param indentLevel indentation level to be used.
 * @param buffer buffer to be used for appending string representation of this instance
 * @return modified buffer containing new string representation of the instance
 */
public StringBuffer toString(final int indentLevel, final StringBuffer buffer) {
    final String indent = PolicyUtils.Text.createIndent(indentLevel);
    final String innerIndent = PolicyUtils.Text.createIndent(indentLevel + 1);
    final String innerDoubleIndent = PolicyUtils.Text.createIndent(indentLevel + 2);

    buffer.append(indent);
    if (type == ModelNode.Type.ASSERTION) {
        buffer.append("assertion data {");
    } else {
        buffer.append("assertion parameter data {");
    }
    buffer.append(PolicyUtils.Text.NEW_LINE);

    buffer.append(innerIndent).append("namespace = '").append(name.getNamespaceURI()).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("prefix = '").append(name.getPrefix()).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("local name = '").append(name.getLocalPart()).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("value = '").append(value).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("optional = '").append(optional).append('\'').append(PolicyUtils.Text.NEW_LINE);
    buffer.append(innerIndent).append("ignorable = '").append(ignorable).append('\'').append(PolicyUtils.Text.NEW_LINE);
    synchronized (attributes) {
        if (attributes.isEmpty()) {
            buffer.append(innerIndent).append("no attributes");
        } else {

            buffer.append(innerIndent).append("attributes {").append(PolicyUtils.Text.NEW_LINE);
            for(Map.Entry<QName, String> entry : attributes.entrySet()) {
                final QName aName = entry.getKey();
                buffer.append(innerDoubleIndent).append("name = '").append(aName.getNamespaceURI()).append(':').append(aName.getLocalPart());
                buffer.append("', value = '").append(entry.getValue()).append('\'').append(PolicyUtils.Text.NEW_LINE);
            }
            buffer.append(innerIndent).append('}');
        }
    }

    buffer.append(PolicyUtils.Text.NEW_LINE).append(indent).append('}');

    return buffer;
}