Search code examples
javaconnection-poolingshiroapache-tomee

How to point to tomee.xml connection pool from shiro.ini


I configured a connection pool in tomme.xml. So I presume I should not to configure another connection pool in shiro.ini. Instead I can simply point to the connection pool in tomme.xml from shiro.ini. How should I do this?

Here is tomee.xml

<?xml version="1.0" encoding="UTF-8"?>
<tomee>
  <!-- see http://tomee.apache.org/containers-and-resources.html -->

  <!-- activate next line to be able to deploy applications in apps -->
  <!-- <Deployments dir="apps" /> -->  


  <Resource id="testDatabase"  type="DataSource"> 
    accessToUnderlyingConnectionAllowed = false
    alternateUsernameAllowed = false
    connectionProperties = 
    defaultAutoCommit = true
    defaultReadOnly = 
    definition = 
    ignoreDefaultValues = false
    initialSize = 0
    jdbcDriver = com.teradata.jdbc.TeraDriver
    jdbcUrl = jdbc:teradata://XXXXXX,tmode=TERA,charset=UTF8,RECONNECT_COUNT=11
    jtaManaged = true
    maxActive = 20
    maxIdle = 20
    maxOpenPreparedStatements = 0
    maxWaitTime = -1 millisecond
    minEvictableIdleTime = 30 minutes
    minIdle = 0
    numTestsPerEvictionRun = 3
    password = XXXXXXXXXX
    passwordCipher = PlainText
    poolPreparedStatements = false
    serviceId = 
    testOnBorrow = true
    testOnReturn = false
    testWhileIdle = false
    timeBetweenEvictionRuns = -1 millisecond
    userName = XXXXX
    validationQuery = 
  </Resource>


</tomee>

Here is shiro.ini . I need to configure jdbcRealm in shiro.ini

[main]
# This does not work  
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
dataSource = org.apache.shiro.jndi.JndiObjectFactory
dataSource.resourceRef = true
dataSource.resourceName = "testDatabase"
jdbcRealm.dataSource = $dataSource
jdbcRealm.permissionsLookupEnabled = true  

# Configure JDBC realm SQL queries. 
jdbcRealm.authenticationQuery = SELECT XXX
jdbcRealm.userRolesQuery = SELECT XXX)

[urls]
/login.xhtml = user
/app/** = user  

I could configure a jdbcRealm within shiro.ini but I want to implement an already existing connection pool in tomee.xml . How can I do this ?


Solution

  • Not an expert in Shiro, but your tomee.xml configuration (while very verbose) should work. Your approach is correct, do not define a database pool in the application, define it on the server itself.

    Take a look at the accepted answer here: How to configure JDBCRealm to obtain its DataSource from JNDI

    And pay attention to the two comments on that answer. Cheers!