Hi, Colm, I already tried to cast to LoginSecurityContext, but the ClassCast Exception will be thrown.
What I want to get is the authenticated "username", I think it should be return by mc.getSecurityContext().getUserPrincipal().getName(), but from my testing result, the role name will be return from mc.getSecurityContext().getUserPrincipal().getName(), but not the username. Maybe that's something wrong in the CXF jaxrs security impl? Thanks. Xilai -----Original Message----- From: Colm O hEigeartaigh [mailto:[email protected]] Sent: Tuesday, March 11, 2014 6:06 PM To: [email protected] Subject: Re: How to get Subject (user) from jaxrs context You can cast the mc.getSecurityContext() to a LoginSecurityContext (if this is applicable). This has a "getSubject()" method. Colm. On Tue, Mar 11, 2014 at 6:09 AM, XiLai Dai <[email protected]> wrote: > Hi, > > We have a REST service impl class and just want to get the > authentication user info from the impl of one operation, it looks like: > > public class FlowManagementServiceImpl implements FlowManagementService { > @Context > private org.apache.cxf.jaxrs.ext.MessageContext mc; > > @GET > @Path("/deploy/{flowName}/{flowVersion}") > @Produces("text/plain") > public Response deployFlow(@PathParam("flowName") String flowName, > @PathParam("flowVersion") String flowVersion) { > ...... > System.out.println("role: " + > mc.getSecurityContext().getUserPrincipal().getName()); > ...... > } > } > > Seems only the principlal name can be retrieved from MessageContext, > how to get the Subject (user) name from the operation? Thanks! > (CXF 2.7.10 used) > > Thanks. > Xilai Dai > -- Colm O hEigeartaigh Talend Community Coder http://coders.talend.com
