use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class AbstractTokenInterceptor method policyNotAsserted.
protected void policyNotAsserted(AbstractToken assertion, String reason, SoapMessage message) {
if (assertion == null) {
return;
}
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
Collection<AssertionInfo> ais = aim.get(assertion.getName());
if (ais != null) {
for (AssertionInfo ai : ais) {
if (ai.getAssertion() == assertion) {
ai.setNotAsserted(reason);
}
}
}
if (!assertion.isOptional()) {
throw new PolicyException(new Message(reason, LOG));
}
}
use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class AbstractPolicySecurityTest method runOutInterceptorAndValidate.
protected Document runOutInterceptorAndValidate(SoapMessage msg, Policy policy, AssertionInfoMap aim, List<QName> assertedOutAssertions, List<QName> notAssertedOutAssertions) throws Exception {
this.getOutInterceptor().handleMessage(msg);
try {
aim.checkEffectivePolicy(policy);
} catch (PolicyException e) {
// Expected but not relevant
} finally {
if (assertedOutAssertions != null) {
for (QName assertionType : assertedOutAssertions) {
Collection<AssertionInfo> ais = aim.get(assertionType);
assertNotNull(ais);
for (AssertionInfo ai : ais) {
checkAssertion(aim, assertionType, ai, true);
}
}
}
if (notAssertedOutAssertions != null) {
for (QName assertionType : notAssertedOutAssertions) {
Collection<AssertionInfo> ais = aim.get(assertionType);
assertNotNull(ais);
for (AssertionInfo ai : ais) {
checkAssertion(aim, assertionType, ai, false);
}
}
}
}
return msg.getContent(SOAPMessage.class).getSOAPPart();
}
use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class HTTPClientPolicyTest method testUsingHTTPClientPolicies.
@Test
public void testUsingHTTPClientPolicies() throws Exception {
SpringBusFactory bf = new SpringBusFactory();
bus = bf.createBus(POLICY_ENGINE_ENABLED_CFG);
BusFactory.setDefaultBus(bus);
LoggingInInterceptor in = new LoggingInInterceptor();
bus.getInInterceptors().add(in);
bus.getInFaultInterceptors().add(in);
LoggingOutInterceptor out = new LoggingOutInterceptor();
bus.getOutInterceptors().add(out);
bus.getOutFaultInterceptors().add(out);
// use a client wsdl with policies attached to endpoint, operation and message subjects
URL url = HTTPClientPolicyTest.class.getResource("http_client_greeter.wsdl");
BasicGreeterService gs = new BasicGreeterService(url, GREETER_QNAME);
final Greeter greeter = gs.getGreeterPort();
updateAddressPort(greeter, PORT);
LOG.fine("Created greeter client.");
try {
greeter.sayHi();
fail("Did not receive expected PolicyException.");
} catch (WebServiceException wex) {
PolicyException ex = (PolicyException) wex.getCause();
assertEquals("INCOMPATIBLE_HTTPCLIENTPOLICY_ASSERTIONS", ex.getCode());
}
// greetMeOneWay - no message or operation policies
greeter.greetMeOneWay("CXF");
// greetMe - operation policy specifies receive timeout and should cause every
// other invocation to fail
assertEquals("CXF", greeter.greetMe("cxf"));
try {
greeter.greetMe("cxf");
fail("Didn't get the exception");
} catch (Exception ex) {
// ex.printStackTrace();
assertTrue(ex.getCause().getClass().getName(), ex.getCause() instanceof SocketTimeoutException);
}
try {
greeter.pingMe();
fail("Expected PingMeFault not thrown.");
} catch (PingMeFault ex) {
assertEquals(2, ex.getFaultInfo().getMajor());
assertEquals(1, ex.getFaultInfo().getMinor());
}
((Closeable) greeter).close();
}
use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class SecurityVerificationOutInterceptor method handleMessage.
/**
* Checks if some security assertions are specified without binding assertion and cannot be fulfilled.
* Throw PolicyException in this case
*
* @param message
* @throws PolicyException if assertions are specified without binding
*/
public void handleMessage(SoapMessage message) throws Fault {
if (MessageUtils.isRequestor(message)) {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (aim != null && PolicyUtils.getSecurityBinding(aim) == null) {
AssertionInfo assertion = getSecuredPart(aim);
if (assertion != null) {
String error = String.format("%s assertion cannot be fulfilled without binding. " + "At least one binding assertion (%s, %s, %s) must be specified in policy.", assertion.getAssertion().getName(), SP12Constants.TRANSPORT_BINDING.getLocalPart(), SP12Constants.ASYMMETRIC_BINDING.getLocalPart(), SP12Constants.SYMMETRIC_BINDING.getLocalPart());
assertion.setNotAsserted(error);
LOG.severe(error);
throw new PolicyException(assertion);
}
}
}
}
use of org.apache.cxf.ws.policy.PolicyException in project cxf by apache.
the class ExternalAttachmentProviderTest method testReadDocumentUnknownDomainExpression.
@Test
public void testReadDocumentUnknownDomainExpression() throws MalformedURLException {
Bus bus = control.createMock(Bus.class);
DomainExpressionBuilderRegistry debr = control.createMock(DomainExpressionBuilderRegistry.class);
EasyMock.expect(bus.getExtension(DomainExpressionBuilderRegistry.class)).andReturn(debr);
EasyMock.expect(debr.build(EasyMock.isA(Element.class))).andThrow(new PolicyException(new Exception()));
URL url = ExternalAttachmentProviderTest.class.getResource("resources/attachments3.xml");
String uri = url.toExternalForm();
control.replay();
ExternalAttachmentProvider eap = new ExternalAttachmentProvider(bus);
eap.setLocation(new UrlResource(uri));
try {
eap.readDocument();
fail("Expected PolicyException not thrown.");
} catch (PolicyException ex) {
// expected
}
control.verify();
}
Aggregations