java - Propagate user principal from REST to EJB layer -


i starting application uses rest api makes calls ejb layer on jboss wildfly (resteasy).

the rest services inside war calls ejb layer. know how achieve basic or custom form of authenthication on rest resteasy interceptor checks headers etc. described here: http://howtodoinjava.com/2013/06/26/jax-rs-resteasy-basic-authentication-and-authorization-tutorial/

the problem - check on rest facade. inside ejb layer don't know user authenticated against rest service.

to clear - when using rmi , remote ejb calls authentication, user name stored in session context:

@stateless public class loginservice { @resource private sessioncontext sessioncontext;    public string getcurrentuser() {     principal principal = sessioncontext.getcallerprincipal();     return principal.getname(); //i need username rest auth     //currently it's anonymous   } } 

is there way propagate username in standard way? e.g. putting custom principal sessioncontext?

you can use subject's doas method. see javadocs here.

when makings calls war ejb authenticated subject's doas method. way subject propagated context of ejb. (eg. @rolesallowed work fine) can config authentication in web.xml usual if want.

to subject in war, try subject usersubject=(subject)policycontext.getcontext("javax.security.auth.subject.container");


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -