How to configure JDBCRealm to obtain its DataSource from JNDI

后端 未结 4 1150
猫巷女王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条回答
  •  孤独总比滥情好
    2021-02-04 05:48

    Vrushank's answer was really close: you don't need to subclass the JdbcRealm here - you can use Shiro's JndiObjectFactory to acquire the DataSource and then reference that DataSource when you configure the JdbcRealm:

    [main]
    dataSource = org.apache.shiro.jndi.JndiObjectFactory
    dataSource.resourceName = java://app/jdbc/myDataSource
    
    jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
    jdbcRealm.dataSource = $dataSource
    #addt'l config
    

    For a web application, save the file under WEB-INF/shiro.ini.

    See Also

    • https://github.com/danielmt/shiro-primefaces-example/blob/master/src/main/webapp/WEB-INF/shiro.ini

提交回复
热议问题