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


Java RestRequest.header方法代碼示例

本文整理匯總了Java中org.elasticsearch.rest.RestRequest.header方法的典型用法代碼示例。如果您正苦於以下問題:Java RestRequest.header方法的具體用法?Java RestRequest.header怎麽用?Java RestRequest.header使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.rest.RestRequest的用法示例。


在下文中一共展示了RestRequest.header方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseVersion

import org.elasticsearch.rest.RestRequest; //導入方法依賴的package包/類
public static long parseVersion(RestRequest request) {
    if (request.hasParam("version")) {
        return request.paramAsLong("version", Versions.MATCH_ANY);
    }
    String ifMatch = request.header("If-Match");
    if (ifMatch != null) {
        return Long.parseLong(ifMatch);
    }
    return Versions.MATCH_ANY;
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:11,代碼來源:RestActions.java

示例2: LoginUserContext

import org.elasticsearch.rest.RestRequest; //導入方法依賴的package包/類
public LoginUserContext(RestRequest request, ClusterService clusterService) {
    authenticated = false;
    // get username and password
    String auth = request.header("Authorization");
    if (request.param(USERNAME_KEY) != null) {
        loginUsername = request.param(USERNAME_KEY);
        password = request.param(PASSWORD_KEY);
        if (request.hasParam(AUTHENTICATED_KEY)) {
            authenticated = Boolean.parseBoolean(request.param(AUTHENTICATED_KEY));
        }
    } else if ((auth != null) && (auth.length() > BASIC_LENGTH)) {
        auth = auth.substring(BASIC_LENGTH);
        String decodedAuth = new String(Base64.decodeBase64(auth));
        String[] nameAndPass = decodedAuth.split(":");
        if (nameAndPass.length > 0) {
            loginUsername = nameAndPass[0];
        }
        if (nameAndPass.length > 1) {
            password = nameAndPass[1];
        }
    }
    
    if (Strings.isNullOrEmpty(loginUsername)) {
        throw new NoPermissionException(RestStatus.UNAUTHORIZED.getStatus(), "could not parse username from http header or url");
    }
    
    MetaData metaData = clusterService.state().metaData();
    if (UserProperty.getUsernameWithoutTenantFromFullUsername(loginUsername).equalsIgnoreCase(UserProperty.ROOT_NAME)) {
        userProperty = metaData.getUserMetadata().getUserProperties().get(UserProperty.ROOT_NAME);
        UserProperty.Builder userBuilder = new UserProperty.Builder(userProperty);
        userBuilder.changeUsername(UserProperty.ROOT_NAME, UserProperty.getTenantIdFromLoginUserName(loginUsername, metaData.tenantMetadata()));
        userProperty = userBuilder.build();
    } else {
        userProperty = metaData.getUserMetadata().getUserPropertyFromLoginUser(loginUsername, metaData.tenantMetadata());
    }
    if (userProperty == null) {
        throw new NoPermissionException(RestStatus.UNAUTHORIZED.getStatus(), "could not find user " + loginUsername);
    }
    tenantId = userProperty.getTenantId();
    fullUsername = userProperty.getUsernameWithTenant();
    // get sourceAddrs and proxyAddrs
    InetSocketAddress addrs = (InetSocketAddress) request.getRemoteAddress();
    String forwardAddrsList = request.header("X-Forwarded-For");
    if (forwardAddrsList != null && forwardAddrsList.length() > 0) {
        proxyAddrs = addrs.getAddress().getHostAddress();
        sourceAddrs = forwardAddrsList.split(",")[0];
    } else {
        sourceAddrs = addrs.getAddress().getHostAddress();
    }
}
 
開發者ID:baidu,項目名稱:Elasticsearch,代碼行數:51,代碼來源:LoginUserContext.java


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