當前位置: 首頁>>代碼示例>>Java>>正文


Java SecurityContext.isUserInRole方法代碼示例

本文整理匯總了Java中javax.ws.rs.core.SecurityContext.isUserInRole方法的典型用法代碼示例。如果您正苦於以下問題:Java SecurityContext.isUserInRole方法的具體用法?Java SecurityContext.isUserInRole怎麽用?Java SecurityContext.isUserInRole使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在javax.ws.rs.core.SecurityContext的用法示例。


在下文中一共展示了SecurityContext.isUserInRole方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: checkIsUserInRole

import javax.ws.rs.core.SecurityContext; //導入方法依賴的package包/類
/**
 * This endpoint requires a Tester role, and also validates that the caller has the role Echoer by calling
 * {@linkplain SecurityContext#isUserInRole(String)}.
 *
 * @return principal name or FORBIDDEN error
 */
@GET
@Path("/checkIsUserInRole")
@RolesAllowed("Tester")
public Response checkIsUserInRole(@Context SecurityContext sec) {
    Principal user = sec.getUserPrincipal();
    Response response;
    if(!sec.isUserInRole("Echoer")) {
        response = Response.status(new Response.StatusType() {
            @Override
            public int getStatusCode() {
                return Response.Status.FORBIDDEN.getStatusCode();
            }

            @Override
            public Response.Status.Family getFamily() {
                return Response.Status.FORBIDDEN.getFamily();
            }

            @Override
            public String getReasonPhrase() {
                return "SecurityContext.isUserInRole(Echoer) was false";
            }
        }).build();
    }
    else {
        response = Response.ok(user.getName(), MediaType.TEXT_PLAIN).build();
    }
    return response;
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:36,代碼來源:RolesEndpoint.java

示例2: needsGroup1Mapping

import javax.ws.rs.core.SecurityContext; //導入方法依賴的package包/類
/**
 * This endpoint requires a role that is mapped to the group1 role
 * @return principal name
 */
@GET
@Path("/needsGroup1Mapping")
@RolesAllowed("Group1MappedRole")
public String needsGroup1Mapping(@Context SecurityContext sec) {
    Principal user = sec.getUserPrincipal();
    sec.isUserInRole("group1");
    return user.getName();
}
 
開發者ID:eclipse,項目名稱:microprofile-jwt-auth,代碼行數:13,代碼來源:RolesEndpoint.java

示例3: checkSecurity

import javax.ws.rs.core.SecurityContext; //導入方法依賴的package包/類
private void checkSecurity(final MinijaxRequestContext context) {
    final Annotation a = context.getResourceMethod().getSecurityAnnotation();
    if (a == null) {
        return;
    }

    final Class<?> c = a.annotationType();
    if (c == PermitAll.class) {
        return;
    }

    if (c == DenyAll.class) {
        throw new ForbiddenException();
    }

    if (c == RolesAllowed.class) {
        final SecurityContext security = context.getSecurityContext();
        if (security == null || security.getUserPrincipal() == null) {
            throw new NotAuthorizedException(Response.status(Status.UNAUTHORIZED).build());
        }

        boolean found = false;
        for (final String role : ((RolesAllowed) a).value()) {
            if (security.isUserInRole(role)) {
                found = true;
                break;
            }
        }

        if (!found) {
            throw new ForbiddenException();
        }
    }
}
 
開發者ID:minijax,項目名稱:minijax,代碼行數:35,代碼來源:MinijaxApplication.java


注:本文中的javax.ws.rs.core.SecurityContext.isUserInRole方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。