use of org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor in project tomee by apache.
the class ConfigureCxfSecurity method setupWSS4JChain.
public static final void setupWSS4JChain(InterceptorProvider endpoint, Map<String, Object> inProps, Map<String, Object> outProps) {
if (null != inProps && !inProps.isEmpty()) {
endpoint.getInInterceptors().add(new SAAJInInterceptor());
endpoint.getInInterceptors().add(new WSS4JInInterceptor(inProps));
// if WS Security is used with a JAX-WS handler (See EjbInterceptor), we have to deal with mustUnderstand flag
// in WS Security headers. So, let's add an interceptor
endpoint.getInInterceptors().add(new WSSPassThroughInterceptor());
}
if (null != outProps && !outProps.isEmpty()) {
endpoint.getOutInterceptors().add(new SAAJOutInterceptor());
endpoint.getOutInterceptors().add(new WSS4JOutInterceptor(outProps));
}
}
use of org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor in project cxf by apache.
the class SamlTokenTest method makeInvocation.
private SoapMessage makeInvocation(Map<String, Object> outProperties, List<String> xpaths, Map<String, Object> inProperties, Map<String, String> inMessageProperties) throws Exception {
Document doc = readDocument("wsse-request-clean.xml");
WSS4JOutInterceptor ohandler = new WSS4JOutInterceptor();
PhaseInterceptor<SoapMessage> handler = ohandler.createEndingInterceptor();
SoapMessage msg = getSoapMessageForDom(doc);
for (String key : outProperties.keySet()) {
msg.put(key, outProperties.get(key));
}
handler.handleMessage(msg);
SOAPMessage saajMsg = msg.getContent(SOAPMessage.class);
doc = saajMsg.getSOAPPart();
for (String xpath : xpaths) {
assertValid(xpath, doc);
}
byte[] docbytes = getMessageBytes(doc);
XMLStreamReader reader = StaxUtils.createXMLStreamReader(new ByteArrayInputStream(docbytes));
DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setValidating(false);
dbf.setIgnoringComments(false);
dbf.setIgnoringElementContentWhitespace(true);
dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder();
db.setEntityResolver(new NullResolver());
StaxUtils.read(db, reader, false);
WSS4JInInterceptor inHandler = new WSS4JInInterceptor(inProperties);
SoapMessage inmsg = new SoapMessage(new MessageImpl());
inmsg.put(SecurityConstants.SAML_ROLE_ATTRIBUTENAME, "role");
for (String inMessageProperty : inMessageProperties.keySet()) {
inmsg.put(inMessageProperty, inMessageProperties.get(inMessageProperty));
}
Exchange ex = new ExchangeImpl();
ex.setInMessage(inmsg);
inmsg.setContent(SOAPMessage.class, saajMsg);
inHandler.handleMessage(inmsg);
return inmsg;
}
use of org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor in project cxf by apache.
the class Server method run.
protected void run() {
Bus bus = BusFactory.getDefaultBus();
setBus(bus);
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED);
inProperties.put(ConfigurationConstants.PW_CALLBACK_REF, new KeystorePasswordCallback());
inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "bob.properties");
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
bus.getInInterceptors().add(inInterceptor);
broker.updateWsdl(bus, "testutils/jms_test.wsdl");
Endpoint.publish(null, new SecurityGreeterImplTwoWayJMS());
}
use of org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor in project cxf by apache.
the class StaxToDOMSamlTest method testSaml2.
@Test
public void testSaml2() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_UNSIGNED);
final Map<QName, Object> customMap = new HashMap<>();
CustomSamlValidator validator = new CustomSamlValidator();
validator.setRequireSAML1Assertion(false);
customMap.put(WSConstants.SAML_TOKEN, validator);
customMap.put(WSConstants.SAML2_TOKEN, validator);
inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
inProperties.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
service.put(SecurityConstants.VALIDATE_SAML_SUBJECT_CONFIRMATION, "false");
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
WSSSecurityProperties properties = new WSSSecurityProperties();
List<WSSConstants.Action> actions = new ArrayList<>();
actions.add(WSSConstants.SAML_TOKEN_UNSIGNED);
properties.setActions(actions);
properties.setSamlCallbackHandler(new SAML2CallbackHandler());
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(properties);
client.getOutInterceptors().add(ohandler);
assertEquals("test", echo.echo("test"));
}
use of org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor in project cxf by apache.
the class StaxToDOMSamlTest method testSaml1TokenHOKConfig.
@Test
public void testSaml1TokenHOKConfig() throws Exception {
// Create + configure service
Service service = createService();
Map<String, Object> inProperties = new HashMap<>();
inProperties.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED + " " + ConfigurationConstants.SIGNATURE);
inProperties.put(ConfigurationConstants.SIG_VER_PROP_FILE, "insecurity.properties");
final Map<QName, Object> customMap = new HashMap<>();
CustomSamlValidator validator = new CustomSamlValidator();
customMap.put(WSConstants.SAML_TOKEN, validator);
customMap.put(WSConstants.SAML2_TOKEN, validator);
inProperties.put(WSS4JInInterceptor.VALIDATOR_MAP, customMap);
WSS4JInInterceptor inInterceptor = new WSS4JInInterceptor(inProperties);
service.getInInterceptors().add(inInterceptor);
// Create + configure client
Echo echo = createClientProxy();
Client client = ClientProxy.getClient(echo);
client.getInInterceptors().add(new LoggingInInterceptor());
client.getOutInterceptors().add(new LoggingOutInterceptor());
Map<String, Object> outConfig = new HashMap<>();
outConfig.put(ConfigurationConstants.ACTION, ConfigurationConstants.SAML_TOKEN_SIGNED);
SAML1CallbackHandler callbackHandler = new SAML1CallbackHandler();
callbackHandler.setSignAssertion(true);
callbackHandler.setConfirmationMethod(SAML1Constants.CONF_HOLDER_KEY);
outConfig.put(ConfigurationConstants.SAML_CALLBACK_REF, callbackHandler);
outConfig.put(ConfigurationConstants.PW_CALLBACK_REF, new PasswordCallbackHandler());
outConfig.put(ConfigurationConstants.SIGNATURE_USER, "alice");
outConfig.put(ConfigurationConstants.SIG_PROP_FILE, "alice.properties");
outConfig.put(ConfigurationConstants.SIG_KEY_ID, "DirectReference");
WSS4JStaxOutInterceptor ohandler = new WSS4JStaxOutInterceptor(outConfig);
client.getOutInterceptors().add(ohandler);
try {
echo.echo("test");
fail("Failure expected on receiving sender vouches instead of HOK");
} catch (javax.xml.ws.soap.SOAPFaultException ex) {
// expected
}
validator.setRequireSenderVouches(false);
assertEquals("test", echo.echo("test"));
}
Aggregations