mixpplus
11/28/2019 - 11:33 AM

spring权限配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:security="http://www.springframework.org/schema/security"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/security http://www.springframework.org/schema/security/spring-security.xsd">


    <!--授权-->
    <!--配置资源不拦截-->
    <security:http pattern="/favicon.ico" security="none"></security:http>

    <!--授权: 给资源赋予权限-->
    <!--
        auto-config: 是否自动默认配置
        use-expressions: 是否使用spEL表达式
            不使用: ROLE_ADMIN ROLE_USER
            使用: hasRole('ROLE_ADMIN')  hasAnyRole('', '')
                   hasAuthority('')  hasAnyAuthority('','')
    -->
    <security:http auto-config="true" use-expressions="true">
        <!--不需要在拦截页面-->

        <!--配置自定义页面-->
        <!--
            login-page="": 登录页面
            login-processing-url="": 登录请求路径
            authentication-success-forward-url: 登录成功的路径(必须以 / 开头)
            authentication-failure-forward-url; 登录失败后路径(必须以 / 开头)
        -->

        <security:form-login
                login-page="http://localhost:83/login.html"
                login-processing-url="/login.do"
                authentication-success-forward-url="/user/doSuccess.do"
                authentication-failure-forward-url="/user/doFail.do"
        ></security:form-login>

        <security:csrf disabled="true"></security:csrf>

        <security:logout invalidate-session="true" logout-url="/logout.do" logout-success-url="http://localhost:83/login.html"></security:logout>

    </security:http>




    <!--创建对象-->
    <bean id="userService" class="com.itheima.security.SpringSecurityUserService"></bean>


    <!--认证: 提供用户信息-->
    <!--认证管理器-->
    <security:authentication-manager>
        <!--提供认证(用户名,密码,权限信息)信息-->
        <!--关联实现UserDetailsService接口的实现类-->
        <security:authentication-provider user-service-ref="userService">
            <!--关联加密工具类-->
            <security:password-encoder ref="passwordEncoder"></security:password-encoder>
        </security:authentication-provider>
    </security:authentication-manager>

    <!--关联加密工具类-->
    <bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"></bean>


    <!--开启注解-->
    <security:global-method-security pre-post-annotations="enabled"></security:global-method-security>
    
    
     <!--
    跨域配置
    <mvc:cors>
        <mvc:mapping path="/**"
                     allowed-origins="http://localhost:80"
                     allowed-methods="GET, PUT,OPTIONS,POST,DELETE"
                     allow-credentials="true"
                     max-age="3600" />
    </mvc:cors>
    
     浏览器会向所请求的服务器发起两次请求,第一次是浏览器使用OPTIONS方法发起一个预检请求,第二次才是真正的异步请求,第一次的预检请求获知服务器是否允许该跨域请求:如果允许,才发起第二次真实的请求;如果不允许,则拦截第二次请求。
	 allowed-origins: 允许的远程服务地址 要和远程请求路径上的地址一模一样 是localhost 就不能写127.0.0.1
	 allowed-methods: 允许的请求方式
	 max-age: 用来指定本次预检请求的有效期,单位为秒,在此期间不用发出另一条预检请求
        allow-credentials: 请求是否带cookie信息
        
        跨域时需要在每个axios请求上面添加一下代码:
        axios.defaults.withCredentials = true;
        axios.get(app_path + "/checkItem/deleteItem.do?id="+ row.id)...
    -->

</beans>