本文整理了Java中javax.ws.rs.container.ContainerRequestContext.getSecurityContext()
方法的一些代码示例,展示了ContainerRequestContext.getSecurityContext()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ContainerRequestContext.getSecurityContext()
方法的具体详情如下:
包路径:javax.ws.rs.container.ContainerRequestContext
类名称:ContainerRequestContext
方法名:getSecurityContext
[英]Get the injectable security context information for the current request. The SecurityContext#getUserPrincipal() must return nullif the current request has not been authenticated.
[中]获取当前请求的可注入安全上下文信息。如果当前请求尚未通过身份验证,则SecurityContext#getUserPrincipal()必须返回null。
代码示例来源:origin: apache/shiro
public ShiroSecurityContext(ContainerRequestContext containerRequestContext) {
this.containerRequestContext = containerRequestContext;
this.originalSecurityContext = containerRequestContext.getSecurityContext();
}
代码示例来源:origin: dropwizard/dropwizard
@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
WebApplicationException firstException = null;
for (@SuppressWarnings("rawtypes") AuthFilter authFilter : handlers) {
final SecurityContext securityContext = containerRequestContext.getSecurityContext();
try {
authFilter.filter(containerRequestContext);
if (securityContext != containerRequestContext.getSecurityContext()) {
return;
}
} catch (WebApplicationException e) {
if (firstException == null) {
firstException = e;
}
}
}
throw firstException;
}
}
代码示例来源:origin: jersey/jersey
@Override
public int hashCode() {
checkState();
return 7 * requestContext.getSecurityContext().hashCode();
}
代码示例来源:origin: jersey/jersey
@Override
public boolean equals(Object that) {
checkState();
return that instanceof SecurityContext && that.equals(requestContext.getSecurityContext());
}
代码示例来源:origin: jersey/jersey
@Override
public int hashCode() {
checkState();
return 7 * requestContext.getSecurityContext().hashCode();
}
代码示例来源:origin: jersey/jersey
@Override
public boolean equals(Object that) {
checkState();
return that instanceof SecurityContext && that.equals(requestContext.getSecurityContext());
}
代码示例来源:origin: jersey/jersey
private static boolean isAuthenticated(final ContainerRequestContext requestContext) {
return requestContext.getSecurityContext().getUserPrincipal() != null;
}
}
代码示例来源:origin: jersey/jersey
private static boolean isAuthenticated(final ContainerRequestContext requestContext) {
return requestContext.getSecurityContext().getUserPrincipal() != null;
}
}
代码示例来源:origin: apache/shiro
@Override
public boolean isSecure() {
return containerRequestContext.getSecurityContext().isSecure();
}
代码示例来源:origin: Graylog2/graylog2-server
@Nullable
public static String getUserNameFromRequest(ContainerRequestContext requestContext) {
final SecurityContext securityContext = requestContext.getSecurityContext();
if (!(securityContext instanceof ShiroSecurityContext)) {
return null;
}
final ShiroSecurityContext shiroSecurityContext = (ShiroSecurityContext) securityContext;
final Principal userPrincipal = shiroSecurityContext.getUserPrincipal();
if (!(userPrincipal instanceof ShiroPrincipal)) {
return null;
}
final ShiroPrincipal shiroPrincipal = (ShiroPrincipal) userPrincipal;
return shiroPrincipal.getName();
}
代码示例来源:origin: jersey/jersey
@Override
public Principal getUserPrincipal() {
checkState();
return requestContext.getSecurityContext().getUserPrincipal();
}
代码示例来源:origin: jersey/jersey
@Override
public Principal getUserPrincipal() {
checkState();
return requestContext.getSecurityContext().getUserPrincipal();
}
代码示例来源:origin: jersey/jersey
@Override
public boolean isSecure() {
checkState();
return requestContext.getSecurityContext().isSecure();
}
代码示例来源:origin: jersey/jersey
@Override
public boolean isUserInRole(String role) {
checkState();
return requestContext.getSecurityContext().isUserInRole(role);
}
代码示例来源:origin: jersey/jersey
@Override
public boolean isSecure() {
checkState();
return requestContext.getSecurityContext().isSecure();
}
代码示例来源:origin: jersey/jersey
@Override
public String getAuthenticationScheme() {
checkState();
return requestContext.getSecurityContext().getAuthenticationScheme();
}
代码示例来源:origin: jersey/jersey
@Override
public boolean isUserInRole(String role) {
checkState();
return requestContext.getSecurityContext().isUserInRole(role);
}
代码示例来源:origin: jersey/jersey
@Override
public String getAuthenticationScheme() {
checkState();
return requestContext.getSecurityContext().getAuthenticationScheme();
}
代码示例来源:origin: jersey/jersey
@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
if (!denyAll) {
if (rolesAllowed.length > 0 && !isAuthenticated(requestContext)) {
throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED());
}
for (final String role : rolesAllowed) {
if (requestContext.getSecurityContext().isUserInRole(role)) {
return;
}
}
}
throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED());
}
代码示例来源:origin: jersey/jersey
@Override
public void filter(final ContainerRequestContext requestContext) throws IOException {
if (!denyAll) {
if (rolesAllowed.length > 0 && !isAuthenticated(requestContext)) {
throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED());
}
for (final String role : rolesAllowed) {
if (requestContext.getSecurityContext().isUserInRole(role)) {
return;
}
}
}
throw new ForbiddenException(LocalizationMessages.USER_NOT_AUTHORIZED());
}
内容来源于网络,如有侵权,请联系作者删除!