enhance:改进示例代码。

This commit is contained in:
徐涛 2021-09-29 21:36:41 +08:00
parent bdfb249691
commit 3556c604f9

View File

@ -342,7 +342,7 @@ public class UsernameRealm extends AuthoringRealm {
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
var token = (UsernamePasswordToken) authenticationToken;
return memberRepository.findMemberByUsername((String) token.getPrincipal())
.map(member -> new SimpleAuthenticationInfo(member, member.getPassword(), member.getFulLName()))
.map(member -> new SimpleAuthenticationInfo(member.getUsername(), member.getPassword(), "UsernameRealm"))
.orElseThrow(() -> new AuthenticationException("用户不存在。"));
}
}
@ -406,7 +406,7 @@ public class TokenRealm extends AuthorizingRealm {
// 在BearerToken中无论是principal还是crendentials里保存的都是用户令牌信息
return storeRepository.findTokenById(token.getToken())
.filter(t -> t.getExpires().isAfter(LocalDateTime.now()))
.map(t -> new SimpleAuthenticationInfo(t.getMember(), t.getToken(), t.getMember().getFulLName()))
.map(t -> new SimpleAuthenticationInfo(t.getMember().getUsername(), t.getToken(), "TokenRealm"))
.orElseThrow(() -> new AuthenticationException("用户令牌不存在。"));
}
}