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);
}
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));
}
}
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);
}
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;
}
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;
}
Aggregations