我正在使用Jersey + Jetty + Dropwizard + Hibernate創建Web服務。在Jersey web服務中設置角色
比方說,我有這樣一個網絡資源:
@Path("/")
@PermitAll
public class Resource {
@RolesAllowed("user")
@GET
public String get() { return "GET"; }
@RolesAllowed("admin")
@POST
public String post(String content) { return content; }
@Path("sub")
public SubResource getSubResource() {
return new SubResource();
}
}
我知道你可以用HttpServletRequest.isUserInRole
檢查用戶的角色。
的問題是,我該如何分配開始與角色?澤西如何知道要爲isUserInRole
方法返回什麼,或知道如何過濾人們根據他們的角色沒有獲得特定資源?
我沒有web.xml
或webdefault.xml
,所以定義應該在其他地方完成。
你看的文檔爲[Dropwizard驗證(http://www.dropwizard.io/1.0.0/docs/manual/auth.html)?它支持Basic和OAuth。還有第三方[JWT的lib](https://github.com/ToastShaman/dropwizard-auth-jwt)。所有這些角色的東西都由框架處理。除非你有這些解決方案並且你沒有爲你工作,並且你想自己創建 –