Package org.apache.cxf.ws.policy

Examples of org.apache.cxf.ws.policy.PolicyAssertion


        }
        return tokenStore;
    }
    static PolicyAssertion getAddressingPolicy(AssertionInfoMap aim, boolean optional) {
        Collection<AssertionInfo> lst = aim.get(MetadataConstants.USING_ADDRESSING_2004_QNAME);
        PolicyAssertion assertion = null;
        if (null != lst && !lst.isEmpty()) {
            assertion = lst.iterator().next().getAssertion();
        }
        if (assertion == null) {
            lst = aim.get(MetadataConstants.USING_ADDRESSING_2005_QNAME);
            if (null != lst && !lst.isEmpty()) {
                assertion = lst.iterator().next().getAssertion();
            }
        }
        if (assertion == null) {
            lst = aim.get(MetadataConstants.USING_ADDRESSING_2006_QNAME);
            if (null != lst && !lst.isEmpty()) {
                assertion = lst.iterator().next().getAssertion();
            }
        }
        if (assertion == null) {
            return new PrimitiveAssertion(MetadataConstants.USING_ADDRESSING_2006_QNAME,
                                          optional);
        } else if (optional) {
            return new PrimitiveAssertion(assertion.getName(),
                                          optional);           
        }
        return assertion;
    }
View Full Code Here


                    //Cancel and Renew just sign with the token
                    Policy p = new Policy();
                    ExactlyOne ea = new ExactlyOne();
                    p.addPolicyComponent(ea);
                    All all = new All();
                    PolicyAssertion ass = SecureConversationTokenInterceptorProvider
                        .getAddressingPolicy(aim, false);
                    all.addPolicyComponent(ass);
                    ea.addPolicyComponent(all);
                    PolicyBuilder pbuilder = message.getExchange().getBus()
                        .getExtension(PolicyBuilder.class);
                    SymmetricBinding binding = new SymmetricBinding(SP12Constants.INSTANCE, pbuilder);
                    binding.setIncludeTimestamp(true);
                    ProtectionToken token = new ProtectionToken(SP12Constants.INSTANCE, pbuilder);
                    token.setToken(new SecureConversationToken(SP12Constants.INSTANCE));
                    binding.setProtectionToken(token);
                    binding.setEntireHeadersAndBodySignatures(true);
                   
                    Binding origBinding = getBinding(aim);
                    binding.setAlgorithmSuite(origBinding.getAlgorithmSuite());
                    all.addPolicyComponent(binding);
                   
                    SignedEncryptedParts parts = new SignedEncryptedParts(true,
                                                                          SP12Constants.INSTANCE);
                    parts.setBody(true);
                    if (addNs != null) {
                        parts.addHeader(new Header("To", addNs));
                        parts.addHeader(new Header("From", addNs));
                        parts.addHeader(new Header("FaultTo", addNs));
                        parts.addHeader(new Header("ReplyTO", addNs));
                        parts.addHeader(new Header("MessageID", addNs));
                        parts.addHeader(new Header("RelatesTo", addNs));
                        parts.addHeader(new Header("Action", addNs));
                    }
                    all.addPolicyComponent(parts);
                    pol = p;
                    message.getInterceptorChain().add(SecureConversationTokenFinderInterceptor.INSTANCE);
                } else {
                    Policy p = new Policy();
                    ExactlyOne ea = new ExactlyOne();
                    p.addPolicyComponent(ea);
                    All all = new All();
                    PolicyAssertion ass = SecureConversationTokenInterceptorProvider
                        .getAddressingPolicy(aim, false);
                    all.addPolicyComponent(ass);
                    ea.addPolicyComponent(all);
                    pol = p.merge(pol);
                }
View Full Code Here

                    //Cancel and Renew just sign with the token
                    Policy p = new Policy();
                    ExactlyOne ea = new ExactlyOne();
                    p.addPolicyComponent(ea);
                    All all = new All();
                    PolicyAssertion ass = SecureConversationTokenInterceptorProvider
                        .getAddressingPolicy(aim, false);
                    all.addPolicyComponent(ass);
                    ea.addPolicyComponent(all);
                    SymmetricBinding binding = new SymmetricBinding(SP12Constants.INSTANCE);
                    binding.setIncludeTimestamp(true);
                    ProtectionToken token = new ProtectionToken(SP12Constants.INSTANCE);
                    token.setToken(new SecureConversationToken(SP12Constants.INSTANCE));
                    binding.setProtectionToken(token);
                    binding.setEntireHeadersAndBodySignatures(true);
                   
                    Binding origBinding = getBinding(aim);
                    binding.setAlgorithmSuite(origBinding.getAlgorithmSuite());
                    all.addPolicyComponent(binding);
                   
                    SignedEncryptedParts parts = new SignedEncryptedParts(true,
                                                                          SP12Constants.INSTANCE);
                    parts.setBody(true);
                    if (addNs != null) {
                        parts.addHeader(new Header("To", addNs));
                        parts.addHeader(new Header("From", addNs));
                        parts.addHeader(new Header("FaultTo", addNs));
                        parts.addHeader(new Header("ReplyTO", addNs));
                        parts.addHeader(new Header("MessageID", addNs));
                        parts.addHeader(new Header("RelatesTo", addNs));
                        parts.addHeader(new Header("Action", addNs));
                    }
                    all.addPolicyComponent(parts);
                    pol = p;
                    message.getInterceptorChain().add(SecureConversationTokenFinderInterceptor.INSTANCE);
                } else {
                    Policy p = new Policy();
                    ExactlyOne ea = new ExactlyOne();
                    p.addPolicyComponent(ea);
                    All all = new All();
                    PolicyAssertion ass = SecureConversationTokenInterceptorProvider
                        .getAddressingPolicy(aim, false);
                    all.addPolicyComponent(ass);
                    ea.addPolicyComponent(all);
                    pol = p.merge(pol);
                }
View Full Code Here

        policies = buildTestPolicies();
    }
   
    @Test
    public void testNoNeedToAssertWithEmptyPolicy() {
        PolicyAssertion a = new NestedPrimitiveAssertion(
                                new QName("abc"), false, null, false,
                                null);
        AssertionInfoMap aim = new AssertionInfoMap(
                                Collections.singletonList(a));
        assertTrue("No need to assert", a.isAsserted(aim));
        a = new NestedPrimitiveAssertion(new QName("abc"),
                                         false,
                                         null,
                                         false,
                                         null);
        assertTrue("No need to assert", a.isAsserted(aim));
    }
View Full Code Here

    }
   
   
    @Test
    public void testNoNeedToAssertWithNonEmptyPolicy() {
        PolicyAssertion a = new NestedPrimitiveAssertion(
                                new QName("abc"), false, null, false,
                                null);
        AssertionInfoMap aim = new AssertionInfoMap(
                                Collections.singletonList(a));
        assertTrue("No need to assert", a.isAsserted(aim));
        Policy p = new Policy();
        p.addAssertion(new PrimitiveAssertion(new QName("abc"), false));
        a = new NestedPrimitiveAssertion(new QName("abc"),
                                         false,
                                         p,
                                         false,
                                         null);
        assertFalse("Primitive Assertions need to be asserted",
                    a.isAsserted(aim));
       
        p = new Policy();
        p.addAssertion(new NestedPrimitiveAssertion(new QName("abc"),
                                         false,
                                         null,
                                         false,
                                         null));
        a = new NestedPrimitiveAssertion(new QName("abc"),
                                         false,
                                         p,
                                         false,
                                         null);
        assertTrue("No need to assert", a.isAsserted(aim));
    }
View Full Code Here

    }
   
   
    @Test
    public void testAsserted() {
        PolicyAssertion a1 =
            new CustomPrimitiveAssertion(new QName("abc"), 1);
        PolicyAssertion a2 =
            new CustomPrimitiveAssertion(new QName("abc"), 2);
        Policy nested = new Policy();
        All all = new All();
        all.addAssertion(a2);
        nested.addPolicyComponent(all);
       
        NestedPrimitiveAssertion na = new NestedPrimitiveAssertion(new QName("nested"),
                                         false,
                                         nested,
                                         true,
                                         null);
        List<PolicyAssertion> ais =
            new ArrayList<PolicyAssertion>();
       
        ais.add(a1);
        ais.add(a2);
        ais.add(na);
               
        AssertionInfoMap aim = new AssertionInfoMap(ais);
       
        assertFalse("Assertion has been asserted even though nether na nor a2 have been",
                    na.isAsserted(aim));
       
        assertAssertion(aim, new QName("nested"), true, true);
        assertFalse("Assertion has been asserted even though a2 has not been",
                    na.isAsserted(aim));
       
        // assert a1 only
        assertAssertion(aim, new QName("abc"), true, false);
        assertFalse("Assertion has been asserted even though a2 has not been",
                    na.isAsserted(aim));
        // assert a2 tpp
        assertAssertion(aim, new QName("abc"), true, true);
        assertTrue("Assertion has not been asserted even though both na nad a2 have been",
                    na.isAsserted(aim));
       
        PolicyAssertion a3 = new CustomPrimitiveAssertion(new QName("abc"), 3);
        all.addAssertion(a3);
        aim.getAssertionInfo(new QName("abc")).add(new AssertionInfo(a3));
       
        assertFalse("Assertion has been asserted even though a3 has not been",
                    na.isAsserted(aim));
View Full Code Here

    }
   
      
    @Test
    public void testEqual() {
        PolicyAssertion other = new PrimitiveAssertion(new QName("abc"));
        for (int i = 0; i < policies.length; i++) {
            PolicyAssertion a =
                (PolicyAssertion)policies[i].getFirstPolicyComponent();
            assertTrue("Assertion " + i + " should equal itself.", a.equal(a));
            assertTrue("Assertion " + i + " should not equal other.", !a.equal(other));
            for (int j = i + 1; j < policies.length; j++) {
                Assertion b = (Assertion)policies[j].getFirstPolicyComponent();
                if (j == 1) {
                    assertTrue("Assertion " + i + " should equal " + j + ".", a.equal(b));
                } else {
                    assertTrue("Assertion " + i + " unexpectedly equals assertion " + j + ".", !a.equal(b));
                }
            }
        }
    }
View Full Code Here

        Assertor assertor = control.createMock(Assertor.class);
              
        Policy policy = new Policy();
        ExactlyOne ea = new ExactlyOne();
        All all = new All();
        PolicyAssertion a1 = new TestAssertion();
        all.addAssertion(a1);
        ea.addPolicyComponent(all);
        Collection<PolicyAssertion> maxAlternative =
            CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
        all = new All();
View Full Code Here

        Assertor assertor = control.createMock(Assertor.class);
              
        Policy policy = new Policy();
        ExactlyOne ea = new ExactlyOne();
        All all = new All();
        PolicyAssertion a1 = new TestAssertion();
        all.addAssertion(a1);
        ea.addPolicyComponent(all);
        Collection<PolicyAssertion> maxAlternative =
            CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
        all = new All();
View Full Code Here

        Assertor assertor = control.createMock(Assertor.class);
              
        Policy policy = new Policy();
        ExactlyOne ea = new ExactlyOne();
        All all = new All();
        PolicyAssertion a1 = new TestAssertion();
        all.addAssertion(a1);
        ea.addPolicyComponent(all);
        Collection<PolicyAssertion> firstAlternative =
            CastUtils.cast(all.getPolicyComponents(), PolicyAssertion.class);
        policy.addPolicyComponent(ea);
View Full Code Here

TOP

Related Classes of org.apache.cxf.ws.policy.PolicyAssertion

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.