Question

I have question related to authorization and spring security. To implement authorization checks in one of my services (under a Service Oriented Architecture environment), I was trying to see if I can use Spring-Security. While going through the Spring Security documentation, I read here that spring security uses spring's AOP internally.

Ref: You can elect to perform method authorization using AspectJ or Spring AOP, or you can elect to perform web request authorization using filters. You can use zero, one, two or three of these approaches together. The mainstream usage pattern is to perform some web request authorization, coupled with some Spring AOP method invocation authorization on the services layer.

We are already using Spring AOP in our service implementations. In my case, the requests that will be coming to my RESTful service will carry a custom built token object that should be processed to perform authorization checks.

Based on this, I would like to understand if I can simply use Spring and create an Aspect to catch an inbound request, extract and process the associated (custom built) token and continue/reject the request based on the result ? Do I need spring-security, given that the communication channel is already secured using HTTPS ?

Thanks,

SGSI

Was it helpful?

Solution

For a similar situation we did the following a long time back:

  1. Used an HTTP filter to extract a token from HTTP headers for each request.
  2. Stored the extracted header to thread context.
  3. Added an aspect around service method calls to check the thread context for the token.

This strategy worked well for us. For last many years I have been using Spring Security since it has a more tested and comprehensive implementation for such problems.

If you wish to write your own token-passing implementation, you can check the source code for the Spring Security class SecurityContextHolder that provides multiple ways of passing security information on the execution thread.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top