1

I'm making a RESTful backend using javax.ws.rs running on Tomcat, and the next step is to add the validation of tokens and every call will validate the token except for the call to create a user. I already have a code that runs for every call to take care of the CORS but I don't know what is the best way to exclude only the call to create users (and maybe another call), I will like to avoid the same line on every endpoint (to validate the token only requires two lines, it's not much but I don't like repetition).

1 Answer 1

2

You can write a filter which will validate every incoming request to you service. In that filter, you can check if the token is valid or not.

4
  • But how about the requests that should be excluded from this treatment?
    – Thilo
    Dec 2, 2018 at 3:01
  • 2
    If you are using spring security you do it very easily. Look at @EnableWebSecurity and WebSecurityConfigurerAdapter. You will need to implement WebSecurityConfigurerAdapter and in configure() method you can specify the endpoints to be validated.
    – G.G.
    Dec 2, 2018 at 3:12
  • @UserGG That sound exactly what I was looking for! can you elaborate on that, maybe an example. In any way thanks.
    – Fransebas
    Dec 2, 2018 at 18:36
  • @Fransebas: Look at this blog :spring.io/guides/gs/securing-web
    – G.G.
    Dec 3, 2018 at 5:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.