当前位置: 首页>>代码示例>>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;未经允许,请勿转载。