0

I tried calling superclass public setter method from the subclass constructor and the code just works fine. Is it ok to do so or is it considered a bad practice? What can be the problem if its bad?

Edit: I have an AuthFilter

public class AuthFilter extends UsernamePasswordAuthenticationFilter {

    public AuthFilter(AuthenticationManager authenticationManager) {
    
        setRequiresAuthenticationRequestMatcher(new AntPathRequestMatcher("/user/login", "POST"));
        this.authenticationManager = authenticationManager;
    }
}

The UsernamePasswordAuthenticationFilter has the constructor

public UsernamePasswordAuthenticationFilter() extends AbstractAuthenticationProcessingFilter {
        
    super(new AntPathRequestMatcher("/login", "POST"));
}

So I am using the method setRequiresAuthenticationRequestMatcher(RequestMatcher requestMatcher) present in AbstractAuthenticationProcessingFilter to change the login path. This works, but is this the right way to do this?

Vimal
  • 77
  • 1
  • 9
  • Does this answer your question? [Calling superclass from a subclass constructor in Java](https://stackoverflow.com/questions/19326229/calling-superclass-from-a-subclass-constructor-in-java) – avocadoLambda Jun 25 '20 at 08:58
  • @Peter No that post doesn't answer my question. The problem there is different from this one. I have added more details in my post. – Vimal Jun 25 '20 at 10:11

0 Answers0