I'm (still) studying JASPIC, doing some experiments by simple project: this one. When I call a protected resources ServerAuthModule checks credentials via validateRequest and returns AuthStatus.SUCCESS. HTTP response is 200 but it is empty. I use these two curl commands to test:
curl -H "Content-Type: application/json" -X POST -d '{"username":"xxx","password":"xxx"}' http://localhost:8080/JaspicWeb/services/user/login
curl -H "Authorization: Bearer eyJhbGciOiJIUzI1NiJ9.eyJleHAiOjE0NzE0NzE1ODcsInN1YiI6InVzZXJBIn0.Gyf7w2192vlz3uSwjwtf8z1p9n9k3IqtQMQrubA7oYI" -X GET http://localhost:8080/JaspicWeb/services/user/userA
The first command is to get the token used in the second one. I'm using Jaspic with Wildfly10 and RestEasy.
Update:
I updated the linked project. Now it is a full working Jaspic example.
The SAM's
CallbackHandleris the cause of your troubles.First
it.jaspic.sec.TokenConfigProviderdisregards the handler passed to it by the runtime:Then
it.jaspic.sec.TokenServerConfiguses its own handler, which basically does nothing:Consequently,
it.jaspic.sec.TokenSAM#validateRequestis unable to communicate the caller's identity to the runtime. Since it still erroneously returnsAuthStatus.SUCCESSthough, it is pretty much undefined behaviour from that point on, at least as far as JASPIC is concerned. It is, amusingly, as if the Servlet container were trying to keep both parties happy in this case, by honoring both the SAM'sAuthStatusthat suggests a successful authentication message exchange, on the one hand, as well as the application's<security-constraint>on the other. Admittedly, a401,403, or perhaps better yet, a500response--indicative of an authentication mechanism not obeying its contract--might have been less confusing.The obvious solution is to pass the runtime-provided handler to the SAM. The API clearly doesn't help much, but for the single message layer/single app/single authentication mechanism use case, it should be sufficient to just lazily instantiate the
ServerAuthConfigwith the handler, when it is first requested by the runtime via agetServerAuthConfiginvocation:And, of course, the new constructor called above (which only has to store the handler argument) has to be introduced into
it.jaspic.sec.TokenServerConfig.Those two changes should render the
/services/user/userAendpoint accessible.