如何配置JDBCRealm以从JNDI获取其数据源 [英] How to configure JDBCRealm to obtain its DataSource from JNDI

查看:198
本文介绍了如何配置JDBCRealm以从JNDI获取其数据源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何使用JDBCRealm处理servlet中的用户身份验证和授权?我可以找到的唯一示例是在web.xml中创建数据源(例如

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 (such as Authentication against database using shiro 1.2.1).

我不想在源代码树中包括数据库凭证(出于明显的原因),并且更喜欢通过JNDI使用Context定义的数据源,就像我在所有其他servlet项目中用于其他任何目的的RDBMS一样我已经开发了.

I do not want to include database credentials in my source tree (for obvious reasons) and would prefer to use a Context defined DataSource via JNDI as I have for every other RDBMS I have used for any other purpose in every other servlet project I have developed.

如何配置Shiro JDBCRealm从JNDI获取其DataSource?

How do you configure a Shiro JDBCRealm to obtain its DataSource from JNDI?

推荐答案

Vrushank的答案真的很接近:您不需要在这里对JdbcRealm进行子类化-您可以使用Shiro的

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

对于Web应用程序,将文件保存在WEB-INF/shiro.ini下.

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

这篇关于如何配置JDBCRealm以从JNDI获取其数据源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆