use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class SpnegoContextTokenOutInterceptor method handleMessage.
public void handleMessage(SoapMessage message) throws Fault {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
// extract Assertion information
if (aim != null) {
Collection<AssertionInfo> ais = PolicyUtils.getAllAssertionsByLocalname(aim, SPConstants.SPNEGO_CONTEXT_TOKEN);
if (ais.isEmpty()) {
return;
}
if (isRequestor(message)) {
String tokId = (String) message.getContextualProperty(SecurityConstants.TOKEN_ID);
SecurityToken tok = null;
try {
if (tokId != null) {
tok = TokenStoreUtils.getTokenStore(message).getToken(tokId);
if (tok != null && tok.isExpired()) {
message.getExchange().getEndpoint().remove(SecurityConstants.TOKEN_ID);
message.getExchange().remove(SecurityConstants.TOKEN_ID);
TokenStoreUtils.getTokenStore(message).remove(tokId);
tok = null;
}
}
if (tok == null) {
tok = issueToken(message, aim);
}
for (AssertionInfo ai : ais) {
ai.setAsserted(true);
}
message.getExchange().getEndpoint().put(SecurityConstants.TOKEN_ID, tok.getId());
message.getExchange().put(SecurityConstants.TOKEN_ID, tok.getId());
TokenStoreUtils.getTokenStore(message).add(tok);
} catch (TokenStoreException ex) {
throw new Fault(ex);
}
} else {
// server side should be checked on the way in
for (AssertionInfo ai : ais) {
ai.setAsserted(true);
}
}
}
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class PolicyUtils method getFirstAssertionByLocalname.
public static AssertionInfo getFirstAssertionByLocalname(AssertionInfoMap aim, String localname) {
Collection<AssertionInfo> sp11Ais = aim.get(new QName(SP11Constants.SP_NS, localname));
if (sp11Ais != null && !sp11Ais.isEmpty()) {
return sp11Ais.iterator().next();
}
Collection<AssertionInfo> sp12Ais = aim.get(new QName(SP12Constants.SP_NS, localname));
if (sp12Ais != null && !sp12Ais.isEmpty()) {
return sp12Ais.iterator().next();
}
return null;
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class RMPolicyUtilities method getRMConfiguration.
/**
* Returns an RMAssertion that is compatible with the default value and all RMAssertions pertaining to the
* message (can never be null).
*
* @param defaultValue the default value (non-<code>null</code>)
* @param message the message
* @return the compatible RMAssertion
*/
public static RMConfiguration getRMConfiguration(RMConfiguration defaultValue, Message message) {
RMConfiguration compatible = defaultValue;
Collection<AssertionInfo> ais = collectRMAssertions(message.get(AssertionInfoMap.class));
for (AssertionInfo ai : ais) {
if (ai.getAssertion() instanceof JaxbAssertion<?>) {
RMAssertion rma = (RMAssertion) ((JaxbAssertion<?>) ai.getAssertion()).getData();
compatible = intersect(rma, compatible);
} else if (ai.getAssertion() instanceof PrimitiveAssertion) {
PrimitiveAssertion assertion = (PrimitiveAssertion) ai.getAssertion();
if (RM11Constants.WSRMP_NAMESPACE_URI.equals(assertion.getName().getNamespaceURI())) {
compatible = intersect(assertion, compatible);
}
}
}
return compatible;
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class MAPAggregatorImpl method setupNamespace.
private void setupNamespace(AddressingProperties maps, Message message) {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
String ns = (String) message.getContextualProperty(MAPAggregator.ADDRESSING_NAMESPACE);
if (ns != null) {
maps.exposeAs(ns);
}
return;
}
Collection<AssertionInfo> aic = aim.getAssertionInfo(MetadataConstants.USING_ADDRESSING_2004_QNAME);
if (aic != null && !aic.isEmpty()) {
maps.exposeAs(Names200408.WSA_NAMESPACE_NAME);
}
}
use of org.apache.cxf.ws.policy.AssertionInfo in project cxf by apache.
the class AbstractPolicySecurityTest method runOutInterceptorAndValidate.
protected Document runOutInterceptorAndValidate(SoapMessage msg, Policy policy, AssertionInfoMap aim, List<QName> assertedOutAssertions, List<QName> notAssertedOutAssertions) throws Exception {
if (msg.getExchange().getEndpoint() != null && msg.getExchange().getEndpoint().getEndpointInfo().getProperty(TokenStore.class.getName()) == null) {
msg.put(SecurityConstants.TOKEN_STORE_CACHE_INSTANCE, new MemoryTokenStore());
}
this.getOutInterceptor().handleMessage(msg);
try {
aim.checkEffectivePolicy(policy);
} catch (PolicyException e) {
// Expected but not relevant
} finally {
if (assertedOutAssertions != null) {
for (QName assertionType : assertedOutAssertions) {
Collection<AssertionInfo> ais = aim.get(assertionType);
assertNotNull(ais);
for (AssertionInfo ai : ais) {
checkAssertion(aim, assertionType, ai, true);
}
}
}
if (notAssertedOutAssertions != null) {
for (QName assertionType : notAssertedOutAssertions) {
Collection<AssertionInfo> ais = aim.get(assertionType);
assertNotNull(ais);
for (AssertionInfo ai : ais) {
checkAssertion(aim, assertionType, ai, false);
}
}
}
}
return msg.getContent(SOAPMessage.class).getSOAPPart();
}
Aggregations