wildfly custom module: unable to use class inside deployed EAR - wildfly

I am creating a custom realm in wildfly that will be use by my application for login purposes. If I use the class inside a jar file of a global module, wildfly can find it. However, if I try pointing it to a class inside my EAR file, then wildfly cannot locate the class.
Below config is working. VersaCustomRealm class is located inside VRCustomRealm.jar
standalone.xml
<custom-realm name="vr-login-realm" module="micropact.login" class-name="com.versa.login.VersaCustomRealm">
<configuration>
<property name="admin" value="welcome"/>
</configuration>
</custom-realm>
module.xml
<?xml version='1.0' encoding='UTF-8'?>
<module xmlns="urn:jboss:module:1.1" name="micropact.login">
<resources>
<resource-root path="VRCustomRealm.jar"/>
</resources>
<dependencies>
<module name="org.wildfly.security.elytron"/>
</dependencies>
</module>
Below config does not work. What am I missing? What would be the correct module name for deployed EAR?
<configuration>
<property name="admin" value="welcome"/>
</configuration>
Older version of wildfly still supports login-module where you can specify the custom code. In the below example, I use VersaCustomRealm which is a class inside my EAR file and not in the global module. How can accomplish this with custom realm?
<security-domain name="vr-domain" cache-type="default">
<authentication>
<login-module code="com.versasys.licenseEase.jbosssx.VersaCustomRealm" flag="required">
</login-module>
</authentication>
</security-domain>

I don't believe you can. The server needs anything listed in standalone from modules, before the deployment scanner starts

Related

Context root automatically changing to temp folder name in JBOSS EAP 6.4

I have an application that I am trying to deploy to JBoss EAP 6.4. I don't see any errors while deploying the application. However, when I try to access the application with the context root like http://localhost:8080/contextroot/ I am being redirected to http://localhost:8080/contextroot.war-345rdser34dwwe/login.jsp where contextroot.war-345rdser34dwwe is a folder created under ${jboss.home}/standalone/tmp/vfs/temp
This is my jboss-deployment-structure.xml
<jboss-deployment-structure> <!-- Make sub deployments isolated by default, so they cannot see each others
classes without a Class-Path entry -->
<ear-subdeployments-isolated>false</ear-subdeployments-isolated> <!-- This corresponds to the top level deployment. For a war this is the
war's module, for an ear --> <!-- This is the top level ear module, which contains all the classes in
the EAR's lib folder -->
<deployment>
<resources>
<resource-root path="WEB-INF/lib/bcprov-jdk16-1.46.jar" use-physical-code-source="true"/>
</resources>
<!-- exclude-subsystem prevents a subsystems deployment unit processors running
on a deployment --> <!-- which gives basically the same effect as removing the subsystem, but
it only affects single deployment -->
<exclusions>
<module name="org.javassist" />
<module name="org.hibernate" />
<module name="org.hibernate.validator" />
<module name="org.jboss.msc" />
<module name="javax.faces.api" />
<module name="com.sun.jsf-impl" />
<module name="org.apache.log4j" />
<module name="org.slf4j" />
<module name="org.slf4j.impl" />
<module name="org.apache.commons.logging" />
<module name="org.jboss.resteasy.resteasy-hibernatevalidator-provider" />
</exclusions>
<!-- This allows you to define additional dependencies, it is the same as
using the Dependencies: manifest attribute -->
<dependencies>
<module name="com.company.app.config" optional="TRUE"/>
<module name="deployment.module.nested.app"/>
</dependencies>
</deployment>
<module name="deployment.module.nested.app">
<resources>
<resource-root path="../contextroot.war"/>
</resources>
</module>
This is my jboss-web.xml
<!DOCTYPE jboss-web PUBLIC
"-//JBoss//DTD Web Application 4.2//EN"
"http://www.jboss.org/j2ee/dtd/jboss-web_4_2.dtd">
<jboss-web>
<security-domain>UserModule</security-domain>
<security-domain>ServiceModule</security-domain>
</jboss-web>
This is my config in standalone-ha.xml for security subsystem
<security-domain name="UserModule" cache-type="default">
<authentication>
<login-module code="com.company.uas.service.authentication.loginmodule.UserLoginModule" flag="required"/>
</authentication>
</security-domain>
<security-domain name="ServiceModule" cache-type="default">
<authentication>
<login-module code="com.company.uas.service.authentication.loginmodule.ServiceLoginModule" flag="required"/>
</authentication>
</security-domain>
I have been working on it for couple of days now but could not find anything online related to this issue.
I am not sure if I consider this an answer but I understood why my /contextroot was changing to /contextroot.war-345rdser34dwwe. This was because, I was deploying a war file to JBoss and JBoss was pointing to the exploded version of my war file which was present in the tmp folder for some reason.
I deployed an exploded version of my war file with the name contextroot.war as the name of the folder and it worked.

Migration to JBoss7.2eap from jboss5.1.2eap : java.lang.NoClassDefFoundError: Lorg/apache/commons/dbcp/BasicDataSource

I have migrated my application from jboss5.1.2-eap to jboss-7.2-eapand java6 to java8 but after migration it is starting giving me exception while starting the server.
Caused by: java.lang.NoClassDefFoundError: Lorg/apache/commons/dbcp/BasicDataSource
we have a datasource.xml file present in the classpath of the server, having the following line of code.
<bean id="beanName" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="oracle.jdbc.OracleDriver"/>
<property name="maxActive" value="10"/>
Also we have commons-dbcp-1.2.2.jar present in the classpath but it is not working for jboss-7.2-eap.
Now I am not sure if commons-dbcp-1.2.2.jar is supported by jboss7-eap. as it is present in the classpath of the application(present in the loaded module), but still spring is not able to create the bean for datasource.
I suppose that datasource in Jboss EAP should be placed in standalone.xml configuration file and looks like here:
<datasource jndi-name="java:jboss/datasources/Altis" pool-name="Altis" enabled="true">
<connection-url>jdbc:oracle:thin:#255.255.255.255:1521:sid</connection-url>
<driver-class>oracle.jdbc.OracleDriver</driver-class>
<driver>oracle</driver>
<security>
<user-name>username</user-name>
<password>passwd</password>
</security>
</datasource>
Given module information in the jboss-deployment-structure.xml inside the WEB-INF directory of the war file.
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="com.oracle.sql" export="true"/>
<module name="org.apache.commons.dbcp" export="true"/>
</dependencies>
</deployment>
</jboss-deployment-structure>
Also the module directories should also follow the same naming convention as per the availability of your .class files inside the jar, like in my case I have created module org.apache.commons.dbcp as while opening commons-dbcp-1.2.2.jar file, .class files are present inside org/apache/commons/dbcp folder.
Note: In case of multiple modules, you need to identify there dependency if a module is dependent on other and that information will be given inside module.xml file. like
<module xmlns="urn:jboss:module:1.1" name="org.apache.commons.dbcp">
<resources>
<resource-root path="commons-dbcp-1.2.2.jar"/>
</resources>
<dependencies>
<module name="org.apache.commons.pool"/>
<module name="com.oracle.jdbc.driver"/>
</dependencies>
</module>

Wildfly Postgres JDBC module issue

I have postgres jdbc driver configured as module in Wildfly 10. What I am trying to do, is to use that driver as dependency in application that will be deployed on the server - so in application, I mark this dependency as provided (in pom.xml file) but it seems to be not working.
Current configuration:
Wildfly postgres module is added at wildfly-10.1.0.Final\modules\org\postgresql\main where there is: postgresql-9.4-1206-jdbc4.jar and module.xml with following content:
<module xmlns="urn:jboss:module:1.1" name="org.postgresql">
<resources>
<resource-root path="postgresql-9.4-1206-jdbc4.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
<module name="javax.transaction.api"/>
</dependencies>
</module>
Module is used to define datasource. To this point, everything is working well - with hibernate help tables are happily mapped to entities. Except one thing:
I started to map postgres-jsonb columns with use of javax.persistence.AttributeConverter and following happens:
Scenario 1
When I use postgresql-9.4-1206-jdbc4.jar as a provided (in pom.xml - deployed application), I get following error trying to convert anything:
Caused by: java.lang.ClassNotFoundException: org.postgresql.util.PGobject from [Module "deployment.priject-1.0.1.ear.project.data-1.0.1-SNAPSHOT.jar:main" from Service Module Loader]
at org.jboss.modules.ModuleClassLoader.findClass(ModuleClassLoader.java:198)
at org.jboss.modules.ConcurrentClassLoader.performLoadClassUnchecked(ConcurrentClassLoader.java:363)
at org.jboss.modules.ConcurrentClassLoader.performLoadClass(ConcurrentClassLoader.java:351)
at org.jboss.modules.ConcurrentClassLoader.loadClass(ConcurrentClassLoader.java:93)
... 269 more
Scenario 2
When I use postgresql-9.4-1206-jdbc4.jar with default scope, there is following error:
Caused by: java.lang.ClassCastException: org.postgresql.util.PGobject cannot be cast to org.postgresql.util.PGobject
at com.project.entity.util.converters.JSONBTypeConverter.convertToEntityAttribute(JSONBTypeConverter.java:33)
at com.project.entity.util.converters.JSONBTypeConverter.convertToEntityAttribute(JSONBTypeConverter.java:1)
at org.hibernate.type.descriptor.converter.AttributeConverterSqlTypeDescriptorAdapter$2.doConversion(AttributeConverterSqlTypeDescriptorAdapter.java:140)
... 266 more
Which means: class loader load the same jar two times, and can not cast this object to itself.
Question: Why provided scope of the dependency does not work for manually added (to wildfly) postgres driver? (I guess that would be the solution for me)
You need to use a jboss-deployment-structure.xml to add the module dependency to your deployment.
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.postgresql" />
</dependencies>
</deployment>
<sub-deployment name="project.data-1.0.1-SNAPSHOT.jar">
<dependencies>
<module name="org.postgresql" />
</dependencies>
</sub-deployment>
</jboss-deployment-structure>
Note the module dependency on the EAR may not be required. It just depends on how your EAR is setup.
Another option would be to add a Dependencies manifest entry. Since you're using Maven you could just use the maven-jar-plugin (since it appears this is a JAR inside an EAR) to create the entry.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.postgresql</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>

Does the application server JBoss include CXF installation?

I'm trying to set the CXF Runtime on Eclipse web services preferences window.
I'm trying to point to JBoss installation in my pc at :
C:\jboss-eap-6.3\modules\system\layers\base\org\apache\cxf
But I'm getting error : Missing CXF jar: Please select the CXF home directory.
Shouldn't JBoss include a working CXF installation ?
Jboss AS 7.x have the dependency for apache CXF, you can use that by loading the module in your web application. There are a lot of way to achieve this on of common is setting apache cfx module as global module which will loaded into memory as the application server will started. Add the following lines in standalone.xml of jboss server-
<subsystem xmlns="urn:jboss:domain:ee:1.0" >
<global-modules>
<module name="org.apache.cxf" slot="main" />
</global-modules>
</subsystem>
If you want to add the module as web application dependent then you can use jboss-deployment-structure.xml-
<jboss-deployment-structure>
<deployment>
<dependencies>
<module name="org.apache.cxf" services="import">
<imports>
<include path="**" />
</imports>
</module>
</dependencies>
</deployment>
</jboss-deployment-structure>
and if you are using the maven build the you can load the module by manifest entry for the dependency-
<build>
...
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<archive>
<manifestEntries>
<Dependencies>org.apache.cxf</Dependencies>
</manifestEntries>
</archive>
</configuration>
</plugin>
</plugins>
</build>

Custom jndi object factory in wildfly 8 for CDI

I am trying to achieve injecting a jndi resource using CDI for wildfly 8.
For this purpose i want to use a custom jnidfactory as developed in https://github.com/juanlmelo/mongo-jndi-plugin/
The problem is due to my limited knowledge in wildfly, I don't know the following.
1) how to activate/attach this jndifactory in wildfly, ofcourse I can create an object while startup and assign a jndi name to it programmatically , but want to explore custom factory feature of wildfly
2) the best practice to set the uri property needed by the object factory, i assume using System.getProperty inside the factory should suffice , as the DB uri will be different for each installation
once this is achieved I am confident I can get it injected into my classes using cdi.
I have tried my best to look for similar post, but couldn't find any, if you think this is duplicate please point me to the correct one.
Thanks,
If you want add custom JNDI factory to wildfly using https://github.com/juanlmelo/mongo-jndi-plugin/ you need to do few things:
1) You need to change a little bit implementation of https://github.com/juanlmelo/mongo-jndi-plugin/blob/master/src/main/java/com/mongodb/jndi/MongoClientJNDIFactory.java
- line 38 change to:
String mongoURI = (String) environment.get(MONGO_CLIENT_URI);
and comment out or delete lines 39-49
2) then run command mvn clean package and create directory eg.:
wildfly-8.1.0.Final/modules/com/mongodb/jndi/main/
copy there mongo-jndi-plugin-1.0.jar and create there module.xml file with content:
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="com.mongodb.jndi">
<resources>
<resource-root path="mongo-jndi-plugin-1.0.jar"/>
</resources>
<dependencies>
<module name="com.mongodb.driver"/>
<module name="javax.api"/>
</dependencies>
</module>
3) add mongo driver
-create directory: wildfly-8.1.0.Final/modules/com/mongodb/driver/main
-create there file: module.xml and place there:
<?xml version="1.0" ?>
<module xmlns="urn:jboss:module:1.1" name="com.mongodb.driver">
<resources>
<resource-root path="mongo-java-driver-2.11.0.jar"/>
</resources>
<dependencies>
<module name="javax.api"/>
</dependencies>
</module>
-add to this directory mongo-java-driver-2.11.0.jar library
4) add something like this
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
<object-factory name="java:global/MongoClient" module="com.mongodb.jndi" class="com.mongodb.jndi.MongoClientJNDIFactory">
<environment>
<property name="mongoClientURI" value="mongodb://username:password#yourdomain.com:27017,username:password#yourdomain.com:27017"/>
</environment>
</object-factory>
</bindings>
<remote-naming/>
</subsystem>
to your domain.xml or standalone.xml
voilĂ 
After this steps you can inject MongoClient into your classes using #Resource annotation (eg. #Resource(lookup = "java:global/MongoClient"