use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class CustomPolicyAlgorithmsTest method testSHA256AsymSigAlgorithm.
@Test
public void testSHA256AsymSigAlgorithm() throws Exception {
final String rsaSha2SigMethod = "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256";
String policyName = "signed_elements_policy.xml";
Policy policy = policyBuilder.getPolicy(this.getResourceAsStream(policyName));
AssertionInfoMap aim = new AssertionInfoMap(policy);
AssertionInfo assertInfo = aim.get(SP12Constants.ASYMMETRIC_BINDING).iterator().next();
AsymmetricBinding binding = (AsymmetricBinding) assertInfo.getAssertion();
// set Signature Algorithm to RSA SHA-256
binding.getAlgorithmSuite().getAlgorithmSuiteType().setAsymmetricSignature(rsaSha2SigMethod);
String sigMethod = binding.getAlgorithmSuite().getAlgorithmSuiteType().getAsymmetricSignature();
assertNotNull(sigMethod);
assertEquals(rsaSha2SigMethod, sigMethod);
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project cxf by apache.
the class SCTTokenValidator method validate.
public Credential validate(Credential credential, RequestData data) throws WSSecurityException {
// Sleep to make sure token gets replicated
try {
Thread.sleep(2 * 1000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Credential validatedCredential = super.validate(credential, data);
// Hack to verify the IssuedToken assertion, as this is not done by default in CXF for a
// SecurityContextToken
SoapMessage soapMessage = (SoapMessage) data.getMsgContext();
AssertionInfoMap aim = soapMessage.get(AssertionInfoMap.class);
Collection<AssertionInfo> ais = aim.get(SP12Constants.ISSUED_TOKEN);
for (AssertionInfo ai : ais) {
ai.setAsserted(true);
}
return validatedCredential;
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project tesb-rt-se by Talend.
the class SchemaValidationPolicyAbstractInterceptor method handleMessageWithAssertionInfo.
protected void handleMessageWithAssertionInfo(Message message) throws Fault {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (null == aim) {
return;
}
Collection<AssertionInfo> ais = aim.get(SchemaValidationPolicyBuilder.SCHEMA_VALIDATION);
if (null == ais) {
return;
}
for (AssertionInfo ai : ais) {
if (ai.getAssertion() instanceof SchemaValidationPolicy) {
SchemaValidationPolicy vPolicy = (SchemaValidationPolicy) ai.getAssertion();
ValidationType vldType = vPolicy.getValidationType();
AppliesToType appliesToType = vPolicy.getApplyToType();
MessageType msgType = vPolicy.getMessageType();
String customSchemaPath = vPolicy.getCustomSchemaPath();
if (vldType != ValidationType.WSDLSchema) {
ai.setAsserted(true);
}
if (shouldSchemaValidate(message, msgType, appliesToType)) {
if (vldType == ValidationType.CustomSchema) {
// load custom schema from external source
try {
loadCustomSchema(message, customSchemaPath, this.getClass());
} catch (IOException ex) {
throw new RuntimeException("Can not load custom schema", ex);
}
}
// do schema validation by setting value to
// "schema-validation-enabled" property
validateBySettingProperty(message);
}
ai.setAsserted(true);
}
ai.setAsserted(true);
}
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project tesb-rt-se by Talend.
the class SamEnablingInterceptorProvider method process.
static void process(Message message) {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (aim != null) {
Collection<AssertionInfo> ais = aim.get(SamEnablingPolicyBuilder.SAM_ENABLE);
if (ais != null) {
for (AssertionInfo ai : ais) {
if (ai.getAssertion() instanceof SamEnablingPolicy) {
SamEnablingPolicy vPolicy = (SamEnablingPolicy) ai.getAssertion();
AppliesToType appliesToType = vPolicy.getAppliesToType();
// Service service = ServiceModelUtil.getService(message
// .getExchange());
Exchange ex = message.getExchange();
Bus b = ex.getBus();
if (b.getFeatures().contains(EventFeature.class)) {
ai.setAsserted(true);
return;
}
Endpoint ep = ex.getEndpoint();
Bundle bundle = FrameworkUtil.getBundle(SamEnablingInterceptorProvider.class);
EventFeature eventFeature = null;
if (bundle != null) {
// OSGi
BundleContext context = FrameworkUtil.getBundle(SamEnablingInterceptorProvider.class).getBundleContext();
ServiceReference sref = context.getServiceReference(EventFeature.class.getName());
eventFeature = (EventFeature) context.getService(sref);
} else {
// non-OSGi
if (springContext == null) {
throw springContextException;
}
eventFeature = (EventFeature) springContext.getBean("eventFeature");
}
if (MessageUtils.isRequestor(message)) {
if (MessageUtils.isOutbound(message)) {
// REQ_OUT
if ((appliesToType == AppliesToType.consumer || appliesToType == AppliesToType.always)) {
Client cli = ex.get(Client.class);
if (!cli.getOutInterceptors().contains(WireTapOut.class)) {
eventFeature.initialize(cli, b);
List<Interceptor<? extends Message>> outInterceptors = cli.getOutInterceptors();
message.getInterceptorChain().add(outInterceptors);
outInterceptors.getClass();
}
}
} else {
// RESP_IN
if ((appliesToType == AppliesToType.consumer || appliesToType == AppliesToType.always)) {
Client cli = ex.get(Client.class);
eventFeature.initialize(cli, b);
}
}
} else {
ServerRegistry registry = b.getExtension(ServerRegistry.class);
List<Server> servers = registry.getServers();
if (MessageUtils.isOutbound(message)) {
// RESP_OUT
if ((appliesToType == AppliesToType.provider || appliesToType == AppliesToType.always)) {
for (Server sr : servers) {
EndpointInfo ei = sr.getEndpoint().getEndpointInfo();
if (null != ei && ei.getAddress().equals(ep.getEndpointInfo().getAddress())) {
eventFeature.initialize(sr, b);
}
}
}
} else {
// REQ_IN
if ((appliesToType == AppliesToType.provider || appliesToType == AppliesToType.always)) {
for (Server sr : servers) {
EndpointInfo ei = sr.getEndpoint().getEndpointInfo();
if (null != ei && ei.getAddress().equals(ep.getEndpointInfo().getAddress()) && (!sr.getEndpoint().getInInterceptors().contains(WireTapIn.class))) {
eventFeature.initialize(sr, b);
List<Interceptor<? extends Message>> inInterceptors = sr.getEndpoint().getInInterceptors();
message.getInterceptorChain().add(inInterceptors);
}
}
}
}
}
}
}
}
for (AssertionInfo ai : ais) {
ai.setAsserted(true);
}
}
}
use of org.apache.cxf.ws.policy.AssertionInfoMap in project tesb-rt-se by Talend.
the class CorrelationIDInterceptorProvider method process.
static void process(Message message) throws SAXException, IOException, ParserConfigurationException {
AssertionInfoMap aim = message.get(AssertionInfoMap.class);
if (aim != null) {
Collection<AssertionInfo> ais = aim.get(CorrelationIDPolicyBuilder.CORRELATION_ID);
if (ais == null) {
return;
}
for (AssertionInfo ai : ais) {
if (ai.getAssertion() instanceof CorrelationIDAssertion) {
CorrelationIDAssertion cAssertion = (CorrelationIDAssertion) ai.getAssertion();
MethodType mType = cAssertion.getMethodType();
// String value = cAssetrion.getValue();
String correlationId = null;
// get ID from Http header
correlationId = CorrelationIdProtocolHeaderCodec.readCorrelationId(message);
// get ID from SOAP header
if (null == correlationId) {
correlationId = CorrelationIdSoapCodec.readCorrelationId(message);
}
// get from message
if (null == correlationId) {
// Get ID from Message
correlationId = (String) message.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
}
if ((message.getContent(javax.xml.stream.XMLStreamWriter.class) != null) && (message.getContent(javax.xml.stream.XMLStreamWriter.class) instanceof SAAJStreamWriter)) {
NodeList nodeList = ((SAAJStreamWriter) message.getContent(javax.xml.stream.XMLStreamWriter.class)).getDocument().getElementsByTagNameNS("http://www.talend.com/esb/sam/correlationId/v1", "correlationId");
if (nodeList.getLength() > 0) {
correlationId = nodeList.item(0).getTextContent();
}
}
// get from message exchange
if (null == correlationId) {
// Get ID from Message exchange
Exchange ex = message.getExchange();
if (null != ex) {
Message reqMsg = null;
if (MessageUtils.isOutbound(message)) {
reqMsg = ex.getInMessage();
} else {
reqMsg = ex.getOutMessage();
}
if (null != reqMsg) {
correlationId = (String) reqMsg.get(CorrelationIDFeature.MESSAGE_CORRELATION_ID);
}
}
}
// If correlationId is null we should add it to headers
if (null == correlationId) {
if (MethodType.XPATH.equals(mType)) {
XPathProcessor proc = new XPathProcessor(cAssertion, message);
correlationId = proc.getCorrelationID();
} else if (MethodType.CALLBACK.equals(mType)) {
CorrelationIDCallbackHandler handler = (CorrelationIDCallbackHandler) message.get(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
if (null == handler) {
handler = (CorrelationIDCallbackHandler) message.getContextualProperty(CorrelationIDFeature.CORRELATION_ID_CALLBACK_HANDLER);
}
if (handler != null)
correlationId = handler.getCorrelationId();
}
// request
if (null == correlationId) {
correlationId = ContextUtils.generateUUID();
}
}
message.put(CorrelationIDFeature.MESSAGE_CORRELATION_ID, correlationId);
// MessageUtils.isOutbound(message)) {// RESP_OUT
if (isRestMessage(message)) {
// Add correlationId to http header
if (null == CorrelationIdProtocolHeaderCodec.readCorrelationId(message)) {
CorrelationIdProtocolHeaderCodec.writeCorrelationId(message, correlationId);
}
} else {
// Add correlationId to soap header
if (null == CorrelationIdSoapCodec.readCorrelationId(message)) {
CorrelationIdSoapCodec.writeCorrelationId(message, correlationId);
}
}
// }
ai.setAsserted(true);
}
}
}
}
Aggregations