春、カスタム認証プロバイダで作成されたオブジェクトをコントローラに渡したいと思います。どうやってやるの?私のコントローラで カスタム認証プロバイダからカスタムコントローラへのカスタムオブジェクトの受け渡し方法
@Component
public class CustomAuthProvider implements AuthenticationProvider {
@Override
public Authentication authenticate(Authentication authentication) throws AuthenticationException {
String email = authentication.getName();
String password = authentication.getCredentials().toString();
// check authentication here....
// create custom object
Object customObject = ...
return new UsernamePasswordAuthenticationToken(email,password, customObject);
}
は、私はこのカスタムオブジェクトを使用したい:
@RequestMapping(value = "/user", method = RequestMethod.GET)
public String test(Object customObject) {
//use customObject here
}
I疲れカスタムトークンオブジェクトを作成するために、UsernamePasswordAuthenticationTokenをこのように拡張する:
public class CustomAuthToken extends
UsernamePasswordAuthenticationToken {
//object of any class
private Object customObject;
public CustomAuthToken(Object principal, Object credentials) {
super(principal, credentials);
this.customObject = null;
}
public CustomAuthToken(Object principal, Object credentials, Object customObject) {
super(principal, credentials);
this.customObject = customObject;
}
カスタム認証プロバイダでこのトークンを返すと、次のエラーが表示されます。
No AuthenticationProvider found for com.example.demo.security.CustomAuthToken
これは私の望みを達成するための正しいアプローチですか?このエラーを修正するにはどうすればよいですか?