私は多くのサービスを受けており、認証サービスで認証を集中管理したいと考えています。今私は春のブーツでのnoobieです。私はこれを可能にする方法を知りません。Spring Boot Authorization Serverが外部サービスにリクエストを送信してユーザーの詳細を取得します
私はちょうど春から通常のセキュリティを実装し、それは完全に動作し、jdbcAuthentication
、inMemoryAuthentication
などについてのチュートリアルがいくつか見つかりますが、認証サービスが別のサービスにリクエストを送信する認証はありません。誰かがこれについての手がかりを得るか?
トークンに基づいて、私のセキュリティ - >JWT
私はそれは、ユーザ名が有効であるかどうかを決定するので、私はAuthenticationManagerBuilder
を操作する必要があると思います。
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
}
と私は装うと私の要求を作る - このコードのかもしれない間違った場所
@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()));
}
をJWTの背後にある考え方は、彼らが「ということですステートレスで自己完結型です。 – chrylis
はい、トークンを取得するには、ユーザー名とパスワードを確認する必要があります。これらのデータは私の認証サービスに属していません。彼はいつも私のユーザーサービスに尋ねるべきです。その後、トークンを返す – DrMed