配置JDBC连接shiro.ini [英] Configure shiro.ini for JDBC connection
问题描述
由于我新的一年的学习我已经开始乱搞与Apache四郎安全框架新技术的举措的一部分。
我设法得到它存储用户名,密码和角色在shiro.ini文件中的基本的例子工作,但是当我修改了shiro.ini文件中使用JDBC它只是停止工作。现在我继续尝试访问我的应用程序时收到提示我的用户名和密码。我已经把它尽可能简单(密码甚至没有哈希)。
下面是我的shiro.ini文件,没有任何人有任何想法,我做错了?
[主]
authc.usernameParam =为j_username
authc.passwordParam =为j_password
authc.failureKeyAttribute = shiroLoginFailurejdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.permissionsLookupEnabled =真jdbcRealm.authenticationQuery =选择密码从用户其中username =?
jdbcRealm.userRolesQuery =选择角色从用户其中username =?DS = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName =本地主机
ds.user =根
ds.password =密码
ds.databaseName =数据库
jdbcRealm.dataSource = $ DS#使用内置Chache经理
builtInCacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $ builtInCacheManagersecurityManager.realms = $ jdbcRealm[网友]
[作用]
[网址]
/ * = authcBasic
如果你不给许可查询,然后更好地禁用权限查找。此外,如果你想为什么要用authc属性来使用基本身份验证。
试试以下
[主]
#authc.usernameParam =为j_username
#authc.passwordParam =为j_password
#authc.failureKeyAttribute = shiroLoginFailure jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.permissionsLookupEnabled = FALSE jdbcRealm.authenticationQuery =选择密码从用户其中username =?
从用户jdbcRealm.userRolesQuery =选择角色其中username =? DS = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName =本地主机
ds.user =根
ds.password =密码
ds.databaseName =数据库
jdbcRealm.dataSource = $ DS #使用内置Chache经理
builtInCacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $ builtInCacheManager securityManager.realms = $ jdbcRealm [网友]
[作用]
[网址]
/ * = authcBasic
As part of my new years learning new technologies initiative I have started messing around with the Apache Shiro Security Framework.
I managed to get the basic example working which stores usernames, passwords and roles in the shiro.ini file, but when I modified my shiro.ini file to use JDBC it just stopped working. I now keep getting prompted for my username and password when trying to access my application. I've kept it as simple as possible (the passwords aren't even hashed).
Below is my shiro.ini file, does anyone have any idea what I'm doing wrong?
[main]
authc.usernameParam = j_username
authc.passwordParam = j_password
authc.failureKeyAttribute = shiroLoginFailure
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.permissionsLookupEnabled = true
jdbcRealm.authenticationQuery = "SELECT password FROM user WHERE username = ?"
jdbcRealm.userRolesQuery = "SELECT role FROM user WHERE username = ?"
ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName = localhost
ds.user = root
ds.password = password
ds.databaseName = database
jdbcRealm.dataSource = $ds
# Use Built-in Chache Manager
builtInCacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $builtInCacheManager
securityManager.realms = $jdbcRealm
[users]
[roles]
[urls]
/* = authcBasic
If you are not giving permission query then better disable permission lookup. Also if you want to use basic Authentication why use authc attributes.
Try Following
[main]
#authc.usernameParam = j_username
#authc.passwordParam = j_password
#authc.failureKeyAttribute = shiroLoginFailure
jdbcRealm = org.apache.shiro.realm.jdbc.JdbcRealm
jdbcRealm.permissionsLookupEnabled = false
jdbcRealm.authenticationQuery = SELECT password FROM user WHERE username = ?
jdbcRealm.userRolesQuery = SELECT role FROM user WHERE username = ?
ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName = localhost
ds.user = root
ds.password = password
ds.databaseName = database
jdbcRealm.dataSource = $ds
# Use Built-in Chache Manager
builtInCacheManager = org.apache.shiro.cache.MemoryConstrainedCacheManager
securityManager.cacheManager = $builtInCacheManager
securityManager.realms = $jdbcRealm
[users]
[roles]
[urls]
/* = authcBasic
这篇关于配置JDBC连接shiro.ini的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!