我有很多服务,我想通过身份验证服务集中我的身份验证。现在我是 Spring boot 的菜鸟,我不知道如何使这成为可能。
我只是从 Spring 实现了正常的安全性,它工作得很好,我只找到了一些关于的教程jdbcAuthentication,inMemoryAuthentication等的教程,但没有找到身份验证服务向另一个服务发送请求的身份验证。有人知道这件事吗?
我的安全基于代币 ->JWT
我想我需要操纵AuthenticationManagerBuilder因为它决定用户名是否有效。
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
}
Run Code Online (Sandbox Code Playgroud)
我用 Feign 提出请求 - 也许这段代码的位置错误
@Override
public Authentication attemptAuthentication(HttpServletRequest req, HttpServletResponse res) throws AuthenticationException, IOException, ServletException {
AccountCredentials credentials = new ObjectMapper()
.readValue(req.getInputStream(), AccountCredentials.class);
UserRequest userRequest = Feign.builder()
.decoder(new GsonDecoder())
.target(UserRequest.class,"http://localhost:7998/api/user-service/user/" + credentials.getUsername());
return getAuthenticationManager().authenticate(new UsernamePasswordAuthenticationToken(credentials.getUsername(),credentials.getPassword(),emptyList()));
}
Run Code Online (Sandbox Code Playgroud)