jersey - Checking Principal-user by Injected SecurityContext inside the constructor of a web resource -
i'm relatively new jersey , jax-rs, can't find way in documentation use of securitycontext inside constructor of resource.
our oauth implementation such requests on rest api intercepted implementation of resourcefilter. resource filter sets user principal calling:
containerrequest.setsecuritycontext(new mysecuritycontext(user));
... inside containerrequest.filter() method, wwith concrete class mysecuritycontext, as:
public class mysecuritycontext implements securitycontext { private final user principal; public mysecuritycontext(final user user) { this.principal = user; } @override public string getauthenticationscheme() { return securitycontext.form_auth; } @override public principal getuserprincipal() { return principal; } @override public boolean issecure() { return false; } @override public boolean isuserinrole(string role) { return principal.getroles().contains(role); } }
now want use user principal in constructor of webresource before @get/@post/@delete method called. i've tried injecting
@context securitycontext
..into constructor argument list call getuserprincipal() yields null.
is there way check principal user in constructor of webresource?
thanks!
it works me if inject api endpoint:
@post @resourcefilters({myauthenticationfilter.class}) public response foo(@context httpservletrequest request, @context securitycontext security) { final principal principal = security.getuserprincipal(); [...] return response.status(response.status.ok).build(); }
Comments
Post a Comment