An open API service indexing awesome lists of open source software.

https://github.com/giosil/wservices

Boilerplate for web services implementation with security handler chain example.
https://github.com/giosil/wservices

java javaee soap soap-web-services soap-webservice

Last synced: 2 months ago
JSON representation

Boilerplate for web services implementation with security handler chain example.

Awesome Lists containing this project

README

        

# WServices

Boilerplate for web services implementation with security handler chain example.

## Build

- `git clone https://github.com/giosil/wservices.git`
- `mvn clean install`

## Test Client

For more details see src/test/java.

```java
boolean traceEnabled = true;

Hello_Service service = new Hello_Service();

IHelloService hello = service.getHelloServicesPort();

if(hello instanceof BindingProvider) {

BindingProvider bindingProvider = (BindingProvider) hello;

Map requestContext = bindingProvider.getRequestContext();

requestContext.put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, "http://localhost:8080/wservices/hello/HelloServices?g=Ciao");
// Basic Auth
requestContext.put(BindingProvider.USERNAME_PROPERTY, "admin");
requestContext.put(BindingProvider.PASSWORD_PROPERTY, "admin");

// Add handler chain programmatically
Binding binding = bindingProvider.getBinding();

@SuppressWarnings("rawtypes")
List handlerChain = binding.getHandlerChain();

handlerChain.add(new WSSecurityHandler(traceEnabled));

// ... If the returned chain is modified a call to setHandlerChainis
// required to configure the binding instance with the new chain.
binding.setHandlerChain(handlerChain);
}

String result = hello.hello("World");
```

## Generate Client

`wsimport -s src -d out -p org.dew.hello.client http://localhost:8080/wservices/hello/HelloServices?wsdl`

## Notice

If you use **org.jcp.xml.dsig.internal.dom.XMLDSigRI** in **org.dew.test.WSSecurityHandler** you have to disable restrictions of javac adding *-XDignore.symbol.file* in compiler arguments.

```xml
...


org.apache.maven.plugins
maven-compiler-plugin
3.3

1.8
1.8
true

-XDignore.symbol.file


...
```

Alternatively it is recommended to use **org.apache.jcp.xml.dsig.internal.dom.XMLDSigRI** of Apache Santuario™ (https://santuario.apache.org/).

```xml
...

commons-logging
commons-logging
1.1.1


org.apache.santuario
xmlsec
1.5.7

...
```

## Enabling SSL/TLS Mutual Authentication in JBoss / Wildfly

Edit standalone.xml:

- Copy application.keystore (optional if self signed) and client.keystore in $JBOSS_HOME/standalone/configuration folder;
- Modify keystore configuration;
- Add truststore configuration in authentication;
- Add verify-client="REQUIRED" attribute in https-listener tag.

```xml
...

...








...

...


...

...

...

...

...

...
```

Get client certificate from HttpServletRequest

```java
...
@Resource
protected WebServiceContext webServiceContext;
...

// Method implementation
MessageContext messageContext = webServiceContext.getMessageContext();

HttpServletRequest servletRequest = (HttpServletRequest) messageContext.get(MessageContext.SERVLET_REQUEST);

X509Certificate[] certificates = (X509Certificate[]) httpServletRequest.getAttribute("javax.servlet.request.X509Certificate");
```

## Enabling SSL/TLS debugging

`mvn test -DargLine="-Ddew.test.op=hello_s -Djavax.net.debug=all"`

`mvn test -DargLine="-Ddew.test.op=hello_s -Djavax.net.debug=ssl,handshake"`

`mvn test -DargLine="-Ddew.test.op=hello_s -Djavax.net.debug=ssl:handshake:verbose:keymanager:trustmanager -Djava.security.debug=access:stack"`

`mvn test -DargLine="-Ddew.test.op=hello_s -Djavax.net.debug=ssl:record:plaintext"`

## Apache CXF Logging configuration in JBoss / Wildfly

To enable logging in standalone.xml:

```xml
...





...
```

To disable printing Fault stacktrace in standalone.xml:

```xml
...

...



...

...
```

To disable printing INFO service client creation in standalone.xml:

```xml
...

...



...

...
```

## Contributors

* [Giorgio Silvestris](https://github.com/giosil)