enhance:改进示例代码。
This commit is contained in:
parent
bdfb249691
commit
3556c604f9
|
@ -342,7 +342,7 @@ public class UsernameRealm extends AuthoringRealm {
|
||||||
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
protected AuthenticationInfo doGetAuthenticationInfo(AuthenticationToken authenticationToken) throws AuthenticationException {
|
||||||
var token = (UsernamePasswordToken) authenticationToken;
|
var token = (UsernamePasswordToken) authenticationToken;
|
||||||
return memberRepository.findMemberByUsername((String) token.getPrincipal())
|
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("用户不存在。"));
|
.orElseThrow(() -> new AuthenticationException("用户不存在。"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -406,7 +406,7 @@ public class TokenRealm extends AuthorizingRealm {
|
||||||
// 在BearerToken中,无论是principal还是crendentials里保存的都是用户令牌信息
|
// 在BearerToken中,无论是principal还是crendentials里保存的都是用户令牌信息
|
||||||
return storeRepository.findTokenById(token.getToken())
|
return storeRepository.findTokenById(token.getToken())
|
||||||
.filter(t -> t.getExpires().isAfter(LocalDateTime.now()))
|
.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("用户令牌不存在。"));
|
.orElseThrow(() -> new AuthenticationException("用户令牌不存在。"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user