Search in sources :

Example 71 with WebServiceException

use of javax.xml.ws.WebServiceException in project wildfly by wildfly.

the class PojoEndpointAuthenticationTestCase method accessHelloWithBadPassword.

@Test
public void accessHelloWithBadPassword() throws Exception {
    URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-pojo/POJOAuthService?wsdl");
    Service service = Service.create(wsdlURL, serviceName);
    PojoEndpointIface proxy = service.getPort(PojoEndpointIface.class);
    Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
    reqContext.put(BindingProvider.USERNAME_PROPERTY, "user1");
    reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password-XYZ");
    try {
        proxy.hello("World");
        Assert.fail("Test should fail, HTTP response '401: Unauthorized' was expected");
    } catch (WebServiceException e) {
        // failure is expected
        Assert.assertTrue("HTTPException '401: Unauthorized' was expected", e.getCause().getMessage().contains("401: Unauthorized"));
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 72 with WebServiceException

use of javax.xml.ws.WebServiceException in project wildfly by wildfly.

the class PojoEndpointAuthenticationTestCase method accessHelloWithUnauthorizedUser.

@Test
public void accessHelloWithUnauthorizedUser() throws Exception {
    URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-pojo/POJOAuthService?wsdl");
    Service service = Service.create(wsdlURL, serviceName);
    PojoEndpointIface proxy = service.getPort(PojoEndpointIface.class);
    Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
    reqContext.put(BindingProvider.USERNAME_PROPERTY, "user3");
    reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password3");
    try {
        proxy.hello("World");
        Assert.fail("Test should fail, HTTP response '403: Forbidden' was expected");
    } catch (WebServiceException e) {
        // failure is expected
        Assert.assertTrue("String '403: Forbidden' was expected in " + e.getCause().getMessage(), e.getCause().getMessage().contains("403: Forbidden"));
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 73 with WebServiceException

use of javax.xml.ws.WebServiceException in project wildfly by wildfly.

the class EJBEndpointAuthenticationTestCase method accessHelloForNoneWithValidRole2.

@Test
public void accessHelloForNoneWithValidRole2() throws Exception {
    URL wsdlURL = new URL(baseUrl, "/jaxws-authentication-ejb3/EJB3AuthService?wsdl");
    Service service = Service.create(wsdlURL, serviceName);
    EJBEndpointIface proxy = service.getPort(EJBEndpointIface.class);
    Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
    reqContext.put(BindingProvider.USERNAME_PROPERTY, "user2");
    reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password2");
    try {
        proxy.helloForNone("World");
        Assert.fail("Test should fail, user shouldn't be allowed to invoke that method");
    } catch (WebServiceException e) {
        // failure is expected
        Assert.assertEquals(getNotAllowedExceptionMessage("helloForNone"), e.getCause().getMessage());
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 74 with WebServiceException

use of javax.xml.ws.WebServiceException in project wildfly by wildfly.

the class EJBEndpointNoClassLevelSecurityAnnotationAuthenticationTestCase method accessHelloForRolesWithInvalidRole.

@Test
public void accessHelloForRolesWithInvalidRole() throws Exception {
    URL wsdlURL = new URL(baseUrl, deploymentWsdlURL);
    Service service = Service.create(wsdlURL, serviceName);
    EJBEndpointIface proxy = service.getPort(EJBEndpointIface.class);
    Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
    reqContext.put(BindingProvider.USERNAME_PROPERTY, "user3");
    reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password3");
    try {
        proxy.helloForRoles("World");
        Assert.fail("Test should fail, user shouldn't be allowed to invoke that method");
    } catch (WebServiceException e) {
        // failure is expected
        Assert.assertEquals(getNotAllowedExceptionMessage("helloForRoles"), e.getCause().getMessage());
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Example 75 with WebServiceException

use of javax.xml.ws.WebServiceException in project wildfly by wildfly.

the class EJBEndpointNoClassLevelSecurityAnnotationAuthenticationTestCase method accessHelloForNoneWithValidRole1.

// ------------------------------------------------------------------------------
//
// Tests for helloForNone method
//
@Test
public void accessHelloForNoneWithValidRole1() throws Exception {
    URL wsdlURL = new URL(baseUrl, deploymentWsdlURL);
    Service service = Service.create(wsdlURL, serviceName);
    EJBEndpointIface proxy = service.getPort(EJBEndpointIface.class);
    Map<String, Object> reqContext = ((BindingProvider) proxy).getRequestContext();
    reqContext.put(BindingProvider.USERNAME_PROPERTY, "user1");
    reqContext.put(BindingProvider.PASSWORD_PROPERTY, "password1");
    try {
        proxy.helloForNone("World");
        Assert.fail("Test should fail, user shouldn't be allowed to invoke that method");
    } catch (WebServiceException e) {
        // failure is expected
        Assert.assertEquals(getNotAllowedExceptionMessage("helloForNone"), e.getCause().getMessage());
    }
}
Also used : WebServiceException(javax.xml.ws.WebServiceException) Service(javax.xml.ws.Service) BindingProvider(javax.xml.ws.BindingProvider) URL(java.net.URL) Test(org.junit.Test)

Aggregations

WebServiceException (javax.xml.ws.WebServiceException)120 Test (org.junit.Test)50 URL (java.net.URL)37 BindingProvider (javax.xml.ws.BindingProvider)25 Service (javax.xml.ws.Service)22 QName (javax.xml.namespace.QName)14 IOException (java.io.IOException)10 Message (org.apache.cxf.common.i18n.Message)9 JAXBException (javax.xml.bind.JAXBException)8 SOAPFaultException (javax.xml.ws.soap.SOAPFaultException)8 Bus (org.apache.cxf.Bus)7 Packet (com.sun.xml.ws.api.message.Packet)6 AuthStatus (javax.security.auth.message.AuthStatus)6 SOAPException (javax.xml.soap.SOAPException)6 SOAPMessage (javax.xml.soap.SOAPMessage)6 ArrayList (java.util.ArrayList)5 WebService (javax.jws.WebService)5 Subject (javax.security.auth.Subject)5 HttpSession (javax.servlet.http.HttpSession)5 Handler (javax.xml.ws.handler.Handler)5