【问题标题】:Authentication against database using shiro 1.2.1使用 shiro 1.2.1 对数据库进行身份验证
【发布时间】:2012-10-05 08:16:06
【问题描述】:

我在我的项目中使用 Apache Shiro。目前我正在使用 1.1.0 版本,现在我正在尝试将 Shiro 组件迁移到最新版本 1.2.1。但是,当我尝试对数据库进行用户身份验证时,由于某种原因它无法正常工作,并且我没有收到任何错误,但身份验证没有发生。

以下是我在 shiro.ini 文件中提供的数据库详细信息。

[main]
cacheManager = com.cacheManager.ShiroCacheManager
securityManager.cacheManager = $cacheManager

jdbcRealm=org.apache.shiro.realm.jdbc.JdbcRealm

jdbcRealm.authenticationQuery = select user_pass from users where user_name = ?
jdbcRealm.userRolesQuery = select role_name from user_roles where user_name = ?

ds = com.mysql.jdbc.jdbc2.optional.MysqlDataSource
ds.serverName = 192.168.0.75
ds.port  = 3306
ds.user = test
ds.databaseName = appfuse
jdbcRealm.dataSource = $ds

但它仍然没有命中数据库。我正在使用 tomcat 服务器并尝试使用 guice 和 shiro 集成示例...

非常感谢您在这方面的任何帮助,并提前感谢您的帮助!

感谢和问候,
古普塔·卡塔卡姆

【问题讨论】:

  • 您是否遇到任何特定错误?你能分享一下吗?如果删除缓存管理器会发生什么?

标签: java security authentication guice shiro


【解决方案1】:

1.1 和 1.2 之间有许多不同之处可能会影响您的问题...这是我认为最有可能发生的问题

  • SHIRO-178shiro.ini 现在应该在 WEB-INF 文件夹中。你的移动了吗?

此外,还有一些与身份验证相关的更改:

  1. SHIRO-23 将 Jsecurity 与 Guice 集成
  2. SHIRO-213密码和哈希管理
  3. SHIRO-279 创建一个简单的命令行实用程序来散列密码
  4. SHIRO-280 创建 PasswordService 以自动化用户密码管理技术
  5. SHIRO-287 启用 Web 配置的 SecurityManager 以供非请求线程静态访问

我认为这是第一个,但 entire list of release notes can be found here 用于 1.2.0 和 here for 1.2.1

【讨论】:

    【解决方案2】:

    如果你使用的是 Spring,那么就使用这个

    创建数据库访问数据库

    <bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager" />
        <property name="loginUrl" value="/login" />
        <property name="successUrl" value="/homePage" />
        <property name="unauthorizedUrl" value="/unauthorized" />
        <property name="filters">
            <util:map>
                <entry key="authc">
                    <bean class="org.apache.shiro.web.filter.authc.PassThruAuthenticationFilter" />
                </entry>
            </util:map>
        </property>
        <property name="filterChainDefinitions">
            <value>
                /favicon.ico = anon
                /assets/** = anon
                /** = authc
            </value>
        </property>
    </bean>
    
    <bean id="shiroCacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
        <property name="cacheManagerConfigFile" value="classpath:ehcache.xml"></property>
    </bean>
    
    <bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
        <property name="cacheManager" ref="shiroCacheManager" />
        <property name="realm" ref="myRealm" />
    </bean>
    <bean id="lifecycleBeanPostProcessor" class="org.apache.shiro.spring.LifecycleBeanPostProcessor" />
    
    <bean id="myRealm" class="org.apache.shiro.realm.jdbc.JdbcRealm">
        <property name="dataSource" ref="shiroDatasource" />
        <property name="permissionsLookupEnabled" value="true" />
    </bean>
    
    <bean class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close" id="shiroDatasource">
        <property name="driverClassName" value="com.mysql.jdbc.Driver" />
        <property name="url"
            value="jdbc:mysql://localhost:3306/accessdb?autoReconnect=true&amp;zeroDateTimeBehavior=convertToNull" />
        <property name="username" value="username" />
        <property name="password" value="passwor" />
        <property name="validationQuery" value="SELECT 1" />
    </bean>
    

    【讨论】:

      猜你喜欢
      • 2017-07-23
      • 2012-08-26
      • 2013-06-30
      • 2015-09-28
      • 2014-07-09
      • 2017-02-20
      • 2013-06-27
      • 2016-04-17
      • 2016-01-11
      相关资源
      最近更新 更多