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


Java HttpServerRequest.getHeader方法代码示例

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


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

示例1: refuseNonLanAccess

import io.vertx.core.http.HttpServerRequest; //导入方法依赖的package包/类
/**
 * 判断当前请求是否允许,如果不允许,则将状态码设为403并结束响应
 * 
 * @return true:禁止访问 false=允许访问
 * @author Leibniz.Hu
 */
protected boolean refuseNonLanAccess(RoutingContext rc) {
    HttpServerRequest req = rc.request();
    HttpServerResponse resp = rc.response();
    String realIp = req.getHeader("X-Real-IP");
    String xforward = req.getHeader("X-Forwarded-For");
    //禁止外网访问
    if (realIp != null && !isLanIP(realIp)) {
        log.warn("检测到非法访问,来自X-Real-IP={}", realIp);
        resp.setStatusCode(403).end();
        return true;
    }
    if (xforward != null && !isLanIP(xforward)) {
        log.warn("检测到非法访问,来自X-Forwarded-For={}", xforward);
        resp.setStatusCode(403).end();
        return true;
    }
    return false;
}
 
开发者ID:Leibnizhu,项目名称:AlipayWechatPlatform,代码行数:25,代码来源:LanAccessSubRouter.java

示例2: authUser

import io.vertx.core.http.HttpServerRequest; //导入方法依赖的package包/类
public static String authUser(HttpServerRequest request, HttpServerResponse response, Config config) {
    String token = request.getHeader("token");
    if (token == null) {
        response.setStatusCode(403);
        response.end();
        return null;
    }

    String userId = ServerUtils.getIdFromToken(config, token);

    if (userId == null) {
        response.setStatusCode(403);
        response.end();
        return null;
    }

    return userId;
}
 
开发者ID:Samoxive,项目名称:SafetyJim,代码行数:19,代码来源:ServerUtils.java

示例3: provide

import io.vertx.core.http.HttpServerRequest; //导入方法依赖的package包/类
@Override
public User provide(HttpServerRequest request) {
	String token = request.getHeader("X-Token");

	// set user ...
	if (token != null) {
		return users.getUser(token);
	}

	return null;
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:12,代码来源:UserHandler.java

示例4: provide

import io.vertx.core.http.HttpServerRequest; //导入方法依赖的package包/类
@Override
public Token provide(HttpServerRequest request) {
	String token = request.getHeader("X-Token");
	if (token != null) {
		return new Token(token);
	}

	return null;
}
 
开发者ID:zandero,项目名称:rest.vertx,代码行数:10,代码来源:TokenProvider.java

示例5: getAccessToken

import io.vertx.core.http.HttpServerRequest; //导入方法依赖的package包/类
/**
 * Obtains the access token from the request. It is expected to be the
 * Authorization with a bearer tag. The authentication code is expected to be a
 * given pattern.
 *
 * @param contextRequest
 *            request
 * @return access token
 */
private String getAccessToken(final HttpServerRequest contextRequest) {

    final String authorizationHeader = contextRequest.getHeader(AUTHORIZATION);
    if (authorizationHeader == null) {
        return null;
    }
    final Matcher m = Pattern.compile(BEARER_TOKEN_PATTERN).matcher(authorizationHeader);
    if (!m.matches()) {
        return null;
    } else {
        return m.group(1);
    }
}
 
开发者ID:trajano,项目名称:app-ms,代码行数:23,代码来源:ProtectedHandler.java

示例6: handle

import io.vertx.core.http.HttpServerRequest; //导入方法依赖的package包/类
@Override
public void handle(final RoutingContext context) {

    final HttpServerRequest contextRequest = context.request();
    final HttpServerResponse contextResponse = context.response();

    final String requestID = requestIDProvider.newRequestID(context);

    final String token = contextRequest.getFormAttribute("token");
    if (token == null || !TOKEN_PATTERN.matcher(token).matches()) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(400)
            .setStatusMessage(BAD_REQUEST)
            .end(Errors.invalidRequest("Missing or invalid token " + token).toBuffer());
        return;
    }

    final String authorization = contextRequest.getHeader(HttpHeaders.AUTHORIZATION);
    if (authorization == null) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(401)
            .setStatusMessage("Unauthorized Client")
            .putHeader("WWW-Authenticate", "Basic")
            .end(Errors.unauthorizedClient("Missing authorization").toBuffer());
        return;
    }

    // Trust the authorization endpoint and use the body handler
    final HttpClientRequest revocationRequest = httpClient.post(Conversions.toRequestOptions(authorizationEndpoint.resolve("/revoke")),
        authorizationResponse -> authorizationResponse.bodyHandler(contextResponse
            .setChunked(false)
            .setStatusCode(authorizationResponse.statusCode())
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .putHeader(RequestIDProvider.REQUEST_ID, requestID)
            .setStatusMessage(authorizationResponse.statusMessage())::end));
    revocationRequest
        .putHeader(HttpHeaders.AUTHORIZATION, authorization)
        .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_FORM_URLENCODED)
        .putHeader(HttpHeaders.ACCEPT, MediaTypes.APPLICATION_JSON)
        .putHeader(REQUEST_ID, requestID)
        .putHeader(DATE, RFC_1123_DATE_TIME.format(now(UTC)))
        .end("token_type_hint=refresh_token&token=" + token);

}
 
开发者ID:trajano,项目名称:app-ms,代码行数:49,代码来源:RevocationHandler.java

示例7: handle

import io.vertx.core.http.HttpServerRequest; //导入方法依赖的package包/类
@Override
public void handle(final RoutingContext context) {

    final HttpServerRequest contextRequest = context.request();
    final HttpServerResponse contextResponse = context.response();

    final String requestID = requestIDProvider.newRequestID(context);

    final String grantType = contextRequest.getFormAttribute("grant_type");
    if (grantType == null) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(400)
            .setStatusMessage(BAD_REQUEST)
            .end(Errors.invalidGrant("Missing grant type").toBuffer());
        return;
    }

    final String authorization = contextRequest.getHeader(HttpHeaders.AUTHORIZATION);
    if (authorization == null) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(401)
            .setStatusMessage("Unauthorized Client")
            .putHeader("WWW-Authenticate", "Basic")
            .end(Errors.unauthorizedClient("Missing authorization").toBuffer());
        return;
    }

    if (!"refresh_token".equals(grantType)) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(400)
            .setStatusMessage(BAD_REQUEST)
            .end(Errors.build("unsupported_grant_type", "Unsupported grant type").toBuffer());
        return;
    }
    final String refreshToken = contextRequest.getFormAttribute("refresh_token");
    if (refreshToken == null || !TOKEN_PATTERN.matcher(refreshToken).matches()) {
        contextResponse
            .setChunked(false)
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .setStatusCode(400)
            .setStatusMessage(BAD_REQUEST)
            .end(Errors.invalidGrant("Invalid grant").toBuffer());
        return;
    }

    // Trust the authorization endpoint and use the body handler
    final HttpClientRequest authorizationRequest = httpClient.post(Conversions.toRequestOptions(authorizationEndpoint.resolve("/token")),
        authorizationResponse -> authorizationResponse.bodyHandler(contextResponse
            .setChunked(false)
            .setStatusCode(authorizationResponse.statusCode())
            .putHeader(HttpHeaders.CONTENT_TYPE, MediaTypes.APPLICATION_JSON)
            .putHeader(RequestIDProvider.REQUEST_ID, requestID)
            .setStatusMessage(authorizationResponse.statusMessage())::end));
    authorizationRequest
        .putHeader(HttpHeaders.AUTHORIZATION, authorization)
        .putHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded")
        .putHeader(HttpHeaders.ACCEPT, "application/json")
        .putHeader(REQUEST_ID, requestID)
        .putHeader(DATE, RFC_1123_DATE_TIME.format(now(UTC)))
        .end("grant_type=refresh_token&refresh_token=" + refreshToken);

}
 
开发者ID:trajano,项目名称:app-ms,代码行数:69,代码来源:RefreshHandler.java


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