UsernamePasswordAuthenticationToken
UsernamePasswordAuthenticationToken继承AbstractAuthenticationToken实现Authentication
所以当在页面中输入用户名和密码之后首先会进入到UsernamePasswordAuthenticationToken验证(Authentication),
然后生成的Authentication会被交由AuthenticationManager来进行管理
而AuthenticationManager管理一系列的AuthenticationProvider,
而每一个Provider都会通UserDetailsService和UserDetail来返回一个
以UsernamePasswordAuthenticationToken实现的带用户名和密码以及权限的Authentication
public class SecurityProvider implements AuthenticationProvider {
@Autowired
private MyUserDetailService userDetailsService;
@Override
public Authentication authenticate(Authentication authentication)
throws AuthenticationException {
//
UsernamePasswordAuthenticationToken token = (UsernamePasswordAuthenticationToken) authentication;
UserDetails userDetails = userDetailsService.loadUserByUsername(token.getName());
if (userDetails == null) {
throw new UsernameNotFoundException("找不到该用户");
}
if(!userDetails.getPassword().equals(token.getCredentials().toString()))
{
throw new BadCredentialsException("密码错误");
}
return new UsernamePasswordAuthenticationToken(userDetails,userDetails.getPassword(),userDetails.getAuthorities());
}
@Override
public boolean supports(Class<?> authentication) {
// TODO Auto-generated method stub
return UsernamePasswordAuthenticationToken.class.equals(authentication);
}
}
https://github.com/Somersames/MySecurity
http://www.jdon.com/dl/best/securing-rest-services-with-spring.html.html
http://stackoverflow.com/questions/8764545/how-to-get-active-users-userdetails/8769670#8769670
UsernamePasswordAuthenticationToken的更多相关文章
- Spring Security笔记:自定义Login/Logout Filter、AuthenticationProvider、AuthenticationToken
在前面的学习中,配置文件中的<http>...</http>都是采用的auto-config="true"这种自动配置模式,根据Spring Securit ...
- 转:Acegi Security
Acegi Security -- Spring下最优秀的安全系统 http://www.springside.org.cn/docs/reference/Acegi.htm 1. Acegi 介绍 ...
- 【JavaEE】SSH+Spring Security自定义Security的部分处理策略
本文建立在 SSH与Spring Security整合 一文的基础上,从这篇文章的example上做修改,或者从 配置了AOP 的example上做修改皆可.这里主要补充我在实际使用Spring Se ...
- REST Security with JWT using Java and Spring Security
Security Security is the enemy of convenience, and vice versa. This statement is true for any system ...
- BPMX3模拟登录
实现功能只需要输入一个帐号即可登录系统. 需要实现上面的功能需要: 1.编辑imitate.jsp页面 <%@page import="com.hotent.core.util.Con ...
- 使用 Spring Security 保护 Web 应用的安全
安全一直是 Web 应用开发中非常重要的一个方面.从安全的角度来说,需要考虑用户认证和授权两个方面.为 Web 应用增加安全方面的能力并非一件简单的事情,需要考虑不同的认证和授权机制.Spring S ...
- Spring boot配合Spring session(redis)遇到的错误
背景:本MUEAS项目,一开始的时候,是没有引入redis的,考虑到后期性能的问题而引入.之前没有引用redis的时候,用户登录是正常的.但是,在加入redis支持后,登录就出错!错误如下: . __ ...
- 菜鸟-手把手教你把Acegi应用到实际项目中(1.1)
相信不少朋友们对于学习Acegi的过程是比较痛苦的,而且可能最初一个例子都没能真正运行起来.即使能运行起来,对于里面那么多的配置,更搞不清楚为什么要那么配,多配一个和少配一个究竟有什么区别? 最终头都 ...
- 【Spring】关于Boot应用中集成Spring Security你必须了解的那些事
Spring Security Spring Security是Spring社区的一个顶级项目,也是Spring Boot官方推荐使用的Security框架.除了常规的Authentication和A ...
随机推荐
- 十大ios开发者喜爱的开源库
十大ios开发者喜爱的开源库 (转自博客园) 2014-08-17 14:07:58| 分类: objective-c | 标签:ios 开源库 |举报|字号 订阅 下载LOFTER我的照片书 ...
- Spring Boot 2.0系列文章(七):SpringApplication 深入探索
关注我 转载请务必注明原创地址为:http://www.54tianzhisheng.cn/2018/04/30/springboot_SpringApplication/ 前言 在 Spring B ...
- Course3-Python文件I/O
1. 读取键盘输入 Python提供了两个内置函数从标准输入读入一行文本,默认的标准输入是键盘.如下: 1). raw_input. raw_input([prompt]) 函数从标准输入读取一个行, ...
- Spring Boot 多模块与 Maven 私有仓库
前言 系统复杂了,抽离单一职责的模块几乎是必须的:若需维护多个项目,抽离公用包上传私有仓库管理也几乎是必须的.其优点无需赘述,以下将记录操作过程. 1. 多模块拆分 在.NET 中由于其统一性,实现上 ...
- Windows上模拟Linux环境的软件Cygwin
Windows上模拟Linux环境的软件Cygwin 2010-10-11 15:19 我要评论(0) 字号:T|T Cygwin是一个用于在Windows上 模拟Linux环境的软件.它可 ...
- CSS基础知识01
一.CSS基础知识介绍 1.css是cascading style sheet层叠式样式表的简写 2.css小用法 加粗:font-weight:bold; 正常用:norma ...
- Gradle连接Maven仓库直接从仓库 更新JAR包
一般情况下服务器编写好服务程序 会用Maven打成JAR包,放在Maven仓库里管理,我们在用的时候直接引用就可以, 那么如何在Gradle项目中使用本地的 或者远程的Maven仓库呢 当M ...
- django自定义用户表
django中已经给我生成默认的User表,其中的字段已经可以满足我们的日常需求. 但有时候,我们需要更多的字段,我们就可以自定义.来替换django自带的User表. #models.py from ...
- spring 整合 shiro框架
shiro是用来干嘛的?从它的官网上(http://shiro.apache.org/)基本可以了解到,她主要提供以下功能: (1)Authentication(认证) (2)Authorizatio ...
- fastjson 的使用总结
前言 最近在开发过程中使用了大量的json作为前后端数据交换的方式,由于之前没有对json做过系统的学习,所有在使用过程中查阅了大量的文档与资料,这里主要记录了我在开发后对json以及fastjson ...