Question

How to map two different datasources in jboss *-ds.xml (in server/default/deploy) to two seperate login modules in login-config.xml (in server/default/conf) ?

( The datasources are at two different ip addresses)

I have tried the following so far but to no avail:

*-ds.xml

<connection-url>jdbc:mysql:loadbalance://hostip1,hostip2:port/dbname?loadBalanceBlacklistTimeout=5000</connection-url>

<security-domain>Policy1</security-domain>

login-config.xml

<application-policy name="Policy1">
<authentication>

  <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="sufficient">
<module-option name="username">userforip1</module-option>
<module-option name="password">pwdforip1</module-option>
</login-module>

  <login-module code="org.jboss.resource.security.SecureIdentityLoginModule" flag="sufficient">
<module-option name="username">userforip2</module-option>
<module-option name="password">pwdforip2</module-option>
</login-module>

</authentication>
</application-policy>

What more is required to be done ?

No correct solution

OTHER TIPS

<local-tx-datasource>
    <jndi-name>Name1</jndi-name>
    <connection-url>jdbc:mysql://Host1:Port1/catissuecore</connection-url>
    <user-name>user1</user-name>
    <password>pwd1</password>
    <driver-class>org.gjt.mm.mysql.Driver</driver-class>
    <check-valid-connection-sql>select 1</check-valid-connection-sql>
</local-tx-datasource>
<local-tx-datasource>
    <jndi-name>Name2</jndi-name>
    <connection-url>jdbc:mysql://Host2:Port2/catissuecore</connection-url>
    <user-name>user2</user-name>
    <password>pwd2</password>
    <driver-class>org.gjt.mm.mysql.Driver</driver-class>
    <check-valid-connection-sql>select 1</check-valid-connection-sql>
</local-tx-datasource>  

Above is the datasource file which you can use for your purpose. The users should have appropriate privileges and access.

I was trying to figure out something, but it seems that you can't do anything with default login modules.

The only solution that comes to my mind is to create custom login module and implement there needed logic.

If you have seam on your project, you can use a programatic way to get entity manager that persistenceUnitName can be diferent for each user, example:

EntityManager em =(EntityManager) org.jboss.seam.Component.getInstance("persistenceUnitName" + user.getName(), true);

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top