私の質問が初心者に聞こえるように思えるなら、謝罪してください。私は春の世界には新しいです。私はSpring Securityを使用してユーザーを認証しています。認証が正常に動作しているが、認証成功後、私は春がコントローラメソッド.`春のセキュリティ設定で春のセキュリティでログイン成功を処理する方法
@RequestMapping(value = "/login", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
public JwtAuthenticationResponse userLogin() {
System.out.println("Login Success");
JwtUser user = (JwtUser) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
String token = userService.generateToken(authenticationService.loadUserByUsername(user.getUsername()));
JwtAuthenticationResponse response = new JwtAuthenticationResponse(token, user.getAuthorities().toArray(),user.getUsername());
return response;
}
}
を呼びたい、私はこの場合、次の
http.authorizeRequests().anyRequest().permitAll().and().formLogin().loginProcessingUrl("/login").defaultSuccessUrl("/login");
http.addFilterBefore(filter,UsernamePasswordAuthenticationFilter.class);
を追加し、それがデフォルトに戻っています春のログインフォーム。私のコントローラメソッドを呼び出すのではありません。
私は
http://localhost:8080/myapp/login
を使用して要求が、誰かが私は、ログイン後に認証トークンを送信するためには、ログインが成功した後、コントローラを呼び出すために何をすべきかを提案することができました。
ありがとうございました!
は、ログインのためのカスタムコントローラを提供している場合は、ちょうどhttpSecurity
設定から
.formLogin().loginProcessingUrl("/login").defaultSuccessUrl("/login")
次取り除くあなた
@Ankitセキュリティ設定XMLファイルを使用していません。私はWebSecurityConfigurerAdapterを拡張し、AbstractAnnotationConfigDispatcherServletInitializerで設定しました。私はSpring MVCを使用しています。 – dharan