How to configure JDBCRealm to obtain its DataSource from JNDI

后端 未结 4 1153
猫巷女王i
猫巷女王i 2021-02-04 05:31

How do you use a JDBCRealm to handle authenticating and authorizing users in servlets? The only example I can find is to create the DataSource in web.xml

4条回答
  •  梦毁少年i
    2021-02-04 06:13

    I commented on @Les Hazlewood answer and on @Recurse comment, but might be that new answer is better option.

    In my case I have to use only JDNI datasource name on weblogic and full path on tomcat:

    Tomcat:

     ds = org.apache.shiro.jndi.JndiObjectFactory   
     ds.requiredType = javax.sql.DataSource  
     ds.resourceName = java:/comp/env/oracle/pportal_dev
    
     # JDBC realm config  
     jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm  
     jdbcRealm.permissionsLookupEnabled = true 
     jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
     jdbcRealm.dataSource = $ds
    

    Weblogic

     ds = org.apache.shiro.jndi.JndiObjectFactory   
     ds.requiredType = javax.sql.DataSource   
     ds.resourceName = oracle/pportal_dev
    
     # JDBC realm config  
     jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm  
     jdbcRealm.permissionsLookupEnabled = true 
     jdbcRealm.dataSource = $ds
    

    Note

    ds.resourceName = java:/comp/env/oracle/pportal_dev 
    vs
    ds.resourceName = oracle/pportal_dev
    

提交回复
热议问题