I'm trying to secure the JAX-RS endpoint and am currently trying to figure out how the authentication and authorization work. Most examples are quite simple as they only piggyback from Java EE App-Server role via web.xml.
I'm wondering how to use something else than the Java EE AS roles. For example: I'd like to use session or some sort of token (or some sort of identifier).
It all depends upon the JAX-RS implementation you're using. I'm using Jersey on embedded Jetty.
See How to Configure Security with Embedded Jetty
Once you have the
Principal
in theHttpServletRequest
, you can inject these into the context of the JAX-RS request.Disclaimer: Don't role your own security framework unless you really, really, really, need one.
Look at what the OAuth filter in Jersey does. It reads the Authorization header which holds credentials in a different format than those normally understood (HTTP Basic). It'll turn those credentials into roles which you can then use to implement security (@RolesAllowed) if you add in the Roles Allowed Filter which does the actually enforcement. Try looking at how those filters work.