本文整理匯總了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();
}