Spring MVC and Shiro Configuration using ini files

若如初见. 提交于 2019-12-07 02:24:01

问题


I'm trying to set up an environment with Spring MVC and Apache Shiro. I'm following articles mentioned in shiro.apache.org.

I'm using Spring's DelegatingFilterProxy as Shiro Filter in web.xml.

The current filtering is done using :

<bean id="shiroFilter" class="org.apache.shiro.spring.web.ShiroFilterFactoryBean">
        <property name="securityManager" ref="securityManager"/>
        <property name="loginUrl" value="/login"/>
        <property name="successUrl" value="/dashboard"/>
        <property name="unauthorizedUrl" value="/unauthorized"/>
        <property name="filterChainDefinitions">
            <value>
                /** = authc, user, admin
                /admin/** = authc, admin
                /login = anon
            </value>
        </property>
    </bean>

Question is, how do I use shiro.ini file defining security settings?


回答1:


You don't need to use shiro.ini. All of the rest of your configuration can (and should, since you're using ShiroFilterFactoryBean) be done in Spring.

For example, adding a securityManager and ehCache based cache manager to your shiroFilter:

<bean id="securityManager" class="org.apache.shiro.web.mgt.DefaultWebSecurityManager">
    <property name="realm" ref="myRealm"/>
    <property name="sessionMode" value="native"/>
    <property name="sessionManager" ref="sessionManager"/>
    <property name="cacheManager" ref="cacheManager"/>
</bean>

<bean id="cacheManager" class="org.apache.shiro.cache.ehcache.EhCacheManager">
    <property name="cacheManager" ref="ehCacheManager"/>
</bean>

<bean id="ehCacheManager" 
    class="org.springframework.cache.ehcache.EhCacheManagerFactoryBean"/>

<bean id="sessionDAO" 
    class="org.apache.shiro.session.mgt.eis.EnterpriseCacheSessionDAO"/>

<bean id="sessionManager"
    class="org.apache.shiro.web.session.mgt.DefaultWebSessionManager">
    <property name="sessionDAO" ref="sessionDAO"/>
</bean>

<bean id="myRealm" class="com.foo.MyRealm"/>



回答2:


You can check shiro documentation here http://shiro.apache.org/reference.html, it contains everything, in spring, as Les said, usually define different beans instead of using the shiro.ini file, but also you can use this file for authentication, use IniRealm like:

<bean id="myRealm" class="org.apache.shiro.realm.text.IniRealm">
  <property name="resourcePath" value="classpath:/shiro.ini" />
</bean>

more detail refers to here



来源:https://stackoverflow.com/questions/7448460/spring-mvc-and-shiro-configuration-using-ini-files

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!