In this demonstration we will see how to create a simple keystore and based on this how to configure the HTTPs connector in JBoss AS7. Also in many production environments it is desired to redirect clients incoming HTTP requests to HTTPs automatically.

So here we will see how can be use the redirect port configuration in the http connector and what kind of information we need to provide inside the “web.xml” file of our web application where we want automatic HTTPs redirection feature to make all the client conversation with the server CONFIDENTIAL.

SSL Configuration on JBoss AS7

Step1). Create a simple SSL certificate keystore. We can use the “keytool” utility which comes by default with the JDK and present inside the “$JAVA_HOME/bin” directory. So before running the below command make sure that you have set the PATH to point to your JDK bin directory.

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;%PATH%

Step2). Run the following command to create a sample key store file with name “chap8.keystore”

 keytool -genkey -keystore chap8.keystore -storepass rmi+ssl -keypass rmi+ssl 
            -keyalg RSA -alias chapter8  -validity 3650 
            -dname "cn=chapter8 example,ou=admin book,dc=jboss,dc=org"

Step3). Now paste the generated “chap8.keystore” inside the “/home/userone/jboss-as-7.1.0.Beta1/standalone/configuration” directory and then edit the “standalone-full.xml” file present in the same directory. We will need to edit the “urn:jboss:domain:web:1.1” subsystem as following:

        <subsystem xmlns="urn:jboss:domain:web:1.1" default-virtual-server="default-host">
            <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http" redirect-port="8443"/>

            <connector name="https" protocol="HTTP/1.1" scheme="https" socket-binding="https" enable-lookups="false" secure="true">
                <ssl name="ssl" 
            <virtual-server name="default-host" enable-welcome-root="true">
                <alias name="localhost"/>
                <alias name="example.com"/>

NOTE: We added the redirect-port=”8443″ inside the http connector as well as we added the “https” connector settings with the ssl informations.

Step4). Now restart the JBoss AS7 server from inside “/home/userone/jboss-as-7.1.0.Beta1//bin” directory as following:

[userone@localhost bin]$./standalone.sh -c standalone-full.xml

Writing Test WebApplication

Step5). For simple testing we will write a web application. So create a directory somewhere in your file system with name “/home/userone/SelfSigned_SSL_Demo” and then create another directory “src” inside “/home/userone/SelfSigned_SSL_Demo”.

Step6). place the following kind of simple “index.jsp” file inside “/home/userone/SelfSigned_SSL_Demo/src” directory:

    <title>SSL Demo</title>
  <body bgcolor=maroon text=white>
       <b>index.jsp executed successfully over HTTPS.</b>

Step7). Now we will write a “web.xml” file inside the “/home/userone/SelfSigned_SSL_Demo/src” directory, and in this file we will define the user-data-constraint as CONFIDENTIAL sothat clients request matching the url-pattern defined will be automatically be redirected to the redirect-port defined inside the “standalone-full.xml” file.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
             <web-resource-name>HTTPs Test</web-resource-name>

Step8). To simply build and deploy the above web application we will write the following kind of “build.xml” file inside “/home/userone/SelfSigned_SSL_Demo” directory.

<project name="JBoss_Service" default="post-deploy">
<property name="jboss.home" value="/home/userone/jboss-as-7.1.0.Beta1" />
<property name="jboss.module.dir" value="${jboss.home}/modules" />
<property name="java.home.dir" value="/home/userone/MyJdks/jdk1.6.0_05" />
<property name="basedir" value="." />
<property name="war.exploaded.name" value="SelfSigned_HttpsTest" />
<property name="src.dir" value="src" />
<property name="output.dir" value="build" />
   <path id="jboss.classpath">
     <fileset dir="${jboss.module.dir}">
        <include name="**/*.jar"/>

   <target name="init">
      <delete dir="${output.dir}" />
      <mkdir dir="${output.dir}" />
      <mkdir dir="${output.dir}/${war.exploaded.name}"/>
      <mkdir dir="${output.dir}/${war.exploaded.name}/WEB-INF"/>
   <target name="build" depends="init">
        <copy todir="${output.dir}/${war.exploaded.name}/WEB-INF">
	  <fileset dir="${basedir}/src">
	      <include name="web.xml"/>
        <copy todir="${output.dir}/${war.exploaded.name}">
	  <fileset dir="${basedir}/src">
	      <include name="index.jsp"/>
        <jar jarfile="${output.dir}/${war.exploaded.name}.war" basedir="${output.dir}/${war.exploaded.name}" compress="true" /> 

        <target name="deploy" depends="build">
            <echo message="*******************  Deploying   *********************" />  
            <echo message="********** ${war.exploaded.name}.war to ${jboss.home}/standalone/deployments **********" />  
            <copy todir="${jboss.home}/standalone/deployments/">
                <fileset dir="${output.dir}/">
                  <include name="${war.exploaded.name}.war"/> 
            <echo message="*******************  Deployed Successfully   *********************" />  
        <target name="post-deploy" depends="deploy">
            <echo message="*******************  NOTE  *********************" />
            <echo message="***** You should be able to access your WSDL using Browser now *****" />
            <echo message="                http://localhost:8080/${war.exploaded.name}/index.jsp" />
            <echo message="You will notice that your URL is automactically changing to https"/>
            <echo message="https://localhost:8443/${war.exploaded.name}/index.jsp" />

Step9). Now before running your ANT script to build and deploy the above webapplication you should have the ANT as well as JAVA set in the $PATH variable of the Shell / command prompt as following:

For Unix Based OS:
export PATH=/home/userone/jdk1.6.0_21/bin:/home/userone/org.apache.ant_1.6.5/bin:$PATH

For Windows Based OS:
set PATH=C:/jdk1.6.0_21/bin;C:/org.apache.ant_1.6.5/bin;%PATH%

Step10). run the ant script “ant” to build and deploy the application on JBoss AS7.

[userone@localhost SelfSigned_SSL_Demo]$ ant
Buildfile: build.xml

   [delete] Deleting directory /home/userone/SelfSigned_SSL_Demo/build
    [mkdir] Created dir: /home/userone/SelfSigned_SSL_Demo/build
    [mkdir] Created dir: /home/userone/SelfSigned_SSL_Demo/build/SelfSigned_HttpsTest
    [mkdir] Created dir: /home/userone/SelfSigned_SSL_Demo/build/SelfSigned_HttpsTest/WEB-INF

     [copy] Copying 1 file to /home/userone/SelfSigned_SSL_Demo/build/SelfSigned_HttpsTest/WEB-INF
     [copy] Copying 1 file to /home/userone/SelfSigned_SSL_Demo/build/SelfSigned_HttpsTest
      [jar] Building jar: /home/userone/SelfSigned_SSL_Demo/build/SelfSigned_HttpsTest.war

     [echo] *******************  Deploying   *********************
     [echo] ********** SelfSigned_HttpsTest.war to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments **********
     [copy] Copying 1 file to /home/userone/jboss-as-7.1.0.Beta1/standalone/deployments
     [echo] *******************  Deployed Successfully   *********************

     [echo] *******************  NOTE  *********************
     [echo] ***** You should be able to access your WSDL using Browser now *****
     [echo]                 http://localhost:8080/SelfSigned_HttpsTest/index.jsp
     [echo] You will notice that your URL is automactically changing to https
     [echo] https://localhost:8443/SelfSigned_HttpsTest/index.jsp

Total time: 0 seconds

NOTE: Access the application with URL “http://localhost:8080/SelfSigned_HttpsTest/index.jsp” and you will notice that your URL is automatically chaged to ” https://localhost:8443/SelfSigned_HttpsTest/index.jsp”

MiddlewareMagic Team

If you enjoyed this post, please consider leaving a comment or subscribing to the RSS feed to have future articles delivered to your feed reader.