當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring Security 匿名认证
生活随笔
收集整理的這篇文章主要介紹了
Spring Security 匿名认证
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1、項目截圖:
2、匿名認證配置:
<?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/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/securityhttp://www.springframework.org/schema/security/spring-security.xsd"><security:http auto-config="true"><security:anonymous enabled="true" key="doesNotMatter" granted-authority="ROLE_ANONYMOUSLY" username="user"></security:anonymous><security:intercept-url pattern="/admin/**" access="ROLE_USER"/> --設置ROLE_USER訪問權限<security:intercept-url pattern="/common/**" access="ROLE_USER,ROLE_ANONYMOUSLY"/><security:intercept-url pattern="/**" access="ROLE_USER,ROLE_ANONYMOUSLY"></security:intercept-url></security:http> <!-- <bean id="anonymousAuthFilter"class="org.springframework.security.web.authentication.AnonymousAuthenticationFilter"><property name="key" value="doesNotMatter" /><property name="userAttribute" value="anonymousUser,ROLE_ANONYMOUS" /></bean><bean id="anonymousAuthenticationProvider"class="org.springframework.security.authentication.AnonymousAuthenticationProvider"><property name="key" value="doesNotMatter" /></bean>--><security:authentication-manager><security:authentication-provider><security:user-service><security:user name="admin" password="admin" authorities="ROLE_USER"></security:user><security:user name="user" password="user" authorities="ROLE_ANONYMOUSLY"></security:user></security:user-service></security:authentication-provider></security:authentication-manager> </beans>admin 登陸后能訪問所有頁面,而user登陸將返回拒絕授權,如圖:
轉載于:https://www.cnblogs.com/tyb1222/p/4157947.html
總結
以上是生活随笔為你收集整理的Spring Security 匿名认证的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 网页TO PDF
- 下一篇: Android Studio开发环境配置