如何使用a JDBCRealm来处理servlet中的用户身份验证和授权?我能找到的唯一例子是创建DataSource web.xml(例如使用shiro 1.2.1对数据库进行身份验证).
我并不想在我的源代码树的数据库凭据(原因很明显),并希望通过JNDI使用上下文定义数据源,因为我有我在每一个其他的servlet项目用于任何其它目的,所有其他RDBMS我已经开发.
如何配置Shiro 从JNDI JDBCRealm获取它DataSource?
我正在尝试使用Shiro验证在Tomcat 6中运行的servlet.
我有以下shiro.ini文件:
[main]
ps = org.apache.shiro.authc.credential.DefaultPasswordService
pm = org.apache.shiro.authc.credential.PasswordMatcher
pm.passwordService = $ps
aa = org.apache.shiro.authc.credential.AllowAllCredentialsMatcher
sm = org.apache.shiro.authc.credential.SimpleCredentialsMatcher
jof = org.apache.shiro.jndi.JndiObjectFactory
jof.resourceName = jdbc/UserDB
jof.requiredType = javax.sql.DataSource
jof.resourceRef = true
realm = org.apache.shiro.realm.jdbc.JdbcRealm
realm.permissionsLookupEnabled = true
realm.credentialsMatcher = $pm
; Note factories are automatically invoked via getInstance(),
; see org.apache.shiro.authc.config.ReflectionBuilder::resolveReference
realm.dataSource = $jof
securityManager.realms = $realm
[urls]
/rest/** = authcBasic
/prot/** = authcBasic
Run Code Online (Sandbox Code Playgroud)
以下在我的数据库中:
mysql> select * from users;
+----------+------------------+----------+----------------------------------------------+--------------------------+
| username | email | verified | password | …Run Code Online (Sandbox Code Playgroud)