use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class PolicyUtilsTest method testGetRMConfiguration.
@Test
public void testGetRMConfiguration() {
RMConfiguration cfg = new RMConfiguration();
cfg.setBaseRetransmissionInterval(Long.valueOf(3000));
cfg.setExponentialBackoff(true);
Message message = control.createMock(Message.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(null);
control.replay();
assertSame(cfg, RMPolicyUtilities.getRMConfiguration(cfg, message));
control.verify();
control.reset();
AssertionInfoMap aim = control.createMock(AssertionInfoMap.class);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
Collection<AssertionInfo> ais = new ArrayList<>();
EasyMock.expect(aim.get(RM10Constants.RMASSERTION_QNAME)).andReturn(ais);
control.replay();
assertSame(cfg, RMPolicyUtilities.getRMConfiguration(cfg, message));
control.verify();
control.reset();
RMAssertion b = new RMAssertion();
BaseRetransmissionInterval bbri = new RMAssertion.BaseRetransmissionInterval();
bbri.setMilliseconds(Long.valueOf(2000));
b.setBaseRetransmissionInterval(bbri);
JaxbAssertion<RMAssertion> assertion = new JaxbAssertion<>();
assertion.setName(RM10Constants.RMASSERTION_QNAME);
assertion.setData(b);
AssertionInfo ai = new AssertionInfo(assertion);
ais.add(ai);
EasyMock.expect(message.get(AssertionInfoMap.class)).andReturn(aim);
EasyMock.expect(aim.get(RM10Constants.RMASSERTION_QNAME)).andReturn(ais);
control.replay();
RMConfiguration cfg1 = RMPolicyUtilities.getRMConfiguration(cfg, message);
assertNull(cfg1.getAcknowledgementInterval());
assertNull(cfg1.getInactivityTimeout());
assertEquals(2000L, cfg1.getBaseRetransmissionInterval().longValue());
assertTrue(cfg1.isExponentialBackoff());
control.verify();
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class PolicyBasedWSS4JStaxOutInterceptor method configureProperties.
@Override
protected void configureProperties(SoapMessage msg, OutboundSecurityContext outboundSecurityContext, WSSSecurityProperties securityProperties) throws WSSecurityException {
AssertionInfoMap aim = msg.get(AssertionInfoMap.class);
AssertionInfo asymAis = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.ASYMMETRIC_BINDING);
if (asymAis != null) {
checkAsymmetricBinding(msg, securityProperties);
asymAis.setAsserted(true);
}
AssertionInfo symAis = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.SYMMETRIC_BINDING);
if (symAis != null) {
checkSymmetricBinding(msg, securityProperties);
symAis.setAsserted(true);
}
AssertionInfo transAis = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.TRANSPORT_BINDING);
if (transAis != null) {
checkTransportBinding(msg, securityProperties);
transAis.setAsserted(true);
}
super.configureProperties(msg, outboundSecurityContext, securityProperties);
if (transAis != null) {
TransportBinding binding = (TransportBinding) transAis.getAssertion();
new StaxTransportBindingHandler(securityProperties, msg, binding, outboundSecurityContext).handleBinding();
} else if (asymAis != null) {
AsymmetricBinding binding = (AsymmetricBinding) asymAis.getAssertion();
new StaxAsymmetricBindingHandler(securityProperties, msg, binding, outboundSecurityContext).handleBinding();
} else if (symAis != null) {
SymmetricBinding binding = (SymmetricBinding) symAis.getAssertion();
new StaxSymmetricBindingHandler(securityProperties, msg, binding, outboundSecurityContext).handleBinding();
} else {
// Fall back to Transport Binding
new StaxTransportBindingHandler(securityProperties, msg, null, outboundSecurityContext).handleBinding();
}
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class AbstractBindingBuilder method getEncryptedParts.
public List<WSEncryptionPart> getEncryptedParts() throws SOAPException {
EncryptedParts parts = null;
EncryptedElements elements = null;
ContentEncryptedElements celements = null;
Collection<AssertionInfo> ais = getAllAssertionsByLocalname(SPConstants.ENCRYPTED_PARTS);
if (!ais.isEmpty()) {
for (AssertionInfo ai : ais) {
parts = (EncryptedParts) ai.getAssertion();
ai.setAsserted(true);
}
}
ais = getAllAssertionsByLocalname(SPConstants.ENCRYPTED_ELEMENTS);
if (!ais.isEmpty()) {
for (AssertionInfo ai : ais) {
elements = (EncryptedElements) ai.getAssertion();
ai.setAsserted(true);
}
}
ais = getAllAssertionsByLocalname(SPConstants.CONTENT_ENCRYPTED_ELEMENTS);
if (!ais.isEmpty()) {
for (AssertionInfo ai : ais) {
celements = (ContentEncryptedElements) ai.getAssertion();
ai.setAsserted(true);
}
}
if (parts == null && elements == null && celements == null) {
return new ArrayList<>();
}
List<WSEncryptionPart> securedParts = new ArrayList<>();
boolean isBody = false;
if (parts != null) {
isBody = parts.isBody();
for (Header head : parts.getHeaders()) {
WSEncryptionPart wep = new WSEncryptionPart(head.getName(), head.getNamespace(), "Header");
securedParts.add(wep);
}
Attachments attachments = parts.getAttachments();
if (attachments != null) {
String encModifier = "Element";
if (MessageUtils.getContextualBoolean(message, SecurityConstants.USE_ATTACHMENT_ENCRYPTION_CONTENT_ONLY_TRANSFORM, false)) {
encModifier = "Content";
}
WSEncryptionPart wep = new WSEncryptionPart("cid:Attachments", encModifier);
securedParts.add(wep);
}
}
// the encrypted list to prevent duplication / errors in encryption.
return getPartsAndElements(false, isBody, securedParts, elements == null ? null : elements.getXPaths(), celements == null ? null : celements.getXPaths());
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class AbstractStaxBindingHandler method configureLayout.
protected void configureLayout(AssertionInfoMap aim) {
AssertionInfo ai = PolicyUtils.getFirstAssertionByLocalname(aim, SPConstants.LAYOUT);
Layout layout = null;
if (ai != null) {
layout = (Layout) ai.getAssertion();
ai.setAsserted(true);
}
if (layout != null && layout.getLayoutType() != null) {
assertPolicy(new QName(layout.getName().getNamespaceURI(), layout.getLayoutType().name()));
}
if (!timestampAdded) {
return;
}
boolean timestampLast = layout != null && layout.getLayoutType() == LayoutType.LaxTsLast;
WSSConstants.Action actionToPerform = WSSConstants.TIMESTAMP;
List<WSSConstants.Action> actionList = properties.getActions();
if (timestampLast) {
actionList.add(0, actionToPerform);
} else {
actionList.add(actionToPerform);
}
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class StaxTransportBindingHandler method handleNonEndorsingSupportingTokens.
/**
* Handle the non-endorsing supporting tokens
*/
private void handleNonEndorsingSupportingTokens(AssertionInfoMap aim) throws Exception {
Collection<AssertionInfo> ais;
ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SIGNED_SUPPORTING_TOKENS);
if (!ais.isEmpty()) {
for (AssertionInfo ai : ais) {
SupportingTokens sgndSuppTokens = (SupportingTokens) ai.getAssertion();
if (sgndSuppTokens != null) {
addSignedSupportingTokens(sgndSuppTokens);
}
ai.setAsserted(true);
}
}
ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SIGNED_ENCRYPTED_SUPPORTING_TOKENS);
if (!ais.isEmpty()) {
for (AssertionInfo ai : ais) {
SupportingTokens sgndSuppTokens = (SupportingTokens) ai.getAssertion();
if (sgndSuppTokens != null) {
addSignedSupportingTokens(sgndSuppTokens);
}
ai.setAsserted(true);
}
}
ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.ENCRYPTED_SUPPORTING_TOKENS);
if (!ais.isEmpty()) {
for (AssertionInfo ai : ais) {
SupportingTokens encrSuppTokens = (SupportingTokens) ai.getAssertion();
if (encrSuppTokens != null) {
addSignedSupportingTokens(encrSuppTokens);
}
ai.setAsserted(true);
}
}
ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SUPPORTING_TOKENS);
if (!ais.isEmpty()) {
for (AssertionInfo ai : ais) {
SupportingTokens suppTokens = (SupportingTokens) ai.getAssertion();
if (suppTokens != null && suppTokens.getTokens() != null && suppTokens.getTokens().size() > 0) {
handleSupportingTokens(suppTokens, false, false);
}
ai.setAsserted(true);
}
}
}
Aggregations