[英]JAAS and web service authorization : get logged user
我有一個通過 JAAS 登錄的 JSF 應用程序。 它工作正常。
現在,我的頁面調用了 REST web 服務。 我需要知道是誰提出了請求。
在請求的 header 我有:
Cookie = JSESSIONID=XBHZuYnzgkGyQSR8kBLNSks_s7nuXAMli7Gp-9Mn.dlicitra; _ga=GA1.1.1590792307.1560863707
web 服務在無狀態 EJB 中實現。 方法是:
@Path(value = "myservice/{id}")
@GET
@Produces(value = "application/json")
public List<Records> getServices(
@HeaderParam(value = "Cookie") String cookie,
@PathParam(value = "id") Long id){
return ... ;
}
如何從cookie字符串中獲取登錄用戶?
As explained in the comment, instead of mangling with parsing or decoding the cookie's SessionId, I'd go with the Java EE's security API built-in solution of injecting the SecurityContext
into the EJB, and getting the userPrincipal from it:
@Context
private SecurityContext securityContext;
在你的方法中:
Principal principal = securityContext.getUserPrincipal();
也可以看看:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.