当前位置: 首页>>代码示例>>Java>>正文


Java SecurityContext.getUserPrincipal方法代码示例

本文整理汇总了Java中javax.ws.rs.core.SecurityContext.getUserPrincipal方法的典型用法代码示例。如果您正苦于以下问题:Java SecurityContext.getUserPrincipal方法的具体用法?Java SecurityContext.getUserPrincipal怎么用?Java SecurityContext.getUserPrincipal使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.ws.rs.core.SecurityContext的用法示例。


在下文中一共展示了SecurityContext.getUserPrincipal方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: echoInput

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@GET
@Path("/echo")
@RolesAllowed("Echoer")
public String echoInput(@Context SecurityContext sec, @QueryParam("input") String input) {
    Principal user = sec.getUserPrincipal();
    return input + ", user="+user.getName();
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:8,代码来源:RolesEndpoint.java

示例2: echoNeedsToken2Role

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@GET
@Path("/echoNeedsToken2Role")
@RolesAllowed("Token2Role")
public String echoNeedsToken2Role(@Context SecurityContext sec, @QueryParam("input") String input) {
    Principal user = sec.getUserPrincipal();
    return input + ", user="+user.getName();
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:8,代码来源:RolesEndpoint.java

示例3: 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

示例4: issue

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@GET
@Path("/issue")
@Produces(MediaType.TEXT_PLAIN)
public Response issue(@Context SecurityContext securityContext) {

	// get Authentication
	Authentication authc = (Authentication) securityContext.getUserPrincipal();

	// configuration
	JwtConfiguration configuration = ResourceUtils.lookupResource(getClass(), JwtConfiguration.class, providers)
			.orElseThrow(() -> new InternalServerErrorException("JWT configuration not available"));

	// build JWT
	String jwt = JwtTokenBuilder.buildJwtToken(configuration, authc, UUID.randomUUID().toString());
	// ok
	return Response.ok(jwt, MediaType.TEXT_PLAIN).build();

}
 
开发者ID:holon-platform,项目名称:holon-examples,代码行数:19,代码来源:JwtIssuerEndpoint.java

示例5: echoInput2

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@GET
@Path("/echo2")
@RolesAllowed("NoSuchUser")
public String echoInput2(@Context SecurityContext sec, @QueryParam("input") String input) {
    Principal user = sec.getUserPrincipal();
    String name = user != null ? user.getName() : "<null>";
    return input + ", user="+name;
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:9,代码来源:RolesEndpoint.java

示例6: getPrincipalClass

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
/**
 * Validate that the  SecurityContext#getUserPrincipal is a JsonWebToken
 * @param sec
 * @return
 */
@GET
@Path("/getPrincipalClass")
@RolesAllowed("Tester")
public String getPrincipalClass(@Context SecurityContext sec) {
    Principal user = sec.getUserPrincipal();
    boolean isJsonWebToken = user instanceof JsonWebToken;
    return "isJsonWebToken:"+isJsonWebToken;
}
 
开发者ID:eclipse,项目名称:microprofile-jwt-auth,代码行数:14,代码来源:RolesEndpoint.java

示例7: 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

示例8: hello

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@ApiOperation(value = "Secure Hello")
@GET
@Produces(MediaType.APPLICATION_JSON)
public JsonObject hello(@QueryParam("name") final String name,
    @Context final SecurityContext securityContext) {

    final JsonObject json = new JsonObject();
    if (name != null) {
        json.add("name", new JsonPrimitive(name));
    }
    final JwtClaimsSetPrincipal userPrincipal = (JwtClaimsSetPrincipal) securityContext.getUserPrincipal();
    json.add("principal", new JsonPrimitive(userPrincipal.getName()));
    json.add("claims", jsonOps.toJsonElement(userPrincipal.getClaimsSet().toJson()));
    return json;
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:16,代码来源:SecureHelloResource.java

示例9: getAuthenticatedUser

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
protected String getAuthenticatedUser(SecurityContext securityContext) {
    String user = null;
    if (securityContext.getUserPrincipal() != null) {
        user = securityContext.getUserPrincipal().getName();
    } else {
        throw new WebApplicationException(Status.UNAUTHORIZED);
    }
    LOGGER.debug("Authenticated user is: " + user);
    return user;
}
 
开发者ID:SAP,项目名称:cf-mta-deploy-service,代码行数:11,代码来源:OperationsApiServiceImpl.java

示例10: info

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@PermitAll
@GET
@Path("name")
@Produces(MediaType.TEXT_PLAIN)
public String info(@Context SecurityContext securityContext) {
	Authentication authc = (Authentication) securityContext.getUserPrincipal();
	return authc.getName();
}
 
开发者ID:holon-platform,项目名称:holon-jaxrs,代码行数:9,代码来源:TestAuthzStd.java

示例11: 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

示例12: getAccountRoles

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@PermitAll
@GET
@Path("/roles")
@Produces(MediaType.TEXT_PLAIN)
public String getAccountRoles(@Context SecurityContext securityContext) {
	// get Authentication
	Authentication authc = (Authentication) securityContext.getUserPrincipal();
	// get roles
	return authc.getPermissions().stream().map(p -> p.getPermission().orElse(null))
			.collect(Collectors.joining(","));
}
 
开发者ID:holon-platform,项目名称:holon-examples,代码行数:12,代码来源:ProtectedEndpoint.java

示例13: secureForAll

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@GET
@Path("/forall")
public User secureForAll(@Context SecurityContext context) {
    return (User) context.getUserPrincipal();
}
 
开发者ID:maugern,项目名称:jersey-skeleton,代码行数:6,代码来源:SecureResource.java

示例14: secureByAnnotation

import javax.ws.rs.core.SecurityContext; //导入方法依赖的package包/类
@GET
@Path("/byannotation")
@RolesAllowed({"user"})
public User secureByAnnotation(@Context SecurityContext context) {
    return (User) context.getUserPrincipal();
}
 
开发者ID:maugern,项目名称:jersey-skeleton,代码行数:7,代码来源:SecureResource.java


注:本文中的javax.ws.rs.core.SecurityContext.getUserPrincipal方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。