java - How to get logged user name/Principal in Spring MVC REST channel? -
i have spring mvc rest channel:
@controller @requestmapping("/rest") public class rest {
and have method:
@requestmapping(value = "/dosomething") public @responsebody dosomethingresultdto dosomething( @requestbody dosomethingrequestdto)
now need name of user logged in. method
httpservletrequest.getuserprincipal()
but how here? have annotations headers (@requestheader
), or cookies (@cookievalue
). how can principal
in method?
you can inject principal object controller handler method
@requestmapping(value = "/dosomething") public @responsebody dosomethingresultdto dosomething( @requestbody dosomethingrequestdto, principal principal)
Comments
Post a Comment