3

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 ?

EpicPandaForce
  • 79,669
  • 27
  • 256
  • 428
john
  • 647
  • 5
  • 23
  • 53

4 Answers4

2

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!

Community
  • 1
  • 1
Jonathan S. Fisher
  • 8,189
  • 6
  • 46
  • 84
1

try

securityManager.realm = $jdbcRealm
Dev
  • 6,628
  • 2
  • 25
  • 34
1

It seems DataSource is not in JNDI map so you need to add it yourself. You should do this through your DataSource id (in this case 'testDatabase'). There is several manner for example I put following in web.xml:

<resource-ref>
    <res-ref-name>testDatabase</res-ref-name>
    <res-type>javax.sql.DataSource</res-type>
</resource-ref>

or put the following at startup ejb:

@Resource(name="testDatabase", type=javax.sql.DataSource.class)

I prefer to use non-jta DataSource and in this case your non-jta DataSource id should be 'testDatabaseNonJta'. I'm not sure but following line may cause trouble for shiro:

accessToUnderlyingConnectionAllowed = false
M.Amini
  • 106
  • 1
  • 6
1

Jndi name of a resource of tomee.xml is "openejb:Resource/id" or define directly a global name and access it with java:global/....

Romain Manni-Bucau
  • 3,354
  • 1
  • 16
  • 13