Tag: Database

Using Encrypted DataSource Password in JBoss AS7

Hi,

Securing our Application Server resources is one of the most important administrative task. JBoss AS7 uses picketbox security implementations. In this example we will see how we can provide an Encrypted Password for our DataSources rather than using the ClearText Password. The picketbox provides us a class for encrypting the Cleartext passwords using class “org.picketbox.datasource.security.SecureIdentityLoginModule”

BUT in earlier versions on JBoss the Class was available as part of a different package “org.jboss.resource.security.SecureIdentityLoginModule” … So while using JBoss AS7 we must always make sure that we are using the right SecureIdentityLoginModule class as “org.picketbox.datasource.security.SecureIdentityLoginModule”

In this demonstration we will be using JBoss AS7 ( jboss-as-7.1.0.Beta1 ) which can be downloaded from the following link:
http://www.jboss.org/jbossas/downloads

Step1). Create a DataSource as following:

        <subsystem xmlns="urn:jboss:domain:datasources:1.0">
            <datasources>
                <datasource jndi-name="java:jboss/datasources/ExampleDS" pool-name="H2DS" enabled="true">
                    <connection-url>
                        jdbc:h2:mem:test;DB_CLOSE_DELAY=-1
                    </connection-url>
                    <driver>
                        h2
                    </driver>
                    <security>
                        <user-name>sa</user-name>
                        <password>sa</password>
                    </security>
                </datasource>
                
                <!-- ************************************************* -->
                <!-- We Added the below DataSource configuration Here -->
                <datasource jndi-name="java:/MySqlDS" pool-name="MySqlDS_Pool" enabled="true" jta="false" use-ccm="false">
                    <connection-url>
                        jdbc:mysql://localhost:3306/testDB
                    </connection-url>
                    <driver-class>
                        com.mysql.jdbc.Driver
                    </driver-class>
                    <driver>
                        mysql-connector-java-5.1.13-bin.jar
                    </driver>
                    <security>
                        <security-domain>
                            encrypted-ds
                        </security-domain>
                    </security>
                </datasource>
                <!-- ************************************************* -->

                <drivers>
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>
                            org.h2.jdbcx.JdbcDataSource
                        </xa-datasource-class>
                    </driver>
                </drivers>
            </datasources>
        </subsystem>

NOTE:
In above case as we are using “mysql-connector-java-5.1.13-bin.jar” JDBC Driver which is a JDBC 4 compliant Driver so we just placed this Jar file inside the “jboss-as-7.1.0.Beta1/standalone/deployments” directory before creating the DataSource.

NOTE:
In the above DataSource configuration you will notice that inside the security tags we have NOT provided the Username and password rather we are providing the security-domain name (encrypted-ds) which we are going to configure in our next steps.

NOTE:
For more information on installing JDBC Driver and creating DataSources you can refer to the following article: http://middlewaremagic.com/jboss/?p=872

NOTE:
The simplest thing what you can do is just create a DataSource through JBoss Console as mentioned in the above link and then edit the following section of your DataSource to use security-domain rather than user-name and password attributes.

    <security>
         <user-name>dbUserOne</user-name>
         <password>PasswordXYZ</password>
    </security>

Step2). Open a Shell Prompt and then set the CLASSPATH to point to the following JAR’s “picketbox-4.0.6.Beta1.jar” and “jboss-logging-3.1.0.CR2.jar” because these Jars are required to encrypt the clear text password.

[userone@localhost ~]$      export JBOSS_HOME=/home/userone/jboss-as-7.1.0.Beta1
.
[userone@localhost ~]$      export CLASSPATH=${JBOSS_HOME}/modules/org/picketbox/main/picketbox-4.0.6.Beta1.jar:${JBOSS_HOME}/modules/org/jboss/logging/main/jboss-logging-3.1.0.CR2.jar:$CLASSPATH

[userone@localhost ~]$      java  org.picketbox.datasource.security.SecureIdentityLoginModule PasswordXYZ
Encoded password: -5bbc51443039e029747687c1d9ec6a8d
.

NOTE: In above demo suppose our Database Poassword is “PasswordXYZ” so after running the above command we got the encrypted password as “-5bbc51443039e029747687c1d9ec6a8d”

Step3). Now We need to create a “security-domain” inside out “${JBOSS_HOME}/standalone/configuration/standalone-full.xml” file as following, By providing the above Encrypted Password:

                <security-domain name="encrypted-ds" cache-type="default">
                    <authentication>
                        <login-module code="org.picketbox.datasource.security.SecureIdentityLoginModule" flag="required">
                            <module-option name="username" value="dbUserOne"/>
                            <module-option name="password" value="-5bbc51443039e029747687c1d9ec6a8d"/>
                            <module-option name="managedConnectionFactoryName" value="jboss.jca:service=LocalTxCM,name=MySqlDS_Pool"/>
                        </login-module>
                    </authentication>
                </security-domain>

Step4). That’s all now just restart your JBoss profile like following:

.
./standalone.sh -c standalone-full.xml 
.

Testing JBossAS7 DataSource connections using CLI

Step5). Following are the JBoss CLI command which you can use to test your DataSource is working fine or not.
In Standalone mode:

[standalone@localhost:9999 /] /subsystem=datasources/data-source=MySqlDS_Pool:test-connection-in-pool
{
    "outcome" => "success",
    "result" => [true]
}

In Domain mode:

[domain@localhost:9999 /] /host=master/server=server-one/subsystem=datasources/data-source=MySqlDS_Pool:test-connection-in-pool
{
    "outcome" => "success",
    "result" => [true]
}

What if you enter a Wrong Encrypted password in your JBoss Configuration?

Then you will see following kind of exception in your .JBoss Console:

03:19:12,578 INFO  [org.jboss.as.osgi] (MSC service thread 1-4) JBAS011907: Register module: Module "deployment.mysql-connector-java-5.1.13-bin.jar:main" from Service Module Loader
03:19:12,641 ERROR [org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer] (MSC service thread 1-2) Exception during createSubject()PB00024: Access Denied:Unauthenticated caller:null: java.lang.SecurityException: PB00024: Access Denied:Unauthenticated caller:null
	at org.jboss.security.plugins.JBossSecuritySubjectFactory.createSubject(JBossSecuritySubjectFactory.java:89) [picketbox-4.0.9.Final.jar:4.0.9.Final]
	at org.jboss.jca.deployers.common.AbstractDsDeployer$1.run(AbstractDsDeployer.java:1047) [ironjacamar-deployers-common-1.0.11.Final.jar:1.0.11.Final]
	at org.jboss.jca.deployers.common.AbstractDsDeployer$1.run(AbstractDsDeployer.java:1042) [ironjacamar-deployers-common-1.0.11.Final.jar:1.0.11.Final]
	at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_05]
	at org.jboss.jca.deployers.common.AbstractDsDeployer.createSubject(AbstractDsDeployer.java:1041) [ironjacamar-deployers-common-1.0.11.Final.jar:1.0.11.Final]
	at org.jboss.jca.deployers.common.AbstractDsDeployer.deployDataSource(AbstractDsDeployer.java:581) [ironjacamar-deployers-common-1.0.11.Final.jar:1.0.11.Final]
	at org.jboss.jca.deployers.common.AbstractDsDeployer.createObjectsAndInjectValue(AbstractDsDeployer.java:282) [ironjacamar-deployers-common-1.0.11.Final.jar:1.0.11.Final]
	at org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService$AS7DataSourceDeployer.deploy(AbstractDataSourceService.java:283) [jboss-as-connector-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.connector.subsystems.datasources.AbstractDataSourceService.start(AbstractDataSourceService.java:116) [jboss-as-connector-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746) [jboss-msc-1.0.2.GA.jar:1.0.2.GA]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_05]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_05]
	at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_05]

AND

ERROR [org.jboss.jca.core.connectionmanager.pool.strategy.PoolBySubject] (management-handler-thread - 3) IJ000614: Exception during createSubject() PB00024: Access Denied:Unauthenticated caller:null: java.lang.SecurityException: PB00024: Access Denied:Unauthenticated caller:null
	at org.jboss.security.plugins.JBossSecuritySubjectFactory.createSubject(JBossSecuritySubjectFactory.java:89) [picketbox-4.0.9.Final.jar:4.0.9.Final]
	at org.jboss.jca.core.connectionmanager.pool.strategy.PoolBySubject$1.run(PoolBySubject.java:121) [ironjacamar-core-impl-1.0.11.Final.jar:1.0.11.Final]
	at org.jboss.jca.core.connectionmanager.pool.strategy.PoolBySubject$1.run(PoolBySubject.java:116) [ironjacamar-core-impl-1.0.11.Final.jar:1.0.11.Final]
	at java.security.AccessController.doPrivileged(Native Method) [rt.jar:1.7.0_05]
	at org.jboss.jca.core.connectionmanager.pool.strategy.PoolBySubject.createSubject(PoolBySubject.java:115) [ironjacamar-core-impl-1.0.11.Final.jar:1.0.11.Final]
	at org.jboss.jca.core.connectionmanager.pool.strategy.PoolBySubject.testConnection(PoolBySubject.java:85) [ironjacamar-core-impl-1.0.11.Final.jar:1.0.11.Final]
	at org.jboss.as.connector.subsystems.common.pool.PoolOperations$TestConnectionInPool.invokeCommandOn(PoolOperations.java:121) [jboss-as-connector-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.connector.subsystems.common.pool.PoolOperations$1.execute(PoolOperations.java:60) [jboss-as-connector-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:397) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:284) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:211) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.connector.subsystems.common.pool.PoolOperations.execute(PoolOperations.java:74) [jboss-as-connector-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:397) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:284) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:211) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.ModelControllerImpl$DefaultPrepareStepHandler.execute(ModelControllerImpl.java:473) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.executeStep(AbstractOperationContext.java:397) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.doCompleteStep(AbstractOperationContext.java:284) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.AbstractOperationContext.completeStep(AbstractOperationContext.java:211) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.ModelControllerImpl.internalExecute(ModelControllerImpl.java:126) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.ModelControllerImpl.execute(ModelControllerImpl.java:111) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.remote.ModelControllerClientOperationHandler$ExecuteRequestHandler.doExecute(ModelControllerClientOperationHandler.java:139) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.controller.remote.ModelControllerClientOperationHandler$ExecuteRequestHandler$1.execute(ModelControllerClientOperationHandler.java:108) [jboss-as-controller-7.1.2.Final.jar:7.1.2.Final]
	at org.jboss.as.protocol.mgmt.AbstractMessageHandler$2$1.doExecute(AbstractMessageHandler.java:295)
	at org.jboss.as.protocol.mgmt.AbstractMessageHandler$AsyncTaskRunner.run(AbstractMessageHandler.java:512)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1110) [rt.jar:1.7.0_05]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:603) [rt.jar:1.7.0_05]
	at java.lang.Thread.run(Thread.java:722) [rt.jar:1.7.0_05]
	at org.jboss.threads.JBossThread.run(JBossThread.java:122) [jboss-threads-2.0.0.GA.jar:2.0.0.GA]

And your CLI comman to test DataSource connections will fail like following:

[standalone@localhost:9999 /] /subsystem=datasources/data-source=MySqlDS_Pool:test-connection-in-pool
{
    "outcome" => "failed",
    "failure-description" => "JBAS010440: failed to invoke operation: JBAS010447: Connection is not valid",
    "rolled-back" => true
}

.
.
Thanks
MiddlewareMagic Team


How to create MySQL datasource and install MySQL JDBC driver in JBoss AS7

Unlike JBoss AS 6 there is no “$PROFILE/lib” present in JBoss AS 7 where we can place our JDBC Drivers in order to add/register the JDBC Driver. Also in JBoss AS 7 we don’t need to create a separate DataSource file as “*-ds.xml” file.

In JBoss AS 7 the DataSource configuration is placed wither inside the “Jboss-as-7.0.1.Final/standalone/configuration/standalone.xml” (if you are running a JBoss standalone profile), or the datasource information is placed inside the “boss-as-7.0.1.Final/domain/configuration/domain.xml” file.Here in this demonstration we will see how to install/register a JDBC Driver in JBoss AS7 and then how to create a DataSource from Admin-Console.

You can have a look at the below article for creating Oracle Datasource
How to create Oracle DataSource And Install Oracle JDBC Driver in JBoss AS7

You will find a Demo Web Application and the steps to create MySQL DataSource in the following repo:

https://github.com/jaysensharma/MiddlewareMagicDemos/tree/master/DataSourceDemo

WAR Download link: https://github.com/jaysensharma/MiddlewareMagicDemos/raw/master/DataSourceDemo/build/DataSourceDemo.war

In the attached WAR you will see the following:

1). DataSource Injection using @Resource
2). DataSource Referencing using in web.xml
3). DataSource Manual Old style lookup

There are two options to install/Register a JDBC Driver to JBoss AS 7.

  1. Installing a JDBC driver as a deployment
  2. Installing a JDBC driver as a module

Installing a JDBC driver as a deployment

First we need to check which Jdbc Driver are we using? Is it a JDBC 4-compliant driver or a Non-JDBC 4 -compliant driver? Any JDBC 4-compliant driver will automatically be recognized and installed into the system by name and version. A JDBC 4-compliant JAR is identified using the Java service provider mechanism. It contains a text a file named “META-INF/services/java.sql.Driver”, which contains the name of the class(es) of the Drivers which exist in that JAR.

If the driver is already JDBC4-comliant then you can directly deploy it inside the “jboss-as-7.0.1.Final/standalone/deployments” based on the mode which you are using to run your JBoss AS.

Dealing with Non JDBC 4 -compliant Drivers:

If your JDBC Driver is NOT JDBC 4-compliant then we can update the driver using “jar” utility by adding the “META-INF/services/java.sql.Driver” inside it. as following:

  1. Create a directory somewhere in your file system like “/home/userone/testDriver”
  2. Place your Non-JDBC 4 compliant driver in this directory “/home/userone/testDriver” suppose your Driver Jar name is “YourJdbcDriver.jar”
  3. Now create “META-INF/services” directory inside “/home/userone/testDriver”
  4. Create a file with name “java.sql.Driver” inside “/home/userone/testDriver/META-INF/services” directory and then add the fully qualified name of your JDBC Driver class in this file.
  5. Use the jar utility with -u (means update) option to add the META-INF directory with the above contents in it as following
jar  -uf  YourJdbcDriver.jar  META-INF/services/java.sql.Driver

Now you can take your JDBC Driver and then place it inside the “${JBOSS_AS7}/standalone/deployments”.
The advantage of deploying the JDBC Driver as a deployment in “domain” mode is that the deployments are automatically propagated to all servers to which the deployment applies, so the administrator need not to worry about the the JDBC Driver distribution every time.

Installing MySQL JDBC driver as a module

This is another option to install the JDBC Driver as a module. Which requires that we define a new module for our JDBC Driver inside “${JBOSS_AS7}/modules” directory as following:
To install the MySQL JDBC Driver (mysql-connector-java-x.x.xx-bin.jar) then we will need to do the following steps:

  1. Create a directory “MySQL/jdbc/main” inside the “jboss-as-7.0.1.Final/modules” directory.
  2. Paste your “mysql-connector-java-x.x.xx-bin.jar” MySQL Jdbc Driver inside “jboss-as-7.0.1.Final/modules/MySQL/jdbc/main” directory.
  3. Create a file “module.xml” inside “jboss-as-7.0.1.Final/modules/oracle/jdbc/main” as following:
  4. <?xml version="1.0" encoding="UTF-8"?>
    <module xmlns="urn:jboss:module:1.0" name="MySql.jdbc">
        <resources>
            <resource-root path="mysql-connector-java-x.x.xx-bin.jar"/>
        </resources>
        <dependencies>
            <module name="javax.api"/>
            <module name="javax.transaction.api"/>
        </dependencies>
    </module>
    
  5. Now open your “jboss-as-7.0.1.Final/standalone/configuration/standalone.xml” file or “jboss-as-7.0.1.Final/domain/configuration/domain.xml” file and then add the driver declaration tag referring to your module as following, by default you will see the driver declaration tag already contains the declaration for <driver name=”h2″ module=”com.h2database.h2″>:
  6.                 <drivers>
                        <driver name="MySqlJDBCDriver" module="MySql.jdbc" />   <!-- This line has been added -->
                        <driver name="h2" module="com.h2database.h2">
                            <xa-datasource-class>
                                org.h2.jdbcx.JdbcDataSource
                            </xa-datasource-class>
                        </driver>
                    </drivers>
    

    Here we declared the <driver name=”MySqlJDBCDriver” module=”MySql.jdbc”/>

  7. Create a DataSource in your JBoss AS 7 and then in the Driver section you can refer to this Module name “MySQL.jdbc”

Creating a DataSource from JBoss AS 7 Admin Console

  1. After installing the JDBC Driver as mentioned above start your JBoss AS 7 and then login to the admin-console from URL: “http://localhost:9990/console” (as admin/admin credentials)
  2. From left hand panel of the console click on “Connectors—>DataSources”
  3. Creating MySql DataSource in AS7

  4. In the right side panel you will see a button “Add” click on this button.
  5. In Wizard “Step 1/3: Datasource Attributes”
    Enter the DataSource Name as “MySqlDS”
    Enter JNDI Name as “java:/MySqlDSJNDI” or “java:jboss/MySqlDSJNDI” (NOTE the valid DataSource name should start with either java:/ or with java:jboss/ prefix)
  6. DataSource name & JNDI Name

  7. Now in the next Section “Step 2/3: JDBC Driver” you will see all the installed drivers details. in above case as we already registered oracle driver as a module “MySqlJDBCDriver” in previous section so we will be able to see the details as following:
  8. Registered Jdbc Drivers List

  9. In next section provide the Database url (jdbc:mysql://localhost:3306/jboss_test) ,username and password
  10. Specifying DataSource properties

  11. Now you just have to enable the newly created datasource and if everything is configured properly you would see it green as shown in below snap-shot:
  12. DataSource Details

    10:50:32,330 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-7) JBAS010400: Bound data source [java:/MySqlDS]
    

    For More Details visit:
    https://docs.jboss.org/author/display/AS7/Developer+Guide
    http://community.jboss.org/wiki/DataSourceConfigurationinAS7#Installing_a_JDBC_driver_as_a_deployment

    NOTE: JBoss AS7 is a Community release and we always recommend you to use the RedHat Supported JBoss Enterprise Application Platform, There are various reasons behind this. Please refer to the Video: http://www.youtube.com/watch?v=iNFV0r9v14g&feature=player_detailpage

    Thanks
    MiddlewareMagic Team


How to create Oracle DataSource And Install Oracle JDBC Driver in JBoss AS7

Hi,
Unlike JBoss AS 6 there is no “$PROFILE/lib” present in JBoss AS 7 where we can place our JDBC Drivers in order to add/register the JDBC Driver. Also in JBoss AS 7 we don’t need to create a separate DataSource file as “*-ds.xml” file.

In JBoss AS 7 the DataSource configuration is placed wither inside the “Jboss-as-7.0.1.Final/standalone/configuration/standalone.xml” (if you are running a JBoss standalone profile), or the datasource information is placed inside the “boss-as-7.0.1.Final/domain/configuration/domain.xml” file.Here in this demonstration we will see how to install/register a JDBC Driver in JBoss AS7 and then how to create a DataSource from Admin-Console.

You can have a look at the below article for creating MySql Datasource
How to create MySql DataSource And Install MySql JDBC Driver in JBoss AS7

There are two options to install/Register a JDBC Driver to JBoss AS 7.
1). Installing a JDBC driver as a deployment
2). Installing a JDBC driver as a module

Installing a JDBC driver as a deployment

First we need to check which Jdbc Driver are we using? Is it a JDBC 4-compliant driver or a Non-JDBC 4 -compliant driver? Any JDBC 4-compliant driver will automatically be recognized and installed into the system by name and version. A JDBC 4-compliant JAR is identified using the Java service provider mechanism. It contains a text a file named “META-INF/services/java.sql.Driver”, which contains the name of the class(es) of the Drivers which exist in that JAR.

If the driver is already JDBC4-comliant then you can directly deploy it inside the “jboss-as-7.0.1.Final/standalone/deployments” based on the mode which you are using to run your JBoss AS.

Dealing with Non JDBC 4 -compliant Drivers:

If your JDBC Driver is NOT JDBC 4-compliant then we can update the driver using “jar” utility by adding the “META-INF/services/java.sql.Driver” inside it. as following:
Step1). Create a directory somewhere in your file system like “/home/userone/testDriver”
Step2). Place your Non-JDBC 4 compliant driver in this directory “/home/userone/testDriver” suppose your Driver Jar name is “YourJdbcDriver.jar”
Step3). Now create “META-INF/services” directory inside “/home/userone/testDriver”
Step4). Create a file with name “java.sql.Driver” inside “/home/userone/testDriver/META-INF/services” directory and then add the fully qualified name of your JDBC Driver class in this file.
Step5). use the jar utility with -u (means update) option to add the META-INF directory with the above contents in it as following

jar  -uf  YourJdbcDriver.jar  META-INF/services/java.sql.Driver

Now you can take your JDBC Driver and then place it inside the “${JBOSS_AS7}/standalone/deployments”.
The advantage of deploying the JDBC Driver as a deployment in “domain” mode is that the deployments are automatically propagated to all servers to which the deployment applies, so the administrator need not to worry about the the JDBC Driver distribution every time.

Installing a JDBC driver as a module

This is another option to install the JDBC Driver as a module. Which requires that we define a new module for our JDBC Driver inside “${JBOSS_AS7}/modules” directory as following:
Suppose if we want to install the Oracle JDBC Driver (ojdbc6.jar) then we will need to do the following steps:
Step1). Create a directory “oracle/jdbc/main” inside the “jboss-as-7.0.1.Final/modules” directory.
Step2). paste your “ojdbc6.jar” oracle Jdbc Driver inside “jboss-as-7.0.1.Final/modules/oracle/jdbc/main” directory.
Step3). Create a file “module.xml” inside “jboss-as-7.0.1.Final/modules/oracle/jdbc/main” as following:

<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.0" name="oracle.jdbc">
    <resources>
        <resource-root path="ojdbc6.jar"/>
    </resources>
    <dependencies>
        <module name="javax.api"/>
        <module name="javax.transaction.api"/>
    </dependencies>
</module>

Step4). Now open your “jboss-as-7.0.1.Final/standalone/configuration/standalone.xml” file or “jboss-as-7.0.1.Final/domain/configuration/domain.xml” file and then add the driver declaration tag refering to your module as following, by default you will see the driver declaration tag already contains the declaration for <driver name=”h2″ module=”com.h2database.h2″>:

                <drivers>
                    <driver name="OracleJDBCDriver" module="oracle.jdbc" />
                    <driver name="h2" module="com.h2database.h2">
                        <xa-datasource-class>
                            org.h2.jdbcx.JdbcDataSource
                        </xa-datasource-class>
                    </driver>
                </drivers>

Here we declared the <driver name=”OracleJDBCDriver” module=”oracle.jdbc”/>

Step5). Create a DataSource in your JBoss AS 7 and then in the Driver section you can refer to this Module name “oracle.jdbc”

Creating a DataSource from JBoss AS 7 Admin Console

Step1). After installing the JDBC Driver as mentioned above start your JBoss AS 7 and then login to the admin-console from URL: “http://localhost:9990/console” (as admin/admin credentials)
Step2). From left hand panel of the console click on “Connectors—>DataSources”

Creating Oracle DataSource in AS7

Step3). In the right side panel you will see a button “Add” click on this button.
Step4). In Wizard “Step 1/3: Datasource Attributes”
Enter the DataSource Name as “OracleDS”
Enter JNDI Name as “java:/OracleDSJNDI” or “java:jboss/OracleDSJNDI” (NOTE the valid DataSource name should start with either java:/ or with java:jboss/ prefix)

DataSource name & JNDI Name

Step5). Now in the next Section “Step 2/3: JDBC Driver” you will see all the installed drivers details. in above case as we already registered oracle driver as a module “OracleJDBCDriver” in previous section so we will be able to see the details as following:

Registered Jdbc Drivers List

Step6). In next section “” provide the Database url (jdbc:oracle:thin:@10.10.10.10:1521:DB_SID) ,username and password

Specifying DataSource properties

Step7). you will see following kind of messae in your JBoss AS 7 console output:

DataSource Details

10:50:32,330 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-6) Bound data source [OracleDSJNDI]

For More Details visit:
https://docs.jboss.org/author/display/AS7/Developer+Guide
http://community.jboss.org/wiki/DataSourceConfigurationinAS7#Installing_a_JDBC_driver_as_a_deployment
.
.
Thanks
MiddlewareMagic Team


Copyright © 2010-2012 Middleware Magic. All rights reserved. |