我想知道在Security中是否有可能锁定rest的所有端点,并通过在不使用用户名和密码的情况下进行自定义验证来进行登录。
这就像创建一个自定义验证方法,它接收令牌而不是用户/传递。然后,该方法将使用已经验证调用方的第三方验证令牌。
对于OAuth2来说,这听起来很熟悉,因为后端API需要在春季前实现安全,同时它不是OAuth2客户机:
非常感谢!
如有任何评论或参考,我们将不胜感激。
发布于 2017-07-19 14:15:47
Security通过查看SecurityContext
中的SecurityContextHolder
来确定用户是否经过身份验证。这意味着您可以使用以下方法验证用户的身份:
boolean userIsAuthenticated = ...
if(userIsAuthenticated) {
Authentication request = new UsernamePasswordAuthenticationToken(name, password);
Authentication result = ...
SecurityContext context = SecurityContextHolder.createEmptyContext();
context.setAuthentication(result);
SecurityContextHolder.setContext(context);
}
发布于 2017-07-19 10:30:21
Security是一个非常灵活的框架,它发布各种接口,允许用户根据需要定制行为。
我推荐以下资源来学习如何做到这一点:
https://stackoverflow.com/questions/45196658
复制