本文整理汇总了Java中javax.ws.rs.container.ContainerRequestContext.getSecurityContext方法的典型用法代码示例。如果您正苦于以下问题:Java ContainerRequestContext.getSecurityContext方法的具体用法?Java ContainerRequestContext.getSecurityContext怎么用?Java ContainerRequestContext.getSecurityContext使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.ws.rs.container.ContainerRequestContext
的用法示例。
在下文中一共展示了ContainerRequestContext.getSecurityContext方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(final ContainerRequestContext ctx) throws IOException {
final SecurityContext sec = ctx.getSecurityContext();
LOGGER.debug("Checking security context: {}", sec.getUserPrincipal());
if (isNull(sec.getUserPrincipal())) {
ctx.setProperty(SESSION_PROPERTY, new HttpSession());
} else if (adminUsers.contains(sec.getUserPrincipal().getName())) {
ctx.setProperty(SESSION_PROPERTY, new HttpSession(AdministratorAgent));
} else if (sec.getUserPrincipal().getName().isEmpty()) {
ctx.setProperty(SESSION_PROPERTY, new HttpSession());
} else {
ctx.setProperty(SESSION_PROPERTY, new HttpSession(agentService.asAgent(sec.getUserPrincipal().getName())));
}
}
示例2: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(final ContainerRequestContext ctx) throws IOException {
if (nonNull(ctx.getHeaders().getFirst(HttpHeaders.AUTHORIZATION))) {
throw new WebApplicationException(unauthorizedHandler.buildResponse(prefix, realm));
}
final SecurityContext securityContext = ctx.getSecurityContext();
final boolean secure = securityContext != null && securityContext.isSecure();
ctx.setSecurityContext(new SecurityContext() {
@Override
public Principal getUserPrincipal() {
return new PrincipalImpl(Trellis.AnonymousAgent.getIRIString());
}
@Override
public boolean isUserInRole(final String role) {
return false;
}
@Override
public boolean isSecure() {
return secure;
}
@Override
public String getAuthenticationScheme() {
return "NONE";
}
});
}
示例3: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
/**
* Filter method called after a response has been provided for a request.
* This method will refresh the session of the current token and put in the header with the key Authorization
*
* @param requestContext request context.
* @param responseContext response context.
* @throws IOException if an I/O exception occurs.
*/
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext) throws IOException {
if (requestContext.getSecurityContext() != null && requestContext.getSecurityContext().getUserPrincipal() != null) {
responseContext.getHeaders().add(HttpHeaders.AUTHORIZATION,
this.jwtService.generateToken((JWTPrincipal) requestContext.getSecurityContext().getUserPrincipal()).getToken());
}
}
示例4: filter
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext context) throws IOException {
SecurityContext securityContext = context.getSecurityContext();
ResteasyProviderFactory.pushContext(Principal.class, securityContext.getUserPrincipal());
}
示例5: provideValue
import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public SecurityContext provideValue(Parameter parameter, ContainerRequestContext requestContext, ObjectMapper objectMapper) {
return requestContext.getSecurityContext();
}