acegi的认证过程

AuthenticationManager是认证核心接口,其作用是验证客户端输入端用户名是否正确
这个接口只有一个方法
[code]public Authentication authenticate(Authentication authentication)
throws AuthenticationException;[/code]
这个方法就是去验证用户名 密码时候正确,那么用户名密码在那儿呢?封装在Authentication 类中,这样在authenticate()方法中就可取到用户名密码然后去验证。
验证用户名密码的方式是多种多样的如 Dao验证 ldap验证,被称为AuthenticationProvider,这些provider只要有一个验证通过就认为验证成功。(从别处看来的,未验证)
AuthenticationManager有一个子类ProviderManager,用来管理这些provider
其采用循环方式执行每个provider
[code]while (iter.hasNext()) {
AuthenticationProvider provider = (AuthenticationProvider) iter.next();

if (provider.supports(toTest)) {
logger.debug("Authentication attempt using " + provider.getClass().getName());

Authentication result = null;

try {
result = provider.authenticate(authentication);
sessionController.checkAuthenticationAllowed(result);
} catch (AuthenticationException ae) {
lastException = ae;
result = null;
}

if (result != null) {
sessionController.registerSuccessfulAuthentication(result);
publishEvent(new AuthenticationSuccessEvent(result));

return result;
}
}
}[/code]
循环完后,认证结束 返回了一个Authentication实例, 这个Authentication实例跟作为参数传进去的实例有什么不同呢?
看下面的代码
[code]public final Authentication authenticate(Authentication authRequest)
throws AuthenticationException {
try {
Authentication authResult = doAuthentication(authRequest);
copyDetails(authRequest, authResult);

return authResult;
} catch (AuthenticationException e) {
e.setAuthentication(authRequest);
throw e;
}
}[/code]
这段代码还是不能看到两个authResult 和authRequest的不同
看下面的代码
[code]protected Authentication createSuccessAuthentication(Object principal, Authentication authentication,
UserDetails user) {
// Ensure we return the original credentials the user supplied,
// so subsequent attempts are successful even with encoded passwords.
// Also ensure we return the original getDetails(), so that future
// authentication events after cache expiry contain the details
UsernamePasswordAuthenticationToken result = new UsernamePasswordAuthenticationToken(principal,
authentication.getCredentials(), user.getAuthorities());
result.setDetails(authentication.getDetails());

return result;
}[/code]
可以看到Credentials又被作为结果的一部分返回 。
user.getAuthorities是取得用户的权限
principal封装用户名 email等一些用户信息
值得注意的是这句,将传进来的details数据当作结果的一部分返回
result.setDetails(authentication.getDetails());
还有这句
[code]copyDetails(authRequest, authResult);
private void copyDetails(Authentication source, Authentication dest) {
if ((dest instanceof AbstractAuthenticationToken) && (dest.getDetails() == null)) {
AbstractAuthenticationToken token = (AbstractAuthenticationToken) dest;

token.setDetails(source.getDetails());
}
}[/code]
参数中的details又被重新设置到结果中并返回,如果在验证过程中details没有改变。。。。
这个details到底是干什么用的呢? 今天先写到这儿 明天再研究
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值