我试图在Jersey上使用嵌入式JettyHttpContainer。我使用BasicAuthenticator,一切似乎都在起作用:
@GET
@Produces(MediaType.APPLICATION_JSON)
@PermitAll
public Response getData(@Context SecurityContext securityContext) {
if (securityContext.isUserInRole(Roles.ADMIN)) {
do something...
问题是,securityContext.isUserInRole(Request)
始终是错误的并且正在查看来源,这显然是原因:
private SecurityContext getSecurityContext(final Request request) {
return new SecurityContext() {
@Override
public boolean isUserInRole(String role) {
return false;
}
有没有人知道如何正确使用JettyHttpContainer和Jersey SecurityContext?