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/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 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登陆将返回拒绝授权,如图:

Spring Security 匿名认证的更多相关文章
- Spring Security 入门(1-5)Spring Security - 匿名认证
匿名认证 对于匿名访问的用户,Spring Security 支持为其建立一个匿名的 AnonymousAuthenticationToken 存放在 SecurityContextHolder 中, ...
- 最简单易懂的Spring Security 身份认证流程讲解
最简单易懂的Spring Security 身份认证流程讲解 导言 相信大伙对Spring Security这个框架又爱又恨,爱它的强大,恨它的繁琐,其实这是一个误区,Spring Security确 ...
- Spring Cloud实战 | 第九篇:Spring Cloud整合Spring Security OAuth2认证服务器统一认证自定义异常处理
本文完整代码下载点击 一. 前言 相信了解过我或者看过我之前的系列文章应该多少知道点我写这些文章包括创建 有来商城youlai-mall 这个项目的目的,想给那些真的想提升自己或者迷茫的人(包括自己- ...
- Spring Security 接口认证鉴权入门实践指南
目录 前言 SpringBoot 示例 SpringBoot pom.xml SpringBoot application.yml SpringBoot IndexController SpringB ...
- 学习Spring Boot:(二十八)Spring Security 权限认证
前言 主要实现 Spring Security 的安全认证,结合 RESTful API 的风格,使用无状态的环境. 主要实现是通过请求的 URL ,通过过滤器来做不同的授权策略操作,为该请求提供某个 ...
- Spring Security自定义认证页面(动态网页解决方案+静态网页解决方案)--练气中期圆满
写在前面 上一回我们简单分析了spring security拦截器链的加载流程,我们还有一些简单的问题没有解决.如何自定义登录页面?如何通过数据库获取用户权限信息? 今天主要解决如何配置自定义认证页面 ...
- Spring boot +Spring Security + Thymeleaf 认证失败返回错误信息
[Please make sure to select the branch corresponding to the version of Thymeleaf you are using] Stat ...
- 学习Spring Security OAuth认证(一)-授权码模式
一.环境 spring boot+spring security+idea+maven+mybatis 主要是spring security 二.依赖 <dependency> <g ...
- Spring Security 安全认证
Spring Boot 使用 Mybatis 依赖 <dependency> <groupId>org.mybatis.spring.boot</groupId> ...
随机推荐
- 一些日常工具集合(C++代码片段)
一些日常工具集合(C++代码片段) ——工欲善其事,必先利其器 尽管不会松松松,但是至少维持一个比较小的常数还是比较好的 在此之前依然要保证算法的正确性以及代码的可写性 本文依然会持久更新,因为一次写 ...
- ajax批量删除功能的实现源代码
效果展示: 完整代码如下: <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charse ...
- CODEVS.1228 苹果树(DFS序)
To CODEVS.1228 苹果树 To poj 3321 Description 在卡卡的房子外面,有一棵苹果树.每年的春天,树上总会结出很多的苹果.卡卡非常喜欢吃苹果,所以他一直都精心的呵护这 ...
- [HDU5968]异或密码
[HDU5968]异或密码 题目大意: 数据共\(T(T\le100)\)组.每组给定一个长度为\(n(n\le100)\)的非负整数序列\(A(A_i\le1024)\),\(m(m\le100)\ ...
- 使用xlrd模块操作Excel
table = data.sheets()[] table = data.sheet_by_index() print(table) #获取正行或是整列的值 con = table.row_value ...
- 2016年3月12日Android学习笔记
1. //此句不能忘,否则onFling左右滑动不起作用 mLlExamView.setLongClickable(true); mLlExamView.setOnTouchListener(new ...
- Phone漂亮的动画
//此处标明非原创 实现iPhone漂亮的动画效果主要有两种方法, 一种是UIView层面的, 一种是使用CATransition进行更低层次的控制, 第一种是UIView,UIView方式可能在低层 ...
- CocosCreator的节点显示和隐藏
隐藏和显示有两种方式: 1.禁止节点node的运行,方法是x.node.active=false[此时隐藏了节点,且节点不再运行];恢复节点正常运行,x.node.active=true;或者使用x. ...
- java try-with-resource语句使用
定义 JDK7之后,Java多了个新的语法:try-with-resources语句, 可以理解为是一个声明一个或多个资源的 try语句(用分号隔开), 一个资源作为一个对象,并且这个资源必须要在执行 ...
- 【FFmpeg】ffplay播放rtsp视频流花屏问题 (转)
问题描述:ffplay播放rtsp视频流时,播放过程中随机出现花屏现象. 基本流程学习:阅读ffplay源码,熟悉其播放rtsp视频流的基本流程. 在ffplay源码阅读和分析的基础上,画出了其播放r ...