日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

SpringSecurity关闭csrf拦截

發(fā)布時間:2024/4/13 javascript 34 豆豆
生活随笔 收集整理的這篇文章主要介紹了 SpringSecurity关闭csrf拦截 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

然后你開開心心的輸入了用戶名user,密碼user,就出現(xiàn)了如下的界面:

?403什么異常?這是SpringSecurity中的權(quán)限不足!這個異常怎么來的?還記得上面SpringSecurity內(nèi)置認(rèn)證頁面源碼中的那個_csrf隱藏input嗎?問題就在這了!

完整的spring-security配置如下

<?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:context="http://www.springframework.org/schema/context"xmlns:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xmlns:mvc="http://www.springframework.org/schema/mvc"xmlns:security="http://www.springframework.org/schema/security"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/contexthttp://www.springframework.org/schema/context/spring-context.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/mvchttp://www.springframework.org/schema/mvc/spring-mvc.xsdhttp://www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security.xsd"><!--釋放靜態(tài)資源--><security:http pattern="/css/**" security="none"/><security:http pattern="/img/**" security="none"/><security:http pattern="/plugins/**" security="none"/><security:http pattern="/failer.jsp" security="none"/><!--配置springSecurity--><!--auto-config="true" 表示自動加載springsecurity的配置文件use-expressions="true" 表示使用spring的el表達式來配置springsecurity--><security:http auto-config="true" use-expressions="true"><!--讓認(rèn)證頁面可以匿名訪問--><security:intercept-url pattern="/login.jsp" access="permitAll()"/><!--攔截資源--><!--pattern="/**" 表示攔截所有資源access="hasAnyRole('ROLE_USER')" 表示只有ROLE_USER角色才能訪問資源--><security:intercept-url pattern="/**" access="hasAnyRole('ROLE_USER')"/><!--配置認(rèn)證信息--><security:form-login login-page="/login.jsp"login-processing-url="/login"default-target-url="/index.jsp"authentication-failure-url="/failer.jsp"/><!--配置退出登錄信息--><security:logout logout-url="/logout"logout-success-url="/login.jsp"/><!--去掉csrf攔截的過濾器--><!--<security:csrf disabled="true"/>--></security:http><!--把加密對象放入的IOC容器中--><bean id="passwordEncoder" class="org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder"/><!--設(shè)置Spring Security認(rèn)證用戶信息的來源--><!--springsecurity默認(rèn)的認(rèn)證必須是加密的,加上{noop}表示不加密認(rèn)證。--><security:authentication-manager><security:authentication-provider user-service-ref="userServiceImpl"><security:password-encoder ref="passwordEncoder"/></security:authentication-provider></security:authentication-manager> </beans>

總結(jié)

以上是生活随笔為你收集整理的SpringSecurity关闭csrf拦截的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。