Spring下用Acegi的配置文件实例

来源:互联网 发布:mysql登录失败限制 编辑:程序博客网 时间:2024/05/20 01:47
Spring下用Acegi的配置文件实例:一个简单但齐全的配置实例,所有参数都写在xml文件里,以后会贴出使用Hibernate调用数据库中用户身份、权限参数的例子。

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">

<beans>

    <!-- 过滤器代理bean,代理其它过滤器-->
    <bean name="filterBean" class="org.acegisecurity.util.FilterChainProxy" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="filterInvocationDefinitionSource">
            <value>
                CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
                PATTERN_TYPE_APACHE_ANT
                /**=authentFilter,exceptionTranslationFilter,securityInterceptor
            </value>
        </property>
    </bean>

    <!-- 认证管理器-->
    <bean id="aManager" class="org.acegisecurity.providers.ProviderManager" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="providers">
            <list>
                <ref bean="daoAProvider" />
                <bean class="org.acegisecurity.providers.rememberme.RememberMeAuthenticationProvider">
                    <property name="key" value="changeThis"/>
                </bean>
               
            </list>
        </property>
    </bean>

    <!-- 认证提供者,从数据库获得-->
    <bean id="daoAProvider" class="org.acegisecurity.providers.dao.DaoAuthenticationProvider" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="userDetailsService">
            <ref bean="memoryUser"/>
        </property>
    </bean>

    <!-- 内存DAO数据,存放用户信息,暂时,测试用-->
    <bean id="memoryUser" class="org.acegisecurity.userdetails.memory.InMemoryDaoImpl" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="userMap">
            <value>
             chun2000=chun2000,ROLE_SUPERVISION
             abc=abc,ROLE_USER</value>
        </property>
    </bean>

    <!-- 访问决策管理器-->
    <bean id="accessDecisionManager" class="org.acegisecurity.vote.UnanimousBased" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="decisionVoters">
            <list>
                <ref bean="roleVoter" />
            </list>
        </property>
    </bean>
    <!-- 投票决策-->
    <bean id="roleVoter" class="org.acegisecurity.vote.RoleVoter" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default"></bean>
   
   
    <!-- 安全拦截过滤器-->
    <bean id="securityInterceptor" class="org.acegisecurity.intercept.web.FilterSecurityInterceptor" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="objectDefinitionSource">
            <value>
                CONVERT_URL_TO_LOWERCASE_BEFORE_COMPARISON
                PATTERN_TYPE_APACHE_ANT
                /do/*=ROLE_SUPERVISION
                /show.jsp=ROLE_USER
            </value>
        </property>
        <property name="authenticationManager">
            <ref bean="aManager" />
        </property>
        <property name="accessDecisionManager">
            <ref bean="accessDecisionManager"/>
        </property>
    </bean>
   
    <!-- 记住我服务-->
    <bean id="rembermeService" class="org.acegisecurity.ui.rememberme.TokenBasedRememberMeServices" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="userDetailsService">
            <ref bean="memoryUser"/>
        </property>
        <property name="key">
            <value>Can be change</value>
        </property>
    </bean>

    <!-- 基于表单的身份验证过滤器-->
    <bean id="authentFilter" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilter" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="filterProcessesUrl">
            <value>/j_acegi_security_check</value>
        </property>
        <property name="defaultTargetUrl">
            <value>/do/showStudent</value>
        </property>
        <property name="authenticationManager">
            <ref bean="aManager" />
        </property>
        <property name="authenticationFailureUrl">
            <value>/MyJsp.jsp</value>
        </property>
        <property name="rememberMeServices">
            <ref bean="rembermeService" />
        </property>
    </bean>

    <!-- 身份验证认证入口点-->
    <bean id="authenticationProcessingFilterEntryPoint" class="org.acegisecurity.ui.webapp.AuthenticationProcessingFilterEntryPoint" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="loginFormUrl">
            <value>/MyJsp.jsp</value>
        </property>
        <property name="forceHttps">
            <value type="boolean">false</value>
        </property>
    </bean>
   
    <!-- 异常过滤器 -->
    <bean id="exceptionTranslationFilter" class="org.acegisecurity.ui.ExceptionTranslationFilter" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
        <property name="accessDeniedHandler">
            <bean class="org.acegisecurity.ui.AccessDeniedHandlerImpl" abstract="false" singleton="true" lazy-init="default" autowire="default" dependency-check="default">
                <property name="errorPage">
                    <value>/AccessDenied.jsp</value>
                </property>
            </bean>
        </property>
        <property name="authenticationEntryPoint">
            <ref bean="authenticationProcessingFilterEntryPoint"/>
        </property>
    </bean>
</beans>