com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion Java Examples

The following examples show how to use com.sun.xml.internal.ws.policy.sourcemodel.wspolicy.NamespaceVersion. 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: PolicyWSDLParserExtension.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean definitionsElements(final XMLStreamReader reader){
    LOGGER.entering();
    if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {     // Only "Policy" element interests me
        readSinglePolicy(
                policyReader.readPolicyElement(
                reader,
                (null == reader.getLocation().getSystemId()) ? // baseUrl
                    "" : reader.getLocation().getSystemId()),
                false);
        LOGGER.exiting();
        return true;
    }
    LOGGER.exiting();
    return false;
}
 
Example #2
Source File: Policy.java    From TencentKona-8 with 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 #3
Source File: SafePolicyReader.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reads policy reference element <wsp:PolicyReference/> and returns referenced policy URI as String
 *
 * @param reader The XMLStreamReader should be in START_ELEMENT state and point to the PolicyReference element.
 * @return The URI contained in the PolicyReference
 */
public String readPolicyReferenceElement(final XMLStreamReader reader) {
    try {
        if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.PolicyReference) {     // "PolicyReference" element interests me
            for (int i = 0; i < reader.getAttributeCount(); i++) {
                if (XmlToken.resolveToken(reader.getAttributeName(i).getLocalPart()) == XmlToken.Uri) {
                    final String uriValue = reader.getAttributeValue(i);
                    reader.next();
                    return uriValue;
                }
            }
        }
        reader.next();
        return null;
    } catch(XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1001_XML_EXCEPTION_WHEN_PROCESSING_POLICY_REFERENCE(), e));
    }
}
 
Example #4
Source File: PolicyWSDLParserExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean definitionsElements(final XMLStreamReader reader){
    LOGGER.entering();
    if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {     // Only "Policy" element interests me
        readSinglePolicy(
                policyReader.readPolicyElement(
                reader,
                (null == reader.getLocation().getSystemId()) ? // baseUrl
                    "" : reader.getLocation().getSystemId()),
                false);
        LOGGER.exiting();
        return true;
    }
    LOGGER.exiting();
    return false;
}
 
Example #5
Source File: PolicyWSDLParserExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean definitionsElements(final XMLStreamReader reader){
    LOGGER.entering();
    if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {     // Only "Policy" element interests me
        readSinglePolicy(
                policyReader.readPolicyElement(
                reader,
                (null == reader.getLocation().getSystemId()) ? // baseUrl
                    "" : reader.getLocation().getSystemId()),
                false);
        LOGGER.exiting();
        return true;
    }
    LOGGER.exiting();
    return false;
}
 
Example #6
Source File: PolicyWSDLParserExtension.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
private boolean processSubelement(
        final WSDLObject element, final XMLStreamReader reader, final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {
    if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.PolicyReference) {     // "PolicyReference" element interests us
        processReferenceUri(policyReader.readPolicyReferenceElement(reader), element, reader, map);
        return true;
    } else if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {   // policy could be defined here
        final PolicyRecordHandler handler =
                readSinglePolicy(
                policyReader.readPolicyElement(
                reader,
                (null == reader.getLocation().getSystemId()) ? // baseUrl
                    "" : reader.getLocation().getSystemId()),
                true);
        if (null != handler) {           // only policies with an Id can work for us
            addHandlerToMap(map, element, handler);
        } // endif null != handler
        return true; // element consumed
    }//end if Policy element found
    return false;
}
 
Example #7
Source File: Policy.java    From openjdk-jdk8u-backup with 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 #8
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example #9
Source File: PolicyWSDLParserExtension.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
@Override
public boolean definitionsElements(final XMLStreamReader reader){
    LOGGER.entering();
    if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {     // Only "Policy" element interests me
        readSinglePolicy(
                policyReader.readPolicyElement(
                reader,
                (null == reader.getLocation().getSystemId()) ? // baseUrl
                    "" : reader.getLocation().getSystemId()),
                false);
        LOGGER.exiting();
        return true;
    }
    LOGGER.exiting();
    return false;
}
 
Example #10
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example #11
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private PolicySourceModel initializeNewModel(final StartElement element) throws PolicyException, XMLStreamException {
    PolicySourceModel model;

    final NamespaceVersion nsVersion = NamespaceVersion.resolveVersion(element.getName().getNamespaceURI());

    final Attribute policyName = getAttributeByName(element, nsVersion.asQName(XmlToken.Name));
    final Attribute xmlId = getAttributeByName(element, PolicyConstants.XML_ID);
    Attribute policyId = getAttributeByName(element, PolicyConstants.WSU_ID);

    if (policyId == null) {
        policyId = xmlId;
    } else if (xmlId != null) {
        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0058_MULTIPLE_POLICY_IDS_NOT_ALLOWED()));
    }

    model = createSourceModel(nsVersion,
            (policyId == null) ? null : policyId.getValue(),
            (policyName == null) ? null : policyName.getValue());

    return model;
}
 
Example #12
Source File: SafePolicyReader.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Reads policy reference element <wsp:PolicyReference/> and returns referenced policy URI as String
 *
 * @param reader The XMLStreamReader should be in START_ELEMENT state and point to the PolicyReference element.
 * @return The URI contained in the PolicyReference
 */
public String readPolicyReferenceElement(final XMLStreamReader reader) {
    try {
        if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.PolicyReference) {     // "PolicyReference" element interests me
            for (int i = 0; i < reader.getAttributeCount(); i++) {
                if (XmlToken.resolveToken(reader.getAttributeName(i).getLocalPart()) == XmlToken.Uri) {
                    final String uriValue = reader.getAttributeValue(i);
                    reader.next();
                    return uriValue;
                }
            }
        }
        reader.next();
        return null;
    } catch(XMLStreamException e) {
        throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1001_XML_EXCEPTION_WHEN_PROCESSING_POLICY_REFERENCE(), e));
    }
}
 
Example #13
Source File: PolicyWSDLParserExtension.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
private boolean processSubelement(
        final WSDLObject element, final XMLStreamReader reader, final Map<WSDLObject, Collection<PolicyRecordHandler>> map) {
    if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.PolicyReference) {     // "PolicyReference" element interests us
        processReferenceUri(policyReader.readPolicyReferenceElement(reader), element, reader, map);
        return true;
    } else if (NamespaceVersion.resolveAsToken(reader.getName()) == XmlToken.Policy) {   // policy could be defined here
        final PolicyRecordHandler handler =
                readSinglePolicy(
                policyReader.readPolicyElement(
                reader,
                (null == reader.getLocation().getSystemId()) ? // baseUrl
                    "" : reader.getLocation().getSystemId()),
                true);
        if (null != handler) {           // only policies with an Id can work for us
            addHandlerToMap(map, element, handler);
        } // endif null != handler
        return true; // element consumed
    }//end if Policy element found
    return false;
}
 
Example #14
Source File: Policy.java    From openjdk-8-source with 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 #15
Source File: XmlPolicyModelUnmarshaller.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * See {@link PolicyModelUnmarshaller#unmarshalModel(Object) base method documentation}.
 */
public PolicySourceModel unmarshalModel(final Object storage) throws PolicyException {
    final XMLEventReader reader = createXMLEventReader(storage);
    PolicySourceModel model = null;

    loop:
    while (reader.hasNext()) {
        try {
            final XMLEvent event = reader.peek();
            switch (event.getEventType()) {
                case XMLStreamConstants.START_DOCUMENT:
                case XMLStreamConstants.COMMENT:
                    reader.nextEvent();
                    break; // skipping the comments and start document events
                case XMLStreamConstants.CHARACTERS:
                    processCharacters(ModelNode.Type.POLICY, event.asCharacters(), null);
                    // we advance the reader only if there is no exception thrown from
                    // the processCharacters(...) call. Otherwise we don't modify the stream
                    reader.nextEvent();
                    break;
                case XMLStreamConstants.START_ELEMENT:
                    if (NamespaceVersion.resolveAsToken(event.asStartElement().getName()) == XmlToken.Policy) {
                        StartElement rootElement = reader.nextEvent().asStartElement();

                        model = initializeNewModel(rootElement);
                        unmarshalNodeContent(model.getNamespaceVersion(), model.getRootNode(), rootElement.getName(), reader);

                        break loop;
                    } else {
                        throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST()));
                    }
                default:
                    throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0048_POLICY_ELEMENT_EXPECTED_FIRST()));
            }
        } catch (XMLStreamException e) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0068_FAILED_TO_UNMARSHALL_POLICY_EXPRESSION(), e));
        }
    }
    return model;
}
 
Example #16
Source File: PolicyMerger.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @param policies collection of policies to be merged. The collection must not contain '{@code null}' elements!
 * @return merged policy containing combination of policy alternatives stored in all input policies.
 *         If provided collection of policies is {@code null} or empty, returns {@code null}. If provided
 *         collection of policies contains only single policy, the policy is returned.
 */
public Policy merge(final Collection<Policy> policies) {
    if (policies == null || policies.isEmpty()) {
        return null;
    } else if (policies.size() == 1) {
        return policies.iterator().next();
    }

    final Collection<Collection<AssertionSet>> alternativeSets = new LinkedList<Collection<AssertionSet>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example #17
Source File: XmlPolicyModelMarshaller.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marshal given ModelNode and child elements on given TypedXmlWriter.
 *
 * @param nsVersion The WS-Policy version.
 * @param rootNode The ModelNode that is marshalled.
 * @param writer The TypedXmlWriter onto which the content of the rootNode is marshalled.
 */
private void marshal(final NamespaceVersion nsVersion, final ModelNode rootNode, final TypedXmlWriter writer) {
    for (ModelNode node : rootNode) {
        final AssertionData data = node.getNodeData();
        if (marshallInvisible || data == null || !data.isPrivateAttributeSet()) {
            TypedXmlWriter child = null;
            if (data == null) {
                child = writer._element(nsVersion.asQName(node.getType().getXmlToken()), TypedXmlWriter.class);
            } else {
                child = writer._element(data.getName(), TypedXmlWriter.class);
                final String value = data.getValue();
                if (value != null) {
                    child._pcdata(value);
                }
                if (data.isOptionalAttributeSet()) {
                    child._attribute(nsVersion.asQName(XmlToken.Optional), Boolean.TRUE);
                }
                if (data.isIgnorableAttributeSet()) {
                    child._attribute(nsVersion.asQName(XmlToken.Ignorable), Boolean.TRUE);
                }
                for (Entry<QName, String> entry : data.getAttributesSet()) {
                    child._attribute(entry.getKey(), entry.getValue());
                }
            }
            marshal(nsVersion, node, child);
        }
    }
}
 
Example #18
Source File: XmlPolicyModelMarshaller.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Marshal given ModelNode and child elements on given TypedXmlWriter.
 *
 * @param nsVersion The WS-Policy version.
 * @param rootNode The ModelNode that is marshalled.
 * @param writer The TypedXmlWriter onto which the content of the rootNode is marshalled.
 */
private void marshal(final NamespaceVersion nsVersion, final ModelNode rootNode, final TypedXmlWriter writer) {
    for (ModelNode node : rootNode) {
        final AssertionData data = node.getNodeData();
        if (marshallInvisible || data == null || !data.isPrivateAttributeSet()) {
            TypedXmlWriter child = null;
            if (data == null) {
                child = writer._element(nsVersion.asQName(node.getType().getXmlToken()), TypedXmlWriter.class);
            } else {
                child = writer._element(data.getName(), TypedXmlWriter.class);
                final String value = data.getValue();
                if (value != null) {
                    child._pcdata(value);
                }
                if (data.isOptionalAttributeSet()) {
                    child._attribute(nsVersion.asQName(XmlToken.Optional), Boolean.TRUE);
                }
                if (data.isIgnorableAttributeSet()) {
                    child._attribute(nsVersion.asQName(XmlToken.Ignorable), Boolean.TRUE);
                }
                for (Entry<QName, String> entry : data.getAttributesSet()) {
                    child._attribute(entry.getKey(), entry.getValue());
                }
            }
            marshal(nsVersion, node, child);
        }
    }
}
 
Example #19
Source File: PolicyMerger.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @param policies collection of policies to be merged. The collection must not contain '{@code null}' elements!
 * @return merged policy containing combination of policy alternatives stored in all input policies.
 *         If provided collection of policies is {@code null} or empty, returns {@code null}. If provided
 *         collection of policies contains only single policy, the policy is returned.
 */
public Policy merge(final Collection<Policy> policies) {
    if (policies == null || policies.isEmpty()) {
        return null;
    } else if (policies.size() == 1) {
        return policies.iterator().next();
    }

    final Collection<Collection<AssertionSet>> alternativeSets = new LinkedList<Collection<AssertionSet>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example #20
Source File: PolicyWSDLGeneratorExtension.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void start(final WSDLGenExtnContext context) {
    LOGGER.entering();
    try {
        this.seiModel = context.getModel();

        final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators();
        final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length];
        for (int i = 0; i < policyMapConfigurators.length; i++) {
            extenders[i] = PolicyMapExtender.createPolicyMapExtender();
        }
        // Read policy config file
        policyMap = PolicyResolverFactory.create().resolve(
                new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders));

        if (policyMap == null) {
            LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP());
            policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders));
        }

        final WSBinding binding = context.getBinding();
        try {
            final Collection<PolicySubject> policySubjects = new LinkedList<PolicySubject>();
            for (int i = 0; i < policyMapConfigurators.length; i++) {
                policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding));
                extenders[i].disconnect();
            }
            PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName());
        } catch (PolicyException e) {
            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e));
        }
        final TypedXmlWriter root = context.getRoot();
        root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix());
        root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix());
        root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX);

    } finally {
        LOGGER.exiting();
    }
}
 
Example #21
Source File: PolicyWSDLGeneratorExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void start(final WSDLGenExtnContext context) {
    LOGGER.entering();
    try {
        this.seiModel = context.getModel();

        final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators();
        final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length];
        for (int i = 0; i < policyMapConfigurators.length; i++) {
            extenders[i] = PolicyMapExtender.createPolicyMapExtender();
        }
        // Read policy config file
        policyMap = PolicyResolverFactory.create().resolve(
                new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders));

        if (policyMap == null) {
            LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP());
            policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders));
        }

        final WSBinding binding = context.getBinding();
        try {
            final Collection<PolicySubject> policySubjects = new LinkedList<PolicySubject>();
            for (int i = 0; i < policyMapConfigurators.length; i++) {
                policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding));
                extenders[i].disconnect();
            }
            PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName());
        } catch (PolicyException e) {
            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e));
        }
        final TypedXmlWriter root = context.getRoot();
        root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix());
        root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix());
        root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX);

    } finally {
        LOGGER.exiting();
    }
}
 
Example #22
Source File: PolicyMerger.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @param policies collection of policies to be merged. The collection must not contain '{@code null}' elements!
 * @return merged policy containing combination of policy alternatives stored in all input policies.
 *         If provided collection of policies is {@code null} or empty, returns {@code null}. If provided
 *         collection of policies contains only single policy, the policy is returned.
 */
public Policy merge(final Collection<Policy> policies) {
    if (policies == null || policies.isEmpty()) {
        return null;
    } else if (policies.size() == 1) {
        return policies.iterator().next();
    }

    final Collection<Collection<AssertionSet>> alternativeSets = new LinkedList<Collection<AssertionSet>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example #23
Source File: PolicyMerger.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @param policies collection of policies to be merged. The collection must not contain '{@code null}' elements!
 * @return merged policy containing combination of policy alternatives stored in all input policies.
 *         If provided collection of policies is {@code null} or empty, returns {@code null}. If provided
 *         collection of policies contains only single policy, the policy is returned.
 */
public Policy merge(final Collection<Policy> policies) {
    if (policies == null || policies.isEmpty()) {
        return null;
    } else if (policies.size() == 1) {
        return policies.iterator().next();
    }

    final Collection<Collection<AssertionSet>> alternativeSets = new LinkedList<Collection<AssertionSet>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example #24
Source File: PolicyWSDLGeneratorExtension.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void start(final WSDLGenExtnContext context) {
    LOGGER.entering();
    try {
        this.seiModel = context.getModel();

        final PolicyMapConfigurator[] policyMapConfigurators = loadConfigurators();
        final PolicyMapExtender[] extenders = new PolicyMapExtender[policyMapConfigurators.length];
        for (int i = 0; i < policyMapConfigurators.length; i++) {
            extenders[i] = PolicyMapExtender.createPolicyMapExtender();
        }
        // Read policy config file
        policyMap = PolicyResolverFactory.create().resolve(
                new PolicyResolver.ServerContext(policyMap, context.getContainer(), context.getEndpointClass(), false, extenders));

        if (policyMap == null) {
            LOGGER.fine(PolicyMessages.WSP_1019_CREATE_EMPTY_POLICY_MAP());
            policyMap = PolicyMap.createPolicyMap(Arrays.asList(extenders));
        }

        final WSBinding binding = context.getBinding();
        try {
            final Collection<PolicySubject> policySubjects = new LinkedList<PolicySubject>();
            for (int i = 0; i < policyMapConfigurators.length; i++) {
                policySubjects.addAll(policyMapConfigurators[i].update(policyMap, seiModel, binding));
                extenders[i].disconnect();
            }
            PolicyMapUtil.insertPolicies(policyMap, policySubjects, this.seiModel.getServiceQName(), this.seiModel.getPortName());
        } catch (PolicyException e) {
            throw LOGGER.logSevereException(new WebServiceException(PolicyMessages.WSP_1017_MAP_UPDATE_FAILED(), e));
        }
        final TypedXmlWriter root = context.getRoot();
        root._namespace(NamespaceVersion.v1_2.toString(), NamespaceVersion.v1_2.getDefaultNamespacePrefix());
        root._namespace(NamespaceVersion.v1_5.toString(), NamespaceVersion.v1_5.getDefaultNamespacePrefix());
        root._namespace(PolicyConstants.WSU_NAMESPACE_URI, PolicyConstants.WSU_NAMESPACE_PREFIX);

    } finally {
        LOGGER.exiting();
    }
}
 
Example #25
Source File: PolicyWSDLParserExtension.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads policy reference URIs from PolicyURIs attribute and returns them
 * as a String array returns null if there is no such attribute. This method
 * will attempt to check for the attribute in every supported policy namespace.
 * Resulting array of URIs is concatenation of URIs defined in all found
 * PolicyURIs attribute version.
 */
private String[] getPolicyURIsFromAttr(final XMLStreamReader reader) {
    final StringBuilder policyUriBuffer = new StringBuilder();
    for (NamespaceVersion version : NamespaceVersion.values()) {
        final String value = reader.getAttributeValue(version.toString(), XmlToken.PolicyUris.toString());
        if (value != null) {
            policyUriBuffer.append(value).append(" ");
        }
    }
    return (policyUriBuffer.length() > 0) ? policyUriBuffer.toString().split("[\\n ]+") : null;
}
 
Example #26
Source File: PolicyMerger.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @param policies collection of policies to be merged. The collection must not contain '{@code null}' elements!
 * @return merged policy containing combination of policy alternatives stored in all input policies.
 *         If provided collection of policies is {@code null} or empty, returns {@code null}. If provided
 *         collection of policies contains only single policy, the policy is returned.
 */
public Policy merge(final Collection<Policy> policies) {
    if (policies == null || policies.isEmpty()) {
        return null;
    } else if (policies.size() == 1) {
        return policies.iterator().next();
    }

    final Collection<Collection<AssertionSet>> alternativeSets = new LinkedList<Collection<AssertionSet>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example #27
Source File: PolicyWSDLParserExtension.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Reads policy reference URIs from PolicyURIs attribute and returns them
 * as a String array returns null if there is no such attribute. This method
 * will attempt to check for the attribute in every supported policy namespace.
 * Resulting array of URIs is concatenation of URIs defined in all found
 * PolicyURIs attribute version.
 */
private String[] getPolicyURIsFromAttr(final XMLStreamReader reader) {
    final StringBuilder policyUriBuffer = new StringBuilder();
    for (NamespaceVersion version : NamespaceVersion.values()) {
        final String value = reader.getAttributeValue(version.toString(), XmlToken.PolicyUris.toString());
        if (value != null) {
            policyUriBuffer.append(value).append(" ");
        }
    }
    return (policyUriBuffer.length() > 0) ? policyUriBuffer.toString().split("[\\n ]+") : null;
}
 
Example #28
Source File: PolicyMerger.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Takes collection of policies and merges them into a single policy using algorithm described in
 * WS-PolicyAttachment specification. None of the original policies in the collection are modified in
 * any way.
 *
 * The newly created policy has an ID that is a concatentation of all merged policy IDs.
 *
 * @param policies collection of policies to be merged. The collection must not contain '{@code null}' elements!
 * @return merged policy containing combination of policy alternatives stored in all input policies.
 *         If provided collection of policies is {@code null} or empty, returns {@code null}. If provided
 *         collection of policies contains only single policy, the policy is returned.
 */
public Policy merge(final Collection<Policy> policies) {
    if (policies == null || policies.isEmpty()) {
        return null;
    } else if (policies.size() == 1) {
        return policies.iterator().next();
    }

    final Collection<Collection<AssertionSet>> alternativeSets = new LinkedList<Collection<AssertionSet>>();
    final StringBuilder id = new StringBuilder();
    NamespaceVersion mergedVersion = policies.iterator().next().getNamespaceVersion();
    for (Policy policy : policies) {
        alternativeSets.add(policy.getContent());
        if (mergedVersion.compareTo(policy.getNamespaceVersion()) < 0) {
            mergedVersion = policy.getNamespaceVersion();
        }
        final String policyId = policy.getId();
        if (policyId != null) {
            if (id.length() > 0) {
                id.append('-');
            }
            id.append(policyId);
        }
    }

    final Collection<Collection<AssertionSet>> combinedAlternatives = PolicyUtils.Collections.combine(null, alternativeSets, false);

    if (combinedAlternatives == null || combinedAlternatives.isEmpty()) {
        return Policy.createNullPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString());
    } else {
        final Collection<AssertionSet> mergedSetList = new ArrayList<AssertionSet>(combinedAlternatives.size());
        for (Collection<AssertionSet> toBeMerged : combinedAlternatives) {
            mergedSetList.add(AssertionSet.createMergedAssertionSet(toBeMerged));
        }
        return Policy.createPolicy(mergedVersion, null, id.length() == 0 ? null : id.toString(), mergedSetList);
    }
}
 
Example #29
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void parseAssertionData(NamespaceVersion nsVersion, String value, ModelNode childNode, final StartElement childElement) throws IllegalArgumentException, PolicyException {
    // finish assertion node processing: create and set assertion data...
    final Map<QName, String> attributeMap = new HashMap<QName, String>();
    boolean optional = false;
    boolean ignorable = false;

    final Iterator iterator = childElement.getAttributes();
    while (iterator.hasNext()) {
        final Attribute nextAttribute = (Attribute) iterator.next();
        final QName name = nextAttribute.getName();
        if (attributeMap.containsKey(name)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0059_MULTIPLE_ATTRS_WITH_SAME_NAME_DETECTED_FOR_ASSERTION(nextAttribute.getName(), childElement.getName())));
        } else {
            if (nsVersion.asQName(XmlToken.Optional).equals(name)) {
                optional = parseBooleanValue(nextAttribute.getValue());
            } else if (nsVersion.asQName(XmlToken.Ignorable).equals(name)) {
                ignorable = parseBooleanValue(nextAttribute.getValue());
            } else {
                attributeMap.put(name, nextAttribute.getValue());
            }
        }
    }
    final AssertionData nodeData = new AssertionData(childElement.getName(), value, attributeMap, childNode.getType(), optional, ignorable);

    // check visibility value syntax if present...
    if (nodeData.containsAttribute(PolicyConstants.VISIBILITY_ATTRIBUTE)) {
        final String visibilityValue = nodeData.getAttributeValue(PolicyConstants.VISIBILITY_ATTRIBUTE);
        if (!PolicyConstants.VISIBILITY_VALUE_PRIVATE.equals(visibilityValue)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0004_UNEXPECTED_VISIBILITY_ATTR_VALUE(visibilityValue)));
        }
    }

    childNode.setOrReplaceNodeData(nodeData);
}
 
Example #30
Source File: XmlPolicyModelUnmarshaller.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void parseAssertionData(NamespaceVersion nsVersion, String value, ModelNode childNode, final StartElement childElement) throws IllegalArgumentException, PolicyException {
    // finish assertion node processing: create and set assertion data...
    final Map<QName, String> attributeMap = new HashMap<QName, String>();
    boolean optional = false;
    boolean ignorable = false;

    final Iterator iterator = childElement.getAttributes();
    while (iterator.hasNext()) {
        final Attribute nextAttribute = (Attribute) iterator.next();
        final QName name = nextAttribute.getName();
        if (attributeMap.containsKey(name)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0059_MULTIPLE_ATTRS_WITH_SAME_NAME_DETECTED_FOR_ASSERTION(nextAttribute.getName(), childElement.getName())));
        } else {
            if (nsVersion.asQName(XmlToken.Optional).equals(name)) {
                optional = parseBooleanValue(nextAttribute.getValue());
            } else if (nsVersion.asQName(XmlToken.Ignorable).equals(name)) {
                ignorable = parseBooleanValue(nextAttribute.getValue());
            } else {
                attributeMap.put(name, nextAttribute.getValue());
            }
        }
    }
    final AssertionData nodeData = new AssertionData(childElement.getName(), value, attributeMap, childNode.getType(), optional, ignorable);

    // check visibility value syntax if present...
    if (nodeData.containsAttribute(PolicyConstants.VISIBILITY_ATTRIBUTE)) {
        final String visibilityValue = nodeData.getAttributeValue(PolicyConstants.VISIBILITY_ATTRIBUTE);
        if (!PolicyConstants.VISIBILITY_VALUE_PRIVATE.equals(visibilityValue)) {
            throw LOGGER.logSevereException(new PolicyException(LocalizationMessages.WSP_0004_UNEXPECTED_VISIBILITY_ATTR_VALUE(visibilityValue)));
        }
    }

    childNode.setOrReplaceNodeData(nodeData);
}