本文整理汇总了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;
}
示例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();
}
}