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


Java ContainerRequestContext.getHeaderString方法代码示例

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


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

示例1: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext, ContainerResponseContext responseContext)
        throws IOException {
    String origin = requestContext.getHeaderString(ORIGIN);
    if (origin == null || requestContext.getMethod().equalsIgnoreCase("OPTIONS")
            || requestContext.getProperty("cors.failure") != null) {
        // don't do anything if origin is null, its an OPTIONS request, or cors.failure is set
        return;
    }
    responseContext.getHeaders().putSingle(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
    if (allowCredentials)
        responseContext.getHeaders().putSingle(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");

    if (exposedHeaders != null) {
        responseContext.getHeaders().putSingle(ACCESS_CONTROL_EXPOSE_HEADERS, exposedHeaders);
    }
}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:18,代码来源:CorsFilter.java

示例2: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
public void filter(ContainerRequestContext requestContext) throws IOException {
    HttpServletRequest request = ResteasyProviderFactory.getContextData(HttpServletRequest.class);
    RpcContext.getContext().setRequest(request);

    // this only works for servlet containers
    if (request != null && RpcContext.getContext().getRemoteAddress() == null) {
        RpcContext.getContext().setRemoteAddress(request.getRemoteAddr(), request.getRemotePort());
    }

    RpcContext.getContext().setResponse(ResteasyProviderFactory.getContextData(HttpServletResponse.class));

    String headers = requestContext.getHeaderString(DUBBO_ATTACHMENT_HEADER);
    if (headers != null) {
        for (String header : headers.split(",")) {
            int index = header.indexOf("=");
            if (index > 0) {
                String key = header.substring(0, index);
                String value = header.substring(index + 1);
                if (!StringUtils.isEmpty(key)) {
                    RpcContext.getContext().setAttachment(key.trim(), value.trim());
                }
            }
        }
    }
}
 
开发者ID:yunhaibin,项目名称:dubbox-hystrix,代码行数:26,代码来源:RpcContextFilter.java

示例3: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {

    String authorizationHeader = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
    log.info("authorizationHeader : " + authorizationHeader);

    // Check if the HTTP Authorization header is present and formatted correctly
    if (authorizationHeader == null || !authorizationHeader.startsWith("token ")) {
        log.error("invalid authorizationHeader : " + authorizationHeader);
        throw new NotAuthorizedException("Authorization header must be provided");
    }

    // Extract the token from the HTTP Authorization header
    String token = authorizationHeader.substring("Bearer".length()).trim();

    try {
        // Validate the token
        Key key = keyGenerator.generateKey();
        Jwts.parser().setSigningKey(key).parseClaimsJws(token);
        log.info("valid token : " + token);
    } catch (Exception ex) {
        log.error("invalid token : " + token);
        log.error("Exception occurred while validate the token : " + ex);
        requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
    }
}
 
开发者ID:sundarcse1216,项目名称:rest-api,代码行数:27,代码来源:JWTTokenNeededFilter.java

示例4: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    String usertokenId = requestContext.getHeaderString(Constants.USERTOKENID_HEADER);

    if (Strings.isNullOrEmpty(usertokenId)) {
        return;
    }

    UserToken userToken;
    try {
        userToken = tokenServiceClient.getUserTokenById(usertokenId);
    } catch (TokenServiceClientException e) {
        throw new NotAuthorizedException("UsertokenId: '" + usertokenId + "' not valid", e);
    }

    UibBrukerPrincipal brukerPrincipal = UibBrukerPrincipal.ofUserToken(userToken);
    ImmutableSet<String> tilganger = extractRolesAllowed(userToken, brukerPrincipal.uibBruker);

    requestContext.setSecurityContext(new AutentiseringsContext(brukerPrincipal, tilganger));

    if (authenticatedHandler != null) {
        authenticatedHandler.handle(requestContext);
    }
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:25,代码来源:UserTokenFilter.java

示例5: allowCors

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
/**
 * Adds the HTTP head "Access-Control-Allow-Origin: *" to enable
 * all cross domain requests.
 */
private static void allowCors(final ContainerRequestContext request, final ContainerResponseContext response)  {
    final String origin = request.getHeaderString("Origin");
    if (origin == null) {
        return;
    }

    response.getHeaders().add("Access-Control-Allow-Origin", "*");
    response.getHeaders().add("Access-Control-Allow-Credentials", "true");
    response.getHeaders().add("Access-Control-Allow-Methods", "GET, HEAD, OPTIONS, PATCH, POST, PUT, DELETE");

    final String headers = request.getHeaderString("Access-Control-Request-Headers");
    if (headers != null) {
        response.getHeaders().add("Access-Control-Allow-Headers", UrlUtils.urlDecode(headers));
    }
}
 
开发者ID:minijax,项目名称:minijax,代码行数:20,代码来源:MinijaxCorsFilter.java

示例6: checkPermissions

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
private void checkPermissions(ContainerRequestContext requestContext, List<Role> allowedRoles) throws Exception {
    // Check if the user contains one of the allowed roles
    // Throw an Exception if the user has not permission to execute the method
    if(allowedRoles.isEmpty())
        return;
    String authorizationHeader
            = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);
    String token = authorizationHeader
            .substring(AUTHENTICATION_SCHEME.length()).trim();
    List<String> roles = new ArrayList();
    if (!JWT.decode(token).getClaim("gty").isNull() && JWT.decode(token).getClaim("gty").asString().equals("client-credentials")) {
        roles.add("service");
    } else {
        roles = JWT.decode(token).getClaim("roles").asList(String.class);
    }
    for(String role: roles) {
        if(allowedRoles.contains(Role.valueOf(role)))
            return;
    }
    throw new WebApplicationException(
                Response.status(Response.Status.FORBIDDEN).build());
}
 
开发者ID:ISIS2503,项目名称:ThermalComfortBack,代码行数:23,代码来源:AuthorizationFilter.java

示例7: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    if (alwaysAccept(requestContext)) {
        return;
    }

    String apptokenid = requestContext.getHeaderString(APPTOKENID_HEADER);
    if (apptokenid == null || apptokenid.trim().isEmpty()) {
        handleErrorNoAppToken(requestContext);
    } else {
        ApplicationToken token = tokenServiceClient.getApptokenById(apptokenid);
        TokenCheckResult result = applicationTokenAccessValidator.checkApplicationToken(token);
        if (result != TokenCheckResult.AUTHORIZED) {
            handleErrorUnauthorized(requestContext, apptokenid, result);
        } else if (! isAllowedToCallEndpoint(token)) {
            handleErrorUnauthorizedForEndpoint(requestContext, apptokenid, result);
        }
    }
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:20,代码来源:ApplicationTokenFilter.java

示例8: preflight

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
protected void preflight(String origin, ContainerRequestContext requestContext) throws IOException {
    checkOrigin(requestContext, origin);

    Response.ResponseBuilder builder = Response.ok();
    builder.header(ACCESS_CONTROL_ALLOW_ORIGIN, origin);
    if (allowCredentials)
        builder.header(ACCESS_CONTROL_ALLOW_CREDENTIALS, "true");
    String requestMethods = requestContext.getHeaderString(ACCESS_CONTROL_REQUEST_METHOD);
    if (requestMethods != null) {
        if (allowedMethods != null) {
            requestMethods = this.allowedMethods;
        }
        builder.header(ACCESS_CONTROL_ALLOW_METHODS, requestMethods);
    }
    String allowHeaders = requestContext.getHeaderString(ACCESS_CONTROL_REQUEST_HEADERS);
    if (allowHeaders != null) {
        if (allowedHeaders != null) {
            allowHeaders = this.allowedHeaders;
        }
        builder.header(ACCESS_CONTROL_ALLOW_HEADERS, allowHeaders);
    }
    if (corsMaxAge > -1) {
        builder.header(ACCESS_CONTROL_MAX_AGE, corsMaxAge);
    }
    requestContext.abortWith(builder.build());

}
 
开发者ID:fabric8-launcher,项目名称:launcher-backend,代码行数:28,代码来源:CorsFilter.java

示例9: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {

  if (requestContext.getUriInfo().getRequestUri().getPath().endsWith("swagger.json")) {
    return;
  }

  String auth = requestContext.getHeaderString(HttpHeaders.AUTHORIZATION);

  if (auth == null || auth.isEmpty() || !auth.startsWith("Basic")) {
    throw notAuthorizedException;
  }

  auth = auth.replace(AUTHORIZATION_TYPE, "");

  String[] decodedUsernameAndPassword = decode(auth);

  if (decodedUsernameAndPassword.length < 2) {
    throw notAuthorizedException;
  }

  String username = decodedUsernameAndPassword[0];
  String password = decodedUsernameAndPassword[1];

  if (!checkUsernameAndPassword(username, password)) {
    throw notAuthorizedException;
  }
}
 
开发者ID:durimkryeziu,项目名称:jersey-2.x-webapp-for-servlet-container,代码行数:29,代码来源:AuthFilter.java

示例10: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
  String correlationId = requestContext.getHeaderString(headerName);
  if (correlationId == null) {
    correlationId = UUID.randomUUID().toString();
  }
  requestContext.setProperty(mdcName, correlationId);
  MDC.put(mdcName, correlationId);
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:10,代码来源:CorrelationIdFilter.java

示例11: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext request, ContainerResponseContext containerResponseContext)
		throws IOException {
	String origin = request.getHeaderString(ORIGIN_HEADER_FIELD);

	if (origin != null) {
		if (originFilter.isOriginAllowed(origin)) {
			containerResponseContext.getHeaders().add(ACCESS_CONTROL_ALLOW_ORIGIN_HEADER_FIELD, origin);
		}
	}
}
 
开发者ID:Mercateo,项目名称:rest-jersey-utils,代码行数:12,代码来源:AccessControlAllowOriginResponseFilter.java

示例12: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext request) throws IOException {
	String origin = request.getHeaderString(ORIGIN_HEADER_FIELD);

	if (origin != null) {
		if (!originFilter.isOriginAllowed(origin)) {
			throw new BadRequestException("The origin ist not set accordingly");
		}
	}

}
 
开发者ID:Mercateo,项目名称:rest-jersey-utils,代码行数:12,代码来源:AccessControlAllowOriginRequestFilter.java

示例13: authenticate

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
/**
 * Checks if the request contains the username password combination from the given map of username and password.
 *
 */
public void authenticate(ContainerRequestContext request, Map<String, String> usernamePasswordMap) {

    String authHeader = request.getHeaderString("Authorization");
    WebApplicationException wae = new WebApplicationException(Response.status(Response.Status.UNAUTHORIZED)
            .header("WWW-Authenticate", "Basic").entity("not authorized").build());

    String requestUri = request.getUriInfo()!=null?request.getUriInfo().getBaseUri().toString():"";
    if (authHeader == null) {
        log.warn("Authentication of " + requestUri + " failed as auth header was null");
        throw wae;
    } else {
        String[] tokens = authHeader.trim().split("\\s+");

        if (tokens.length != 2 || !tokens[0].equalsIgnoreCase("BASIC")) {
            log.warn("Authentication of " + requestUri + " failed as auth header does not have the right tokens");
            throw wae;
        }

        // valid auth header format, now need to authenticate the right user
        byte[] decodedBytes = Base64.getDecoder().decode(tokens[1]);
        String credString = new String(decodedBytes);

        String[] credentials = credString.split(":");

        if (credentials.length != 2) {
            log.warn("Authentication of " + this.logging.removeCRLF(requestUri) + " failed - invalid credentials format");
            throw wae;
        }

        String loginName = credentials[0];
        String password = credentials[1];

        if (!validateUserAndPassword(loginName, password, usernamePasswordMap)) {
            log.warn("Authentication of " + this.logging.removeCRLF(requestUri) + " failed - user password mismatch");
            throw wae;
        }
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:43,代码来源:AuthUtil.java

示例14: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
    if (allwaysAccept(requestContext)) {
        return;
    }
    String appNameHeader = requestContext.getHeaderString(Constants.CLIENT_APPNAME_HEADER);
    if (Strings.isNullOrEmpty(appNameHeader)) {
        throw new BadRequestException("Header specifying client name required: " + Constants.CLIENT_APPNAME_HEADER);
    }
}
 
开发者ID:code-obos,项目名称:servicebuilder,代码行数:11,代码来源:AppNameFilter.java

示例15: filter

import javax.ws.rs.container.ContainerRequestContext; //导入方法依赖的package包/类
@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
	String userIdStr = requestContext.getHeaderString("userId");
	String securityToken = requestContext.getHeaderString("securityToken");
	if (userIdStr == null || securityToken == null || userIdStr.isEmpty() || securityToken.isEmpty()) {
		throw new NotAuthorizedException("Authorization header must be provided");
	}
	Long userId = Long.valueOf(userIdStr);
	try {
		validateToken(userId, securityToken);
	} catch (Exception e) {
		requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
	}
}
 
开发者ID:SoapboxRaceWorld,项目名称:soapbox-race-core,代码行数:15,代码来源:AuthenticationFilter.java


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