Package org.apache.cxf.policytest.doubleit

Examples of org.apache.cxf.policytest.doubleit.DoubleItPortType


       
    }
   
    @Test
    public void testPolicy() throws Exception {
        DoubleItPortType pt;

        pt = service.getDoubleItPortXPath();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
       
       
        pt = service.getDoubleItPortEncryptThenSign();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));

       
        pt = service.getDoubleItPortSign();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));


        pt = service.getDoubleItPortSignThenEncrypt();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));
       
        ((BindingProvider)pt).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                      POLICY_SIGNENC_PROVIDER_ADDRESS);
        int x = pt.doubleIt(BigInteger.valueOf(5)).intValue();
        assertEquals(10, x);
       
        pt = service.getDoubleItPortHttps();
        updateAddressPort(pt, SSL_PORT);
        try {
            pt.doubleIt(BigInteger.valueOf(25));
        } catch (Exception ex) {
            String msg = ex.getMessage();
            if (!msg.contains("sername")) {
                throw ex;
            }
        }
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.USERNAME, "bob");
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "bob");
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.PASSWORD, "pwd");
        pt.doubleIt(BigInteger.valueOf(25));
       
        try {
            pt = service.getDoubleItPortHttp();
            updateAddressPort(pt, PORT);
            pt.doubleIt(BigInteger.valueOf(25));
            fail("https policy should have triggered");
        } catch (Exception ex) {
            String msg = ex.getMessage();
            if (!msg.contains("HttpsToken")) {
                throw ex;
View Full Code Here


    }
   
    @Test
    public void testSignedOnlyWithUnsignedMessage() throws Exception {
        //CXF-2244
        DoubleItPortType pt;

        pt = service.getDoubleItPortSignedOnly();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        //This should work as it should be properly signed.
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
       
        StringWriter swriter = new StringWriter();
        PrintWriter writer = new PrintWriter(swriter);
        try {
            ClientProxy.getClient(pt).getInInterceptors()
                .add(new LoggingInInterceptor("CheckFaultLogging", writer));
            pt.doubleIt(BigInteger.valueOf(-100));
            fail("Should have resulted in a DoubleItFault_Exception");
        } catch (DoubleItFault_Exception ex) {
            //expected
            writer.flush();
            String s = swriter.toString();
            s = s.substring(s.indexOf("Payload: ") + 9);
            s = s.substring(0, s.lastIndexOf("Envelope>") + 9);
            assertTrue("Content wasn't encrypted!", !s.contains("I don't like that."));
            //System.out.println(s);
            Document d = XMLUtils.parse(new InputSource(new StringReader(s)));
            Node nd = d.getDocumentElement().getFirstChild();
            while (nd != null && !"Body".equals(nd.getLocalName())) {
                nd = nd.getNextSibling();
            }
            if (nd == null) {
                throw ex;
            }
            System.out.println(s);
            Attr val = ((org.w3c.dom.Element)nd)
                .getAttributeNodeNS(PolicyConstants.WSU_NAMESPACE_URI, "Id");
            assertNotNull("No wsu:Id, thus, not signed", val);
        }

       
        //Try sending a message with the "TimestampOnly" policy into affect to the
        //service running the "signed only" policy.  This SHOULD fail as the
        //body is then not signed.
        pt = service.getDoubleItPortTimestampOnly();
        ((BindingProvider)pt).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                      POLICY_SIGNONLY_ADDRESS);
        try {
            pt.doubleIt(BigInteger.valueOf(5));
            fail("should have had a security/policy exception as the body wasn't signed");
        } catch (Exception ex) {
            assertTrue(ex.getMessage().contains("policy alternatives"));
        }
       
View Full Code Here

    public static class DoubleItImplCXF3042 extends AbstractDoubleItImpl {
    }
   
    @Test
    public void testCXF3041() throws Exception {
        DoubleItPortType pt;

        pt = service.getDoubleItPortCXF3041();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
    }
View Full Code Here

        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
    }

    @Test
    public void testCXF3042() throws Exception {
        DoubleItPortType pt;
        pt = service.getDoubleItPortCXF3042();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
    }
View Full Code Here

       
    }
   
    @Test
    public void testPolicy() throws Exception {
        DoubleItPortType pt;

        pt = service.getDoubleItPortXPath();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
       
       
        pt = service.getDoubleItPortEncryptThenSign();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));

       
        pt = service.getDoubleItPortSign();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));


        pt = service.getDoubleItPortSignThenEncrypt();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));
       
        ((BindingProvider)pt).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                      POLICY_SIGNENC_PROVIDER_ADDRESS);
        int x = pt.doubleIt(BigInteger.valueOf(5)).intValue();
        assertEquals(10, x);
       
        pt = service.getDoubleItPortHttps();
        updateAddressPort(pt, SSL_PORT);
        try {
            pt.doubleIt(BigInteger.valueOf(25));
        } catch (Exception ex) {
            String msg = ex.getMessage();
            if (!msg.contains("sername")) {
                throw ex;
            }
        }
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.USERNAME, "bob");
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "bob");
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.PASSWORD, "pwd");
        pt.doubleIt(BigInteger.valueOf(25));
       
        try {
            pt = service.getDoubleItPortHttp();
            updateAddressPort(pt, PORT);
            pt.doubleIt(BigInteger.valueOf(25));
            fail("https policy should have triggered");
        } catch (Exception ex) {
            String msg = ex.getMessage();
            if (!msg.contains("HttpsToken")) {
                throw ex;
View Full Code Here

    }
   
    @Test
    public void testSignedOnlyWithUnsignedMessage() throws Exception {
        //CXF-2244
        DoubleItPortType pt;

        pt = service.getDoubleItPortSignedOnly();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        //This should work as it should be properly signed.
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
       
        StringWriter swriter = new StringWriter();
        PrintWriter writer = new PrintWriter(swriter);
        try {
            ClientProxy.getClient(pt).getInInterceptors()
                .add(new LoggingInInterceptor("CheckFaultLogging", writer));
            pt.doubleIt(BigInteger.valueOf(-100));
            fail("Should have resulted in a DoubleItFault_Exception");
        } catch (DoubleItFault_Exception ex) {
            //expected
            writer.flush();
            String s = swriter.toString();
            s = s.substring(s.indexOf("Payload: ") + 9);
            s = s.substring(0, s.lastIndexOf("Envelope>") + 9);
            assertTrue("Content wasn't encrypted!", !s.contains("I don't like that."));
            //System.out.println(s);
            Document d = XMLUtils.parse(new InputSource(new StringReader(s)));
            Node nd = d.getDocumentElement().getFirstChild();
            while (nd != null && !"Body".equals(nd.getLocalName())) {
                nd = nd.getNextSibling();
            }
            if (nd == null) {
                throw ex;
            }
            //System.out.println(s);
            Attr val = ((org.w3c.dom.Element)nd)
                .getAttributeNodeNS(PolicyConstants.WSU_NAMESPACE_URI, "Id");
            assertNotNull("No wsu:Id, thus, not signed", val);
        }

       
        //Try sending a message with the "TimestampOnly" policy into affect to the
        //service running the "signed only" policy.  This SHOULD fail as the
        //body is then not signed.
        pt = service.getDoubleItPortTimestampOnly();
        ((BindingProvider)pt).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                      POLICY_SIGNONLY_ADDRESS);
        try {
            pt.doubleIt(BigInteger.valueOf(5));
            fail("should have had a security/policy exception as the body wasn't signed");
        } catch (Exception ex) {
            assertTrue(ex.getMessage().contains("policy alternatives"));
        }
       
View Full Code Here

    public static class DoubleItImplCXF3042 extends AbstractDoubleItImpl {
    }
   
    @Test
    public void testCXF3041() throws Exception {
        DoubleItPortType pt;

        pt = service.getDoubleItPortCXF3041();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
    }
View Full Code Here

        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
    }

    @Test
    public void testCXF3042() throws Exception {
        DoubleItPortType pt;
        pt = service.getDoubleItPortCXF3042();
        updateAddressPort(pt, PORT);
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
    }
View Full Code Here

    }
   
    @Test
    public void testPolicy() throws Exception {
        DoubleItService service = new DoubleItService();
        DoubleItPortType pt;

        pt = service.getDoubleItPortXPath();
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
       
       
        pt = service.getDoubleItPortEncryptThenSign();
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));
       
        pt = service.getDoubleItPortSign();
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));

       
        pt = service.getDoubleItPortSignThenEncrypt();
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        pt.doubleIt(BigInteger.valueOf(5));
       
        ((BindingProvider)pt).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                      POLICY_SIGNENC_PROVIDER_ADDRESS);
        int x = pt.doubleIt(BigInteger.valueOf(5)).intValue();
        assertEquals(10, x);
       
        pt = service.getDoubleItPortHttps();
        try {
            pt.doubleIt(BigInteger.valueOf(25));
        } catch (Exception ex) {
            String msg = ex.getMessage();
            if (!msg.contains("sername")) {
                throw ex;
            }
        }
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.USERNAME, "bob");
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_USERNAME, "bob");
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.PASSWORD, "pwd");
        pt.doubleIt(BigInteger.valueOf(25));
       
        try {
            pt = service.getDoubleItPortHttp();
            pt.doubleIt(BigInteger.valueOf(25));
            fail("https policy should have triggered");
        } catch (Exception ex) {
            String msg = ex.getMessage();
            if (!msg.contains("HttpsToken")) {
                throw ex;
View Full Code Here

   
    @Test
    public void testSignedOnlyWithUnsignedMessage() throws Exception {
        //CXF-2244
        DoubleItService service = new DoubleItService();
        DoubleItPortType pt;

        pt = service.getDoubleItPortSignedOnly();
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.CALLBACK_HANDLER,
                                                      new KeystorePasswordCallback());
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.SIGNATURE_PROPERTIES,
                                                      getClass().getResource("alice.properties"));
        ((BindingProvider)pt).getRequestContext().put(SecurityConstants.ENCRYPT_PROPERTIES,
                                                      getClass().getResource("bob.properties"));
        //This should work as it should be properly signed.
        assertEquals(BigInteger.valueOf(10), pt.doubleIt(BigInteger.valueOf(5)));
       
        //Try sending a message with the "TimestampOnly" policy into affect to the
        //service running the "signed only" policy.  This SHOULD fail as the
        //body is then not signed.
        pt = service.getDoubleItPortTimestampOnly();
        ((BindingProvider)pt).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY,
                                                      POLICY_SIGNONLY_ADDRESS);
        try {
            pt.doubleIt(BigInteger.valueOf(5));
            fail("should have had a security/policy exception as the body wasn't signed");
        } catch (Exception ex) {
            assertTrue(ex.getMessage().contains("policy alternatives"));
        }
       
View Full Code Here

TOP

Related Classes of org.apache.cxf.policytest.doubleit.DoubleItPortType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.