UsernamePasswordAuthenticationFilter是登陆用户密码验证过滤器,

来源:互联网 发布:抗皱护肤品知乎 编辑:程序博客网 时间:2024/05/21 21:55

UsernamePasswordAuthenticationFilter是登陆用户密码验证过滤器,它继承了AbstractAuthenticationProcessingFilter过滤器(真正的Filter),是spring security3的第4个过滤器。

UsernamePasswordAuthenticationFilter有3个表单参数,是我们需要知道的

1、usernameParameter:对应登录时的用户名需要传的参数名称,默认为j_username,比如你输入用户hello,表单提交时是这样的 j_username=hello

2、passwordParameter:对应登录时的密码提交时的参数名称,默认为j_password,比如你输入密码是123123,表单提交是这样的 j_password=123123

3、filterProcessesUrl(放在了AbstractAuthenticationProcessingFilter):表单提交地址,默认为/j_spring_security_check,这个地址才能被UsernamePasswordAuthenticationFilter所截取,进行登录认证。

UsernamePasswordAuthenticationFilter会将表单提交的用户密码以及一些用户的其他信息(比如remoteAddr,seesionId),先放入UsernamePasswordAuthenticationToken中

UsernamePasswordAuthenticationToken继承了AbstractAuthenticationToken,AbstractAuthenticationToken继承了Authentication(Authentication存放用户的所有的认证信息)

UsernamePasswordAuthenticationToken 中有2个参数Object principal(主要的身份认证信息),Object credentials(用于证明principal是正确的信息,比如密码)

在一个带有username和password的权限认证请求中,principal就会被赋值username,credentials就会被赋值password;在使用AuthenticationManager的时候,principal会被赋值更多具有丰富内容的信息,比如被赋值成一个UserDetails对象,credentials可能会被赋值密码类似的东西,比如一个特殊的类吧。

AbstractAuthenticationToken中有3个参数Object details,Collection<GrantedAuthority> authorities,boolean authenticated

1、details:额外的认证信息,比如被赋值用户的IP地址

2、authorities:授权信息,比如被赋值用户的角色信息

3、authenticated :是否被验证通过

上面的5个参数是Authentication(是一个接口)必须的

了解以上信息,对理解用户登陆权限的验证过程有很大帮助

0 0
原创粉丝点击