天天看点

Spring Security的xml详细配置

<?xml version="1.0" encoding="UTF-8"?>

<beans:beans

    xmlns="http://www.springframework.org/schema/security"

    xmlns:beans="http://www.springframework.org/schema/beans"

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

    xmlns:dubbo="http://code.alibabatech.com/schema/dubbo"

    xsi:schemaLocation="http://www.springframework.org/schema/beans 

                                                http://www.springframework.org/schema/beans/spring-beans.xsd

                                                http://code.alibabatech.com/schema/dubbo http://code.alibabatech.com/schema/dubbo/dubbo.xsd

                                                http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">

    <!-- 不需要认证的页面,和静态资源不被拦截  -->  <!---->

    <http pattern="/*.html" security="none"></http>

    <http pattern="/css/**" security="none"></http>

    <http pattern="/img/**" security="none"></http>

    <http pattern="/js/**" security="none"></http>

    <http pattern="/plugins/**" security="none"></http>

    <!-- 要先增加用户,不然没用户登录,放开添加用户的方法不被拦截 -->

    <http pattern="/seller/add.do" security="none"></http>

    <!-- 页面的拦截规则 use-expressions:是否启动SPEL表达式 默认是true -->

    <http use-expressions="false">

     <!-- 当前用户必须有ROLE_开头, ROLE_USER的角色 才可以访问根目录及所属子目录的资源 -->

      <intercept-url pattern="/**" access="ROLE_SELLER" />

<!-- 开启表单登陆功能 -->

        <form-login login-page="/login.html"

            default-target-url="/admin/index.html"

            authentication-failure-url="/login.html"

            always-use-default-target="true" />

        <!--关闭跨域请求限制 -->

        <csrf disabled="true" />

        <!-- Spring Security下,X-Frame-Options默认为DENY,非Spring Security环境下,X-Frame-Options的默认大多也是DENY,这种情况下,浏览器拒绝当前页面加载任何Frame页面,设置含义如下: 

                DENY:浏览器拒绝当前页面加载任何Frame页面     SAMEORIGIN:frame页面的地址只能为同源域名下的页面     ALLOW-FROM:origin为允许frame加载的页面地址。 -->

        <headers>

            <frame-options policy="SAMEORIGIN" />

        </headers>

        <!--退出登录 不配置跳到页面,就默认跳到登录页面 -->

        <logout />

        <!-- logout-success-url 指定成功退出登录后要重定向的URL。 通过logout元素的logout-url属性来改变退出登录的默认地址。 -->

        <!-- <logout logout-url="/login.html" logout-success-url="/login.html"/> -->

    </http>

    <!-- 配置授权信息认证管理 -->

    <authentication-manager>

        <!--使用自定义认证服务-->  <!-- user-service-ref="userDetailService"自己指定的认证类 -->

        <authentication-provider user-service-ref="userDetailService">

        <!--把密码的加密的类走到认证的提供者里面  -->  <!--指定加密算法-->

        <password-encoder ref="bcryptEncoder"></password-encoder>

        </authentication-provider>

    </authentication-manager>

    <!-- 认证类 -->

    <beans:bean id="userDetailService"

        class="com.qingfeng.service.UserDetailsServiceImpl">

        <!-- 在 认证类里通过set注入,注入了 

                private SellerService sellerService;

                public void setSellerService(SellerService sellerService) {

                    this.sellerService = sellerService;

                }-->

        <beans:property name="sellerService" ref="sellerService"></beans:property>

    </beans:bean>

    <!-- 引用dubbo 服务 -->

    <dubbo:application name="qingfeng-shop-web" />

    <dubbo:registry address="zookeeper://192.168.25.135:2181" />

    <!--dubbo引用接口    相当是一个bean-->

    <dubbo:reference id="sellerService" inter></dubbo:reference>

    <!--这是密码加密的类  -->

    <beans:bean id="bcryptEncoder"

        class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder" />

</beans:beans>

继续阅读