Search in sources :

Example 6 with AssertionSet

use of com.sun.xml.ws.policy.AssertionSet in project metro-jax-ws by eclipse-ee4j.

the class AddressingPolicyMapConfigurator method createWsamAddressingPolicy.

/**
 * Create a policy with an WSAM Addressing assertion.
 */
private Policy createWsamAddressingPolicy(final QName bindingName, AddressingFeature af) {
    final ArrayList<AssertionSet> assertionSets = new ArrayList<>(1);
    final ArrayList<PolicyAssertion> assertions = new ArrayList<>(1);
    final AssertionData addressingData = AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_ADDRESSING_ASSERTION);
    if (!af.isRequired()) {
        addressingData.setOptionalAttribute(true);
    }
    try {
        AddressingFeature.Responses responses = af.getResponses();
        if (responses == AddressingFeature.Responses.ANONYMOUS) {
            AssertionData nestedAsserData = AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_ANONYMOUS_NESTED_ASSERTION);
            PolicyAssertion nestedAsser = new AddressingAssertion(nestedAsserData, null);
            assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(Collections.singleton(nestedAsser))));
        } else if (responses == AddressingFeature.Responses.NON_ANONYMOUS) {
            final AssertionData nestedAsserData = AssertionData.createAssertionData(W3CAddressingMetadataConstants.WSAM_NONANONYMOUS_NESTED_ASSERTION);
            PolicyAssertion nestedAsser = new AddressingAssertion(nestedAsserData, null);
            assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(Collections.singleton(nestedAsser))));
        } else {
            assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(null)));
        }
    } catch (NoSuchMethodError e) {
        // If JAX-WS 2.2 API is really required, it would been reported in @Addressing or wsam:Addressing processing
        // Don't add any nested assertion to mimic the 2.1 behavior
        assertions.add(new AddressingAssertion(addressingData, AssertionSet.createAssertionSet(null)));
    }
    assertionSets.add(AssertionSet.createAssertionSet(assertions));
    return Policy.createPolicy(null, bindingName.getLocalPart() + "_WSAM_Addressing_Policy", assertionSets);
}
Also used : PolicyAssertion(com.sun.xml.ws.policy.PolicyAssertion) AddressingFeature(jakarta.xml.ws.soap.AddressingFeature) ArrayList(java.util.ArrayList) AssertionSet(com.sun.xml.ws.policy.AssertionSet) AssertionData(com.sun.xml.ws.policy.sourcemodel.AssertionData)

Example 7 with AssertionSet

use of com.sun.xml.ws.policy.AssertionSet in project metro-jax-ws by eclipse-ee4j.

the class ManagementAssertion method getAssertion.

/**
 * Return ManagementAssertion if one can be found in the policy map under
 * the given service and port name.
 *
 * @param <T> The implementation class of the assertion.
 * @param name The fully qualified name of the server or client assertion.
 * @param policyMap The policy map. May be null.
 * @param serviceName The WSDL service name. May not be null.
 * @param portName The WSDL port name. May not be null.
 * @param type The implementation class of the assertion.
 * @return An instance of ManagementAssertion or null.
 * @throws WebServiceException If computing the effective policy of the endpoint scope failed.
 */
protected static <T extends ManagementAssertion> T getAssertion(final QName name, final PolicyMap policyMap, QName serviceName, QName portName, Class<T> type) throws WebServiceException {
    try {
        PolicyAssertion assertion = null;
        if (policyMap != null) {
            final PolicyMapKey key = PolicyMap.createWsdlEndpointScopeKey(serviceName, portName);
            final Policy policy = policyMap.getEndpointEffectivePolicy(key);
            if (policy != null) {
                final Iterator<AssertionSet> assertionSets = policy.iterator();
                if (assertionSets.hasNext()) {
                    final AssertionSet assertionSet = assertionSets.next();
                    final Iterator<PolicyAssertion> assertions = assertionSet.get(name).iterator();
                    if (assertions.hasNext()) {
                        assertion = assertions.next();
                    }
                }
            }
        }
        return assertion == null ? null : assertion.getImplementation(type);
    } catch (PolicyException ex) {
        throw LOGGER.logSevereException(new WebServiceException(ManagementMessages.WSM_1001_FAILED_ASSERTION(name), ex));
    }
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicyAssertion(com.sun.xml.ws.policy.PolicyAssertion) WebServiceException(jakarta.xml.ws.WebServiceException) PolicyMapKey(com.sun.xml.ws.policy.PolicyMapKey) PolicyException(com.sun.xml.ws.policy.PolicyException) AssertionSet(com.sun.xml.ws.policy.AssertionSet)

Example 8 with AssertionSet

use of com.sun.xml.ws.policy.AssertionSet in project metro-jax-ws by eclipse-ee4j.

the class ExternalAttachmentsUnmarshallerTest method testUnmarshal.

/**
 * Test of unmarshal method, of class ExternalAttachmentsUnmarshaller.
 */
public void testUnmarshal() throws Exception {
    final String policies = "<sunman:Policies " + "xmlns:sunman=\"http://java.sun.com/xml/ns/metro/management\" " + "xmlns:wsp=\"http://www.w3.org/ns/ws-policy\" " + "xmlns:wsu=\"http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd\" " + "xmlns:foo=\"http://schemas.example.net/\">" + "  <wsp:PolicyAttachment>" + "    <wsp:AppliesTo>" + "      <wsp:URI>urn:uuid:c9bef600-0d7a-11de-abc1-0002a5d5c51b</wsp:URI>" + "    </wsp:AppliesTo>" + "    <wsp:Policy wsu:Id=\"binding-policy\">" + "      <foo:TopLevelAssertion_1 />" + "    </wsp:Policy>" + "  </wsp:PolicyAttachment>" + "  <wsp:PolicyAttachment>" + "    <wsp:AppliesTo>" + "      <wsp:URI>urn:uuid:62e66b60-0d7b-11de-a1a2-0002a5d5c51b</wsp:URI>" + "    </wsp:AppliesTo>" + "    <wsp:Policy wsu:Id=\"operation-policy\">" + "      <foo:TopLevelAssertion_2 />" + "    </wsp:Policy>" + "  </wsp:PolicyAttachment>" + "  <wsp:PolicyAttachment>" + "    <wsp:AppliesTo>" + "      <wsp:URI>urn:uuid:730d8d20-0d7b-11de-84e9-0002a5d5c51b</wsp:URI>" + "    </wsp:AppliesTo>" + "    <wsp:Policy wsu:Id=\"input-policy\">" + "      <foo:TopLevelAssertion_3>" + "        <foo:TopLevelAssertion_3_Parameter1/>" + "        <foo:TopLevelAssertion_3_Parameter2>" + "          <foo:TopLevelAssertion_3_Parameter2_1/>" + "          <foo:TopLevelAssertion_3_Parameter2_2/>" + "        </foo:TopLevelAssertion_3_Parameter2>" + "        <wsp:Policy>" + "          <wsp:ExactlyOne>" + "              <foo:NestedAssertion_1/>" + "              <foo:NestedAssertion_2/>" + "          </wsp:ExactlyOne>" + "        </wsp:Policy>" + "      </foo:TopLevelAssertion_3>" + "    </wsp:Policy>" + "  </wsp:PolicyAttachment>" + "  <wsp:PolicyAttachment>" + "    <wsp:AppliesTo>" + "      <wsp:URI>urn:uuid:85b0f980-0d7b-11de-8e9d-0002a5d5c51b</wsp:URI>" + "    </wsp:AppliesTo>" + "    <wsp:Policy wsu:Id=\"output-policy\">" + "      <foo:TopLevelAssertion_4/>" + "    </wsp:Policy>" + "  </wsp:PolicyAttachment>" + "  <wsp:PolicyAttachment>" + "    <wsp:AppliesTo>" + "      <wsp:URI>urn:uuid:917cb060-0d7b-11de-9e80-0002a5d5c51b</wsp:URI>" + "    </wsp:AppliesTo>" + "    <wsp:Policy wsu:Id=\"fault-policy\">" + "      <foo:TopLevelAssertion_5/>" + "    </wsp:Policy>" + "  </wsp:PolicyAttachment>" + "</sunman:Policies>";
    final Map<URI, Policy> expResult = new HashMap<URI, Policy>();
    final AssertionData assertionData1 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_1"));
    final PolicyAssertion assertion1 = new PolicyAssertion(assertionData1, null) {
    };
    final LinkedList<PolicyAssertion> assertionList1 = new LinkedList<PolicyAssertion>();
    assertionList1.add(assertion1);
    final AssertionSet assertions1 = AssertionSet.createAssertionSet(assertionList1);
    final LinkedList<AssertionSet> alternatives1 = new LinkedList<AssertionSet>();
    alternatives1.add(assertions1);
    final Policy bindingPolicy = Policy.createPolicy(NamespaceVersion.v1_5, null, "binding-policy", alternatives1);
    expResult.put(new URI("urn:uuid:c9bef600-0d7a-11de-abc1-0002a5d5c51b"), bindingPolicy);
    final AssertionData assertionData2 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_2"));
    final PolicyAssertion assertion2 = new PolicyAssertion(assertionData2, null) {
    };
    final LinkedList<PolicyAssertion> assertionList2 = new LinkedList<PolicyAssertion>();
    assertionList2.add(assertion2);
    final AssertionSet assertions2 = AssertionSet.createAssertionSet(assertionList2);
    final LinkedList<AssertionSet> alternatives2 = new LinkedList<AssertionSet>();
    alternatives2.add(assertions2);
    final Policy operationPolicy = Policy.createPolicy(NamespaceVersion.v1_5, null, "operation-policy", alternatives2);
    expResult.put(new URI("urn:uuid:62e66b60-0d7b-11de-a1a2-0002a5d5c51b"), operationPolicy);
    final AssertionData assertionData31 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_3_Parameter1"));
    final PolicyAssertion assertion31 = new PolicyAssertion(assertionData31, null) {
    };
    final AssertionData assertionData321 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_3_Parameter2_1"));
    final PolicyAssertion assertion321 = new PolicyAssertion(assertionData321, null) {
    };
    final AssertionData assertionData322 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_3_Parameter2_2"));
    final PolicyAssertion assertion322 = new PolicyAssertion(assertionData322, null) {
    };
    final AssertionData assertionData32 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_3_Parameter2"));
    final LinkedList<PolicyAssertion> parameters32 = new LinkedList<PolicyAssertion>();
    parameters32.add(assertion321);
    parameters32.add(assertion322);
    final PolicyAssertion assertion32 = new PolicyAssertion(assertionData32, parameters32) {
    };
    final LinkedList<PolicyAssertion> parameters3 = new LinkedList<PolicyAssertion>();
    parameters3.add(assertion31);
    parameters3.add(assertion32);
    final AssertionData nestedAssertionData1 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "NestedAssertion_1"));
    final PolicyAssertion nestedAssertion1 = new PolicyAssertion(nestedAssertionData1, null) {
    };
    final LinkedList<PolicyAssertion> nestedAssertionList1 = new LinkedList<PolicyAssertion>();
    nestedAssertionList1.add(nestedAssertion1);
    final AssertionSet nestedAlternative1 = AssertionSet.createAssertionSet(nestedAssertionList1);
    final AssertionData assertionData3 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_3"));
    final PolicyAssertion assertion3Alt1 = new PolicyAssertion(assertionData3, parameters3, nestedAlternative1) {
    };
    final LinkedList<PolicyAssertion> assertionList31 = new LinkedList<PolicyAssertion>();
    assertionList31.add(assertion3Alt1);
    final AssertionSet assertions31 = AssertionSet.createAssertionSet(assertionList31);
    final LinkedList<AssertionSet> alternatives3 = new LinkedList<AssertionSet>();
    alternatives3.add(assertions31);
    final AssertionData nestedAssertionData2 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "NestedAssertion_2"));
    final PolicyAssertion nestedAssertion2 = new PolicyAssertion(nestedAssertionData2, null) {
    };
    final LinkedList<PolicyAssertion> nestedAssertionList2 = new LinkedList<PolicyAssertion>();
    nestedAssertionList2.add(nestedAssertion2);
    final AssertionSet nestedAlternative2 = AssertionSet.createAssertionSet(nestedAssertionList2);
    final PolicyAssertion assertion3Alt2 = new PolicyAssertion(assertionData3, parameters3, nestedAlternative2) {
    };
    final LinkedList<PolicyAssertion> assertionList32 = new LinkedList<PolicyAssertion>();
    assertionList32.add(assertion3Alt2);
    final AssertionSet assertions32 = AssertionSet.createAssertionSet(assertionList32);
    alternatives3.add(assertions32);
    final Policy inputPolicy = Policy.createPolicy(NamespaceVersion.v1_5, null, "input-policy", alternatives3);
    expResult.put(new URI("urn:uuid:730d8d20-0d7b-11de-84e9-0002a5d5c51b"), inputPolicy);
    final AssertionData assertionData4 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_4"));
    final PolicyAssertion assertion4 = new PolicyAssertion(assertionData4, null) {
    };
    final LinkedList<PolicyAssertion> assertionList4 = new LinkedList<PolicyAssertion>();
    assertionList4.add(assertion4);
    final AssertionSet assertions4 = AssertionSet.createAssertionSet(assertionList4);
    final LinkedList<AssertionSet> alternatives4 = new LinkedList<AssertionSet>();
    alternatives4.add(assertions4);
    final Policy outputPolicy = Policy.createPolicy(NamespaceVersion.v1_5, null, "output-policy", alternatives4);
    expResult.put(new URI("urn:uuid:85b0f980-0d7b-11de-8e9d-0002a5d5c51b"), outputPolicy);
    final AssertionData assertionData5 = AssertionData.createAssertionData(new QName("http://schemas.example.net/", "TopLevelAssertion_5"));
    final PolicyAssertion assertion5 = new PolicyAssertion(assertionData5, null) {
    };
    final LinkedList<PolicyAssertion> assertionList5 = new LinkedList<PolicyAssertion>();
    assertionList5.add(assertion5);
    final AssertionSet assertions5 = AssertionSet.createAssertionSet(assertionList5);
    final LinkedList<AssertionSet> alternatives5 = new LinkedList<AssertionSet>();
    alternatives5.add(assertions5);
    final Policy faultPolicy = Policy.createPolicy(NamespaceVersion.v1_5, null, "fault-policy", alternatives5);
    expResult.put(new URI("urn:uuid:917cb060-0d7b-11de-9e80-0002a5d5c51b"), faultPolicy);
    final StringReader reader = new StringReader(policies);
    final Map<URI, Policy> result = ExternalAttachmentsUnmarshaller.unmarshal(reader);
    assertEquals(expResult, result);
}
Also used : Policy(com.sun.xml.ws.policy.Policy) PolicyAssertion(com.sun.xml.ws.policy.PolicyAssertion) HashMap(java.util.HashMap) QName(javax.xml.namespace.QName) AssertionSet(com.sun.xml.ws.policy.AssertionSet) URI(java.net.URI) LinkedList(java.util.LinkedList) StringReader(java.io.StringReader) AssertionData(com.sun.xml.ws.policy.sourcemodel.AssertionData)

Example 9 with AssertionSet

use of com.sun.xml.ws.policy.AssertionSet in project metro-jax-ws by eclipse-ee4j.

the class CompactModelGenerator method translate.

@Override
public PolicySourceModel translate(final Policy policy) throws PolicyException {
    LOGGER.entering(policy);
    PolicySourceModel model = null;
    if (policy == null) {
        LOGGER.fine(LocalizationMessages.WSP_0047_POLICY_IS_NULL_RETURNING());
    } else {
        model = this.sourceModelCreator.create(policy);
        ModelNode rootNode = model.getRootNode();
        final int numberOfAssertionSets = policy.getNumberOfAssertionSets();
        if (numberOfAssertionSets > 1) {
            rootNode = rootNode.createChildExactlyOneNode();
        }
        ModelNode alternativeNode = rootNode;
        for (AssertionSet set : policy) {
            if (numberOfAssertionSets > 1) {
                alternativeNode = rootNode.createChildAllNode();
            }
            for (PolicyAssertion assertion : set) {
                final AssertionData data = AssertionData.createAssertionData(assertion.getName(), assertion.getValue(), assertion.getAttributes(), assertion.isOptional(), assertion.isIgnorable());
                final ModelNode assertionNode = alternativeNode.createChildAssertionNode(data);
                if (assertion.hasNestedPolicy()) {
                    translate(assertionNode, assertion.getNestedPolicy());
                }
                if (assertion.hasParameters()) {
                    translate(assertionNode, assertion.getParametersIterator());
                }
            }
        }
    }
    LOGGER.exiting(model);
    return model;
}
Also used : PolicyAssertion(com.sun.xml.ws.policy.PolicyAssertion) AssertionSet(com.sun.xml.ws.policy.AssertionSet)

Example 10 with AssertionSet

use of com.sun.xml.ws.policy.AssertionSet in project metro-jax-ws by eclipse-ee4j.

the class NormalizedModelGenerator method translate.

@Override
protected ModelNode translate(final ModelNode parentAssertion, final NestedPolicy policy) {
    final ModelNode nestedPolicyRoot = parentAssertion.createChildPolicyNode();
    final ModelNode exactlyOneNode = nestedPolicyRoot.createChildExactlyOneNode();
    final AssertionSet set = policy.getAssertionSet();
    final ModelNode alternativeNode = exactlyOneNode.createChildAllNode();
    translate(alternativeNode, set);
    return nestedPolicyRoot;
}
Also used : AssertionSet(com.sun.xml.ws.policy.AssertionSet)

Aggregations

AssertionSet (com.sun.xml.ws.policy.AssertionSet)13 PolicyAssertion (com.sun.xml.ws.policy.PolicyAssertion)10 Policy (com.sun.xml.ws.policy.Policy)7 LinkedList (java.util.LinkedList)6 WebServiceFeature (jakarta.xml.ws.WebServiceFeature)4 PolicyException (com.sun.xml.ws.policy.PolicyException)3 AssertionData (com.sun.xml.ws.policy.sourcemodel.AssertionData)2 WebServiceException (jakarta.xml.ws.WebServiceException)2 AddressingFeature (jakarta.xml.ws.soap.AddressingFeature)2 QName (javax.xml.namespace.QName)2 SelectOptimalEncodingFeature (com.sun.xml.ws.api.client.SelectOptimalEncodingFeature)1 FastInfosetFeature (com.sun.xml.ws.api.fastinfoset.FastInfosetFeature)1 NestedPolicy (com.sun.xml.ws.policy.NestedPolicy)1 PolicyMapKey (com.sun.xml.ws.policy.PolicyMapKey)1 MTOMFeature (jakarta.xml.ws.soap.MTOMFeature)1 StringReader (java.io.StringReader)1 URI (java.net.URI)1 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1