
Bharath Thippireddy introduces the Java web services part 2 course, outlining ws-security fundamentals, including authentication, confidentiality, integrity, and non-repudiation, plus username token, encryption, signatures, and replay attack protection.
Maximize your learning in Java web services part 2 with lectures, quizzes (target 70%), and hands-on assignments after setting up JDK, Tomcat, and Eclipse; use free preview and expect updates.
Troubleshoot maven project errors by deleting the local m2 repository and refreshing dependencies with a maven update project to keep your project in sync with the latest dependencies.
Download the completed sum ws and sum ws client projects from resources, unzip, and import them as Maven projects in Eclipse; configure the server and run the ws client tests.
Build a simple Java web service provider and client that sums two numbers in a step-by-step approach, with emphasis on security and ws standards.
Create the sum ws maven web application in eclipse using a web app archetype, set groupId com.bharath.trainings.ws and artifactId sum ws, and configure src/main/resources, src/main/java, and index.jsp under src/main/webapp.
<properties>
<cxf.version>3.1.9</cxf.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.1</version>
<configuration>
<webXml>src/main/webapp/WEB-INF/web.xml</webXml>
</configuration>
</plugin>
</plugins>
<finalName>sumws</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
</dependencies>
Create the web services endpoint by building two DTOs for a sum operation. Implement a sumWS interface and its sumWSImpl to return the sum of the two request numbers.
Mark the request and response DTOs with JAXB annotations to enable XML serialization and deserialization for the soap engine, using @XmlType for the root element and @XmlElement for fields.
Configure the CXF endpoint by creating the cxf-servlet.xml, defining a jax-ws server with a unique id and service class, and setting the address to /someWS.
Configure the CXF servlet in web.xml to handle web services requests in a Tomcat deployment, and map it to /services/start with load on startup.
Deploy and run the web application on Tomcat via Maven clean and install, deploy the WAR, and access CXF services and the generated WSDL through the services URL.
<properties>
<cxf.version>3.1.9</cxf.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-codegen-plugin</artifactId>
<version>${cxf.version}</version>
<executions>
<execution>
<id>generate-sources</id>
<phase>generate-sources</phase>
<configuration>
<sourceRoot>${basedir}/src/generated</sourceRoot>
<wsdlOptions>
<wsdlOption>
<wsdl>${basedir}/src/main/resources/sumService.wsdl</wsdl>
</wsdlOption>
</wsdlOptions>
</configuration>
<goals>
<goal>wsdl2java</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<finalName>sumwsclient</finalName>
</build>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>3.2.0.RELEASE</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.4</version>
</dependency>
</dependencies>
Understand why ws standards matter for soap-based web services, defining where authentication data belongs in the soap envelope, header, or body.
Explore WS-Security authentication, confidentiality, integrity, and non-repudiation with a shopping use case, detailing username token, X.509, SAML, encryption, signatures, and timestamp protection.
Configure ws-security with WSS4J inside Apache CXF using interceptors on client and server sides to enable authentication, encryption, signature, and timestamp via passwordCallbackRef and property files.
Understand the username token profile, the primary method to authenticate soap based web services by passing a username and password in the soap header, wrapped by ws-security.
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-ws-security</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
Configure the WSS4J in interceptor in the cxf-servlet.xml to enable username token profile security for the soap endpoint, using a map with action, password type, and password callback.
Create and configure the password callback handler for WSS4J, implementing callback handler, mapping user IDs to passwords in a map, and supplying the password at runtime during username token processing.
Deploy the server-side username token profile authentication, run the app on the server, and validate end-to-end testing by launching the client and loading the page in the browser.
Retrieve the CXF client proxy from the port using CXF's getClient method, then obtain the endpoint to attach in and out interceptors for username token profile support.
Programmatically create the WSS4J out interceptor for username token profile, populate its properties hashmap, and attach it to the endpoint's out interceptors to run before sending the SOAP message.
Configure the username token profile by setting three properties in props, using WS handler constants for action, password type, and the password callback class, then save and format the changes.
Run the end-to-end test to verify authentication, where the client sends a username token in the soap header and the server validates it via the password callback handler.
Demonstrates confidentiality in web services through encryption and decryption, explaining symmetric and public-key cryptography, keys, and concepts like RSA, AES, Blowfish, and private/public keys for secure message exchange.
Explore the Java keytool to generate private and public keys, create and protect a keystore, manage aliases and passwords, and export certificates for client encryption and signature verification.
Generate a key pair with the java keytool by executing genkeypair with alias, key store, and passwords; set validity and name details in the keystore.
Export the public key from the key store using keytool with RFC format to create mycert.cer for client distribution. Then import the certificate into the other key store for encryption.
encrypt the client-to-server message and decrypt it on the server using three steps with WSS 4G interceptors, a keystore property file, and an updated client password callback.
keytool -genkey -keyalg RSA -sigalg SHA1withRSA -validity 600 -alias myservicekey -keypass skpass -storepass sspass -keystore serviceKeystore.jks -dname "cn=Bharath"
keytool -genkey -keyalg RSA -sigalg SHA1withRSA -validity 600 -alias myclientkey -keypass ckpass -storepass cspass -keystore clientKeystore.jks -dname "cn=Bharath"
keytool -export -rfc -keystore clientKeystore.jks -storepass cspass -alias myclientkey -file MyClient.cer
keytool -export -rfc -keystore serviceKeystore.jks -storepass sspass -alias myservicekey -file MyService.cer
keytool -import -trustcacerts -keystore serviceKeystore.jks -storepass sspass -alias myclientkey -file MyClient.cer -noprompt
keytool -import -trustcacerts -keystore clientKeystore.jks -storepass cspass -alias myservicekey -file MyService.cer -noprompt
Learn how the trustcacerts flag in keytool allows importing self-signed certificates by using the JDK's trusted CA certificates to establish a trusted certificate chain.
Copy the keystore files into their projects to enable encryption and decryption in the next lecture, organizing a keystore folder under resources for the server and client keystores.
Configure the encryption action and its properties in WSS4J to encrypt the username token alongside the message using the server's public key, keystore, and a properties file.
Create and configure the client keystore properties file for soap and rest security with four properties: keystore path, password, type, and alias to enable client key retrieval and decryption.
Update the password callback handler to return the password for my client key alias and add it to the passwords map, enabling private key retrieval from the keystore for encryption.
Configure server-side decryption by updating CXF-servlet.xml to add the encrypt action and specify the decryption prop file path for decrypt/service keystore properties. Create service keystore.properties to support the decryption step.
Demonstrate end-to-end soap message encryption and decryption by building and running a server-side and client tests with maven, validating encrypted requests and decrypted responses.
Configure server-side encryption by adding a WSS4J out interceptor in the CXF servlet.xml, enabling the encrypt action and using the client key from the encryption property file for encryption.
Enable client-side decryption by configuring WSS4JInInterceptor with the decryption properties and key store, attach it to the endpoint chain, and verify the test passes.
Configure signature on the client to sign outbound messages with the client private key, verifiable by the server using the client public key and a signature property file.
Verify that the server signs messages by configuring the client to enforce a signature in the interceptor, using the client key store for public keys and the server private key.
Explore WS-Security timestamps to prevent replay attacks by defining created and expires times as a time-to-live window, and configure expiry with WSS4J for SOAP messages.
Run the application and the sum ws test, start the server, and examine inbound and outbound soap messages for ws-security timestamps, verifying creation and expiry times, default expiry 300 seconds.
Set the timestamp's time to live to 30 seconds to limit replay attacks, configuring the time to live property and verifying the 30-second expiry window in tests.
Encryption and signatures apply to the soap body; the body is encrypted and the signature is calculated from the soap body, not the header.
Encrypt the signature and the soap body on the server side using a semicolon delimiter, configure cxf-wss4j interceptors, and verify encrypted results in a test.
Include the wsu timestamp in the soap signature to prevent replay attacks by including the timestamp and body in the signature calculation and verifying on the server.
The ONLY Course That Covers SOAP and REST Web Services Security Comprehensively!
What Students Are Saying
“Straight to the point. I was looking for an alternative to Axis2/Rampart for SOAP WS-Security, and I’m glad I found this course. As a nice bonus (for me at least), this course also covers REST security.”
“I have completed both the Web Services courses by Bharath. They are extremely knowledgeable and provide real-world experience. I was able to use the same examples in my company. Now I am planning to take the Create REST APIs using Spring Data REST course by Bharath. Friends, go for the course—you won’t regret it!”
— Vivek Kumar Gupta
“Awesome! Completed up to Encryption & Decryption. Clear explanation. So far, so good.”
— Brady Adams
What You’ll Get
All source code available for download
Responsive instructor — all questions answered within 24 hours
Professional-quality video and audio recordings (check the free preview lectures)
This course is a continuation of my Java Web Services course, one of the most popular Java Web Services courses on Udemy.
If you’re interested in learning and implementing advanced Web Services concepts such as Security, this course is for you.
This is an evolving course, and new topics such as OAuth, Asynchronous Communication, and other advanced Web Services concepts will continue to be added.
What You’ll Learn
Do you want to master the four key security areas and secure your SOAP Web Services?
This course simplifies the concepts through clear explanations and step-by-step implementations. By the end of this course, you will be able to:
Understand the four key security areas.
Use the WS-Security standard to secure your services.
Implement Authentication.
Understand encryption and why it is essential.
Generate security key pairs using the Java Keytool.
Implement Encryption and Decryption on both the Web Service client and provider.
Learn what SOAP message signing is, why it is needed, and how to implement it.
Prevent replay attacks by enabling Timestamps.
Learn additional advanced SOAP and REST Web Services topics as they are added to the course.