2016-01-06 135 views
0

由於我新的一年的學習我已經開始與Apache四郎安全框架亂搞新技術計劃的一部分。配置shiro.ini JDBC連接

我設法得到它存儲的用戶名,密碼,角色在shiro.ini文件中的基本的例子工作,但是當我修改shiro.ini文件中使用JDBC,它只是停止工作。在嘗試訪問我的應用程序時,我現在不斷收到提示輸入用戶名和密碼。我已經把它儘可能簡單(密碼甚至沒有哈希)。

下面是我的shiro.ini文件,沒有任何人有任何想法,我做錯了什麼?

[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 
+0

你可以嘗試從您的查詢刪除引號? – Wouter

回答

1

如果你不給許可查詢,則最好關閉權限查找。另外如果你想使用基本的身份驗證,爲什麼使用authc屬性。

嘗試以下

[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