Deploying a datasource w/ JAAS login module as a .sar in jboss - jboss

Does anyone have experience bundling a datasource (-ds.xml) definition + login-config.xml as a service archive in jboss? I've been fighting with this for awhile to no avail. I'm just looking for some pointers on how I should be laying the .sar out. I want the .sar to ultimately live in a .ear. Any pointers greatly appreciated!

This is relatively straightforward task.
Your EAR file needs to have following layout:
my-app.ear
|+ META-INF
|+ applications.xml and jboss-app.xml
|+ myapp.war
|+ myapp.jar
|+ lib
|+ my-ds.xml
|+ my-login-module-service.xml
where my-ds.xml contains datasource definition as usual. my-login-module-service.xml defines MBean based on the DynamicLoginConfig class. These modules are then referenced within jboss-app.xml (custom JBoss deployment descriptor) as demostrated here:
<jboss-app>
<module>
<service>my-login-module-service.xml</service>
</module>
<module>
<service>my-ds.xml</service>
</module>
</jboss-app>
Easiest way how to create Login Module definition is to use support for embedded XML documents as attributes values. Such a config (my-login-module-service.xml) will looks like this:
<server>
<mbean code="org.jboss.security.auth.login.DynamicLoginConfig"
name="jboss:service=DynamicLoginConfig">
<attribute name="PolicyConfig" serialDataType="jbxb">
<jaas:policy xsi:schemaLocation="urn:jboss:security-config:4.1 resource:security-config_4_1.xsd" xmlns:jaas="urn:jboss:security-config:4.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<jaas:application-policy name="userinrole">
<jaas:authentication>
<jaas:login-module code="org.jboss.security.auth.spi.XMLLoginModule" flag="required">
<jaas:module-option name="my-policy-123">
<ur:users xsi:schemaLocation="urn:jboss:user-roles:1.0 resource:user-roles_1_0.xsd" xmlns:ur="urn:jboss:user-roles:1.0">
<ur:user name="admin" password="admin123">
<ur:role name="MyUserRole"></ur:role>
<ur:role name="AdminUser"></ur:role
</ur:user>
</ur:users>
</jaas:module-option>
<jaas:module-option name="unauthenticatedIdentity">guest</jaas:module-option>
</jaas:login-module>
</jaas:authentication>
</jaas:application-policy>
</jaas:policy>
</attribute>
<depends optional-attribute-name="LoginConfigService">jboss.security:service=XMLLoginConfig</depends>
<depends optional-attribute-name="SecurityManagerService">jboss.security:service=JaasSecurityManager</depends>
</mbean>
</server>
You can verify successful deployment using JNDIVIew bean (java:/jaas/my-policy-123 in this example).
For deployment including custom classes it's better to choose SAR archive deployment together with custom code. In such a case you can separate MBean definition and Login Module config (META-INF/jboss-service.xml) :
<server>
<mbean code="org.jboss.security.auth.login.DynamicLoginConfig" name="jboss:service=DynamicLoginConfig">
<attribute name="AuthConfig">META-INF/login-config.xml</attribute>
<depends optional-attribute-name="LoginConfigService">jboss.security:service=XMLLoginConfig</depends>
<depends optional-attribute-name="SecurityManagerService">jboss.security:service=JaasSecurityManager</depends>
</mbean>
</server>
META-INF/login-config.xml will then contain your policy configuration.
I'm using this approach on JBoss AS 4.x.

Related

Set system properties in standalone-full.xml in wildfly 8.2

I have added system-properties tag in standalone-full.xml, but its not working in standalone mode. However, if I add the same tag in domain.xml it's working for domain mode.
<?xml version='1.0' encoding='UTF-8'?>
<server xmlns="urn:jboss:domain:2.2">
<extensions>
....
</extensions>
<system-properties>
<property name="java.util.Arrays.useLegacyMergeSort" value="true"/>
</system-properties>
</server>
According to this article on jBoss General configuration concepts
System property values can be set in a number of places in domain.xml, host.xml and standalone.xml.
Then what about standalone-full.xml?
I don't want to set it through command line and not even in java code.
In standalone it's probably too late to set it in the configuration files. You'll need to add it to the standalone.conf or standalone.conf.bat in the JAVA_OPTS environment variable. A global property like that needs to be set before anything else attempts to use java.util.Arrays.
If you have started the Wildfly server with standalone-full.xml instead of standalone.xml(the default) than this should be reflected in the start of the server:
standalone.sh -b <hostIP> -c standalone-full.xml -Dorg...
Then this will have effect on first start.
If you change something in this config file, you will need to reload Wildfly(configuration) from jboss cli:
[standalone#localhost:9990 /] :reload
For Wildfly 10 it's working nontheless. I was able to read the property for an instance started with the standalone-full.xml containing some properties.
The manual must be outdated then I guess? Because even Wildfly itself inserts a new property in the standalone-full.xml when using the Wildfly admin webinterface: http://localhost:9990 > Configuration > System Properties (Wildfly will add the property of course to the xml config which was used to start the instance). That's enough proof for me.

Issue enabling jpa and jdbc in Websphere Liberty

I am following these exercises for learning Liberty.
I am having an issue in he Lab 3 - Module 2.2 Liberty and JPA (DB2) .
After setting all the JDBC and Data Source details, i restart the server and i do not see the two lines that mention the dataSource and jdbd driver.
[AUDIT] J2CA8004I : The dataSource DB2Connection is avilable as jdbc/DB2Connection.
[AUDIT] J2CA8000I : The jdbcDriver my JDBCDriver is available.
How can i know if the jpa and jdb features ae correctly set?
This is the server.xml
<!-- Enable features -->
<featureManager onError="WARN">
<feature>jsp-2.2</feature>
<feature>jpa-2.0</feature>
<feature>jdbc-4.0</feature>
</featureManager>
<!-- To access this server from a remote client add a host attribute to the following element, e.g. host="*" -->
<httpEndpoint id="defaultHttpEndpoint"
httpPort="9080"
httpsPort="9443" />
<jdbcDriver id="myJDBCDriver">
<library name="DB2Lib">
<fileset dir="C:\wlp\db2jdbc" includes="db2jcc4.jar, db2jcc_license_cu.jar"></fileset>
</library>
</jdbcDriver>
<dataSource jndiName="jdbc/DB2Connection" id="DB2Connection"
jdbcDriverRef="myJDBCDriver">
<properties.db2.jcc databaseName="SAMPLE" serverName="igacloud" password="{xor}FhgeOz1tPj08" user="db2admin"></properties.db2.jcc>
</dataSource>
Unlike Classic WebSphere, which has a "test connection" capability in its admin console (datasource panel), there is no equivalent means with WebSphere Liberty yet. Have you tried testing the connection with a simple "Hello World" JPA application?
The CWWKF0012I message is simply confirming what features have been enabled - some features depend on other features and automatically enables them, which is why you see more features than defined in your server.xml.

Meaning of name attribute in JBoss MBean xml descriptor

JBoss 4/5 MBeans such as NamingAlias are defined in XML as follows
<mbean code="org.jboss.naming.NamingAlias" name=":service=NamingAlias,fromName=queue/original">
<attribute name="ToName">queue/linked</attribute>
<attribute name="FromName">queue/original</attribute>
</mbean>
Paying attention to the attributename=":service=NamingAlias,fromName=queue/original I see the parameters service and fromName.
Following the instructions to create a custom MBean here:
https://developer.jboss.org/wiki/ExampleHelloWorldService
The XML configuration for the MBean created is
<server>
<mbean code="com.acme.HelloWorldService" name="acme.com:service=HelloWorld">
<attribute name="Message">Hello World</attribute>
</mbean>
</server>
I noticed only service is specified in the name attribute.
Is service mandatory for all the beans? What about adding additional parameters such as fromName? Can these values be used from within the class that implements the MBean or are those mandated?
The name attribute can be any valid (and unique) JMX ObjectName. The keys and values themselves do not have any special significance other than their subjective significance to the developer.
In the first example, the ObjectName does not specify a domain (the value to the left of the colon) so the MBeanServer assumes the default domain, which in this case would be jboss so notionally:
:service=NamingAlias,fromName=queue/original == jboss:service=NamingAlias,fromName=queue/original
The ObjectName (and it's embedded domain and key/values) can be used within the class. In standard JMX, one would typically make the impl implement MBeanRegistration which injects the MBeanServer and ObjectName when the bean is registered. However, the example you referenced is a specialized JBoss ServiceMBean which does this automatically and your implementation will store the ObjectName in the field called serviceName.

Loading properties from a file in a JBoss 6 Web Application

Can I dump a properties file somewhere in one of the JBoss 6 directories, and pick it up from the classpath?
Or even better, does anybody know the mechanism behind a configuration file like $JBOSS_HOME/server/default/deploy/jboss-logging.xml? Changes to this file seem to trigger an event, so that a running instance can process the modifications (without having to bounce the AS).
A possibility is to configure SystemPropertiesService in ./conf/jboss-service.xml.
This allows you to configure system properties in-place, or load them from a properties file:
<server>
<mbean code="org.jboss.varia.property.SystemPropertiesService"
name="jboss.util:type=Service,name=SystemProperties">
<!-- Load properties from each of the given comma seperated URLs -->
<attribute name="URLList">
http://somehost/some-location.properties,
./conf/somelocal.properties
</attribute>
<!-- Set propertuies using the properties file style. -->
<attribute name="Properties">
property1=This is the value of my property
property2=This is the value of my other property
</attribute>
</mbean>
</server>
For more details, refer to: http://docs.jboss.org/jbossas/admindevel326/html/ch10.html
They have made this even easier in JBoss EAP 6 (AS 7).
Pass Property File as Startup Parameter
This can be added within the main start up script or passed as parameter
./standalone.sh --properties=/Users/john.galt/dev/config/ds/jboss.properties
If these properties are read, they will be rendered in the server log as the first statement.
3:58:41,633 DEBUG [org.jboss.as.config] (MSC service thread 1-6) Configured system properties:
DSsettings.password = password
DSsettings.user-name = admin
DSsettings.connection-url = jdbc:oracle:fat:#activedb:1521:DEV
[Standalone] =
awt.nativeDoubleBuffering = true
NOTE: As these settings are logged in server log, ensure no clear text passwords are in the property files in production
Use passed in system properties
You could use these system properties with following syntax.
Example Usage in a data source file
<xa-datasource jndi-name="java:jboss/ds" pool-name="cPool" jta="true" enabled="true" use-ccm="true">
<xa-datasource-property name="URL">
${DSsettings.connection_url}
</xa-datasource-property>
<driver>oracle</driver>
...
<security>
<user-name>${DSsettings.user-name}</user-name>
<password>${DSsettings.password}</password>
</security>
...
</xa-datasource>
In JBoss 6 use: ./deploy/properties-service.xml
On JBoss AS7 properties-service.xml no longer exist, the below is the solution:
http://www.mastertheboss.com/jboss-server/jboss-configuration/how-to-inject-system-properties-into-jboss

How to configure startup sequence of JBoss services (JmsActivation)

When I deploy my application on JBoss 5 the EJBs are created before the QueueService is started. Creation of Message Driven beans now fails miserably because the queues are not yet available:
17:11:29,151 INFO [EJBContainer] STARTED EJB: .....
17:11:29,266 INFO [JndiSessionRegistrarBase] Binding the following Entries in Global JNDI:
..
..
17:11:29,928 WARN [JmsActivation] Failure in jms activation org.jboss.resource.adapter.jms.inflow.JmsActivationSpec#11694c ...
javax.naming.NameNotFoundException: ... not bound
at org.jnp.server.NamingServer.getBinding(NamingServer.java:771)
at org.jnp.server.NamingServer.getBinding(NamingServer.java:779)
at org.jnp.server.NamingServer.getObject(NamingServer.java:785)
at org.jnp.server.NamingServer.lookup(NamingServer.java:443)
at org.jnp.server.NamingServer.lookup(NamingServer.java:399)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:722)
at org.jnp.interfaces.NamingContext.lookup(NamingContext.java:682)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at org.jboss.util.naming.Util.lookup(Util.java:222)
at org.jboss.resource.adapter.jms.inflow.JmsActivation.setupDestination(JmsActivation.java:464)
at org.jboss.resource.adapter.jms.inflow.JmsActivation.setup(JmsActivation.java:352)
at org.jboss.resource.adapter.jms.inflow.JmsActivation$SetupActivation.run(JmsActivation.java:729)
at org.jboss.resource.work.WorkWrapper.execute(WorkWrapper.java:213)
at org.jboss.util.threadpool.BasicTaskWrapper.run(BasicTaskWrapper.java:260)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
at java.lang.Thread.run(Thread.java:619)
17:11:30,027 INFO [QueueService] Queue[/queue/....] started, fullSize=200000, pageSize=2000, downCacheSize=2000
How can the deploy sequence be configured?
Found the answer myself. I added the following annotation to the message driven bean:
#Depends({"jboss.messaging.destination:service=Topic,name=XxxxTopic"})
<?xml version="1.0" encoding="UTF-8"?>
<!--
Null persistence config.
Use this if you don't actually want to persist anything
$Id$
-->
<server>
<!-- Persistence Manager MBean configuration
======================================== -->
<mbean code="org.jboss.messaging.core.jmx.NullPersistenceManagerService"
name="jboss.messaging:service=PersistenceManager"
xmbean-dd="xmdesc/NullPersistenceManager-xmbean.xml"/>
<!-- Messaging Post Office MBean configuration
========================================= -->
<mbean code="org.jboss.messaging.core.jmx.MessagingPostOfficeService"
name="jboss.messaging:service=PostOffice"
xmbean-dd="xmdesc/MessagingPostOffice-xmbean.xml">
<depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
<depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>
<!-- The name of the post office -->
<attribute name="PostOfficeName">JMS post office</attribute>
<!-- This post office is clustered. If you don't want a clustered post office then set to false -->
<attribute name="Clustered">false</attribute>
</mbean>
<!-- Messaging JMS User Manager MBean config
======================================= -->
<mbean code="org.jboss.jms.server.plugin.JDBCJMSUserManagerService"
name="jboss.messaging:service=JMSUserManager"
xmbean-dd="xmdesc/JMSUserManager-xmbean.xml">
<depends optional-attribute-name="TransactionManager">jboss:service=TransactionManager</depends>
</mbean>
</server>
save this as 'null-persistence-service.xml' and put this deploy/messaging/
Now it will works