當前位置: 首頁>>代碼示例>>Java>>正文


Java ContainerRequestContext.getSecurityContext方法代碼示例

本文整理匯總了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())));
    }
}
 
開發者ID:trellis-ldp,項目名稱:trellis,代碼行數:15,代碼來源:AgentAuthorizationFilter.java

示例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";
        }
    });
}
 
開發者ID:trellis-ldp,項目名稱:trellis-rosid,代碼行數:33,代碼來源:AnonymousAuthFilter.java

示例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());
    }
}
 
開發者ID:Crunchy-Torch,項目名稱:coddy,代碼行數:18,代碼來源:TokenResponseFilter.java

示例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());
}
 
開發者ID:mapr-demos,項目名稱:mapr-music,代碼行數:6,代碼來源:UserPrincipalContextFilter.java

示例5: provideValue

import javax.ws.rs.container.ContainerRequestContext; //導入方法依賴的package包/類
@Override
public SecurityContext provideValue(Parameter parameter, ContainerRequestContext requestContext, ObjectMapper objectMapper) {
	return requestContext.getSecurityContext();
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:5,代碼來源:SecurityContextProvider.java


注:本文中的javax.ws.rs.container.ContainerRequestContext.getSecurityContext方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。