Search in sources :

Example 61 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project midpoint by Evolveum.

the class TestWSSecurity method test121GetConfigAsNobodyWrongPasswordDigest.

@Test
public void test121GetConfigAsNobodyWrongPasswordDigest() throws Exception {
    final String TEST_NAME = "test121GetConfigAsNobodyWrongPasswordDigest";
    displayTestTitle(TEST_NAME);
    LogfileTestTailer tailer = createLogTailer();
    modelPort = createModelPort(USER_NOBODY_USERNAME, "wrongNobodyPassword", WSConstants.PW_DIGEST);
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    // WHEN
    try {
        modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
        AssertJUnit.fail("Unexpected success");
    } catch (SOAPFaultException e) {
        assertSoapSecurityFault(e, "FailedAuthentication", "could not be authenticated or authorized");
    }
    tailer.tail();
    assertAuditLoginFailed(tailer, "no authorizations");
}
Also used : LogfileTestTailer(com.evolveum.midpoint.test.util.LogfileTestTailer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.testng.annotations.Test)

Example 62 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project midpoint by Evolveum.

the class TestWSSecurity method test152GetConfigNoPasswordEmptyDigest.

@Test
public void test152GetConfigNoPasswordEmptyDigest() throws Exception {
    final String TEST_NAME = "test152GetConfigNoPasswordEmptyDigest";
    displayTestTitle(TEST_NAME);
    LogfileTestTailer tailer = createLogTailer();
    modelPort = createModelPort(USER_NOPASSWORD_USERNAME, " ", WSConstants.PW_DIGEST);
    Holder<ObjectType> objectHolder = new Holder<ObjectType>();
    Holder<OperationResultType> resultHolder = new Holder<OperationResultType>();
    // WHEN
    try {
        modelPort.getObject(getTypeQName(SystemConfigurationType.class), SystemObjectsType.SYSTEM_CONFIGURATION.value(), null, objectHolder, resultHolder);
        AssertJUnit.fail("Unexpected success");
    } catch (SOAPFaultException e) {
        assertSoapSecurityFault(e, "FailedAuthentication", "could not be authenticated or authorized");
    }
    tailer.tail();
    assertAuditLoginFailed(tailer, "no credentials in user");
}
Also used : LogfileTestTailer(com.evolveum.midpoint.test.util.LogfileTestTailer) ObjectType(com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType) OperationResultType(com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType) Holder(javax.xml.ws.Holder) SystemConfigurationType(com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Test(org.testng.annotations.Test)

Example 63 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.

the class HWDOMSourcePayloadProvider method invoke.

public DOMSource invoke(DOMSource request) {
    QName qn = (QName) ctx.getMessageContext().get(MessageContext.WSDL_OPERATION);
    if (qn == null) {
        throw new RuntimeException("No Operation Name");
    }
    DOMSource response = new DOMSource();
    Node n = request.getNode();
    if (n instanceof Document) {
        n = ((Document) n).getDocumentElement();
    }
    if (n.getLocalName().equals(sayHi.getLocalPart())) {
        response.setNode(sayHiResponse);
    } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
        Element el = DOMUtils.getFirstElement(n);
        String s = DOMUtils.getContent(el);
        if (s.trim().equals("throwFault")) {
            try {
                SOAPFactory f = SOAPFactory.newInstance();
                SOAPFault soapFault = f.createFault();
                soapFault.setFaultString("Test Fault String ****");
                Detail detail = soapFault.addDetail();
                detail = soapFault.getDetail();
                QName qName = new QName("http://www.Hello.org/greeter", "TestFault", "ns");
                DetailEntry de = detail.addDetailEntry(qName);
                qName = new QName("http://www.Hello.org/greeter", "ErrorCode", "ns");
                SOAPElement errorElement = de.addChildElement(qName);
                errorElement.setTextContent("errorcode");
                throw new SOAPFaultException(soapFault);
            } catch (SOAPException e) {
                e.printStackTrace();
            }
        }
        response.setNode(greetMeResponse);
    }
    return response;
}
Also used : DOMSource(javax.xml.transform.dom.DOMSource) QName(javax.xml.namespace.QName) DetailEntry(javax.xml.soap.DetailEntry) Node(org.w3c.dom.Node) SOAPElement(javax.xml.soap.SOAPElement) Element(org.w3c.dom.Element) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) Document(org.w3c.dom.Document) SOAPFactory(javax.xml.soap.SOAPFactory) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPFault(javax.xml.soap.SOAPFault) Detail(javax.xml.soap.Detail)

Example 64 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.

the class HWSoapMessageDocProvider method invoke.

public SOAPMessage invoke(SOAPMessage request) {
    QName qn = (QName) ctx.getMessageContext().get(MessageContext.WSDL_OPERATION);
    if (qn == null) {
        throw new RuntimeException("No Operation Name");
    }
    SOAPMessage response = null;
    SOAPBody body = null;
    try {
        body = SAAJUtils.getBody(request);
    } catch (SOAPException e) {
        return null;
    }
    Node n = body.getFirstChild();
    while (n.getNodeType() != Node.ELEMENT_NODE) {
        n = n.getNextSibling();
    }
    if (n.getLocalName().equals(sayHi.getLocalPart())) {
        response = sayHiResponse;
    } else if (n.getLocalName().equals(greetMe.getLocalPart())) {
        Element el = DOMUtils.getFirstElement(n);
        String v = DOMUtils.getContent(el);
        if (v.contains("Return sayHi")) {
            response = sayHiResponse;
        } else if (v.contains("exceed maxLength")) {
            response = greetMeResponseExceedMaxLengthRestriction;
        } else if (v.contains("throwFault")) {
            try {
                SOAPFactory f = SOAPFactory.newInstance();
                SOAPFault soapFault = f.createFault();
                soapFault.setFaultString("Test Fault String ****");
                Detail detail = soapFault.addDetail();
                detail = soapFault.getDetail();
                QName qName = new QName("http://www.Hello.org/greeter", "TestFault", "ns");
                DetailEntry de = detail.addDetailEntry(qName);
                qName = new QName("http://www.Hello.org/greeter", "ErrorCode", "ns");
                SOAPElement errorElement = de.addChildElement(qName);
                errorElement.setTextContent("errorcode");
                throw new SOAPFaultException(soapFault);
            } catch (SOAPException ex) {
            // ignore
            }
        } else {
            response = greetMeResponse;
        }
    }
    return response;
}
Also used : QName(javax.xml.namespace.QName) DetailEntry(javax.xml.soap.DetailEntry) Node(org.w3c.dom.Node) SOAPElement(javax.xml.soap.SOAPElement) Element(org.w3c.dom.Element) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) SOAPMessage(javax.xml.soap.SOAPMessage) SOAPFactory(javax.xml.soap.SOAPFactory) SOAPBody(javax.xml.soap.SOAPBody) SOAPException(javax.xml.soap.SOAPException) SOAPElement(javax.xml.soap.SOAPElement) SOAPFault(javax.xml.soap.SOAPFault) Detail(javax.xml.soap.Detail)

Example 65 with SOAPFaultException

use of javax.xml.ws.soap.SOAPFaultException in project cxf by apache.

the class ProviderRPCClientServerTest method doGreeterRPCLit.

private void doGreeterRPCLit(SOAPServiceRPCLit service, QName portName, int count, boolean doFault) throws Exception {
    String response1 = new String("TestGreetMeResponse");
    String response2 = new String("TestSayHiResponse");
    try {
        GreeterRPCLit greeter = service.getPort(portName, GreeterRPCLit.class);
        updateAddressPort(greeter, PORT);
        for (int idx = 0; idx < count; idx++) {
            String greeting = greeter.greetMe("Milestone-" + idx);
            assertNotNull("no response received from service", greeting);
            assertEquals(response1, greeting);
            String reply = greeter.sayHi();
            assertNotNull("no response received from service", reply);
            assertEquals(response2, reply);
            if (doFault) {
                try {
                    greeter.greetMe("throwFault");
                } catch (SOAPFaultException ex) {
                    assertNotNull(ex.getFault().getDetail());
                    try {
                        assertTrue(ex.getFault().getDetail().getDetailEntries().hasNext());
                    } catch (Exception e) {
                        e.printStackTrace();
                    }
                }
            }
        }
    } catch (UndeclaredThrowableException ex) {
        throw (Exception) ex.getCause();
    }
}
Also used : GreeterRPCLit(org.apache.hello_world_rpclit.GreeterRPCLit) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException) UndeclaredThrowableException(java.lang.reflect.UndeclaredThrowableException) SOAPFaultException(javax.xml.ws.soap.SOAPFaultException)

Aggregations

SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)97 Test (org.junit.Test)47 QName (javax.xml.namespace.QName)33 URL (java.net.URL)22 LogfileTestTailer (com.evolveum.midpoint.test.util.LogfileTestTailer)21 Test (org.testng.annotations.Test)21 Holder (javax.xml.ws.Holder)19 ObjectType (com.evolveum.midpoint.xml.ns._public.common.common_3.ObjectType)17 OperationResultType (com.evolveum.midpoint.xml.ns._public.common.common_3.OperationResultType)17 SystemConfigurationType (com.evolveum.midpoint.xml.ns._public.common.common_3.SystemConfigurationType)17 SOAPFault (javax.xml.soap.SOAPFault)17 SOAPException (javax.xml.soap.SOAPException)16 Service (javax.xml.ws.Service)11 WebServiceException (javax.xml.ws.WebServiceException)9 WSS4JOutInterceptor (org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor)9 SOAPMessage (javax.xml.soap.SOAPMessage)8 SoapFault (org.apache.cxf.binding.soap.SoapFault)8 Bus (org.apache.cxf.Bus)6 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)6 Fault (org.apache.cxf.interceptor.Fault)6