Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/366.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用shiro 1.2.1对数据库进行身份验证_Java_Security_Authentication_Guice_Shiro - Fatal编程技术网

Java 使用shiro 1.2.1对数据库进行身份验证

Java 使用shiro 1.2.1对数据库进行身份验证,java,security,authentication,guice,shiro,Java,Security,Authentication,Guice,Shiro,我在我的项目中使用ApacheShiro。目前我正在使用1.1.0版本,现在我正在尝试将Shiro组件迁移到最新的1.2.1版本。但是,当我尝试对数据库进行用户身份验证时,由于某种原因它不起作用,并且我没有收到任何错误,但是身份验证没有发生 以下是我在shiro.ini文件中给出的数据库详细信息 [main] cacheManager = com.cacheManager.ShiroCacheManager securityManager.cacheManager = $cacheManager

我在我的项目中使用ApacheShiro。目前我正在使用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集成示例

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

谢谢和问候,

Gupta Katakam

1.1和1.2之间有许多不同之处,可能会影响您的问题。。。这是我认为最有可能的一个

  • shiro.ini现在应该位于WEB-INF文件夹中。你动了你的吗
此外,还有许多与身份验证相关的更改:

  • 将Jsecurity与Guice集成
  • 密码和散列管理
  • 创建一个简单的命令行实用程序来散列密码
  • 创建PasswordService以自动化用户密码管理技术
  • 允许web配置的SecurityManager对非请求线程进行静态访问

  • 我认为这是第一个,但是对于1.2.0和

    来说,如果您使用的是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>
    

    
    /favicon.ico=anon
    /资产/**=anon
    /**=authc
    

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