本文整理汇总了Java中org.elasticsearch.http.netty.NettyHttpRequest类的典型用法代码示例。如果您正苦于以下问题:Java NettyHttpRequest类的具体用法?Java NettyHttpRequest怎么用?Java NettyHttpRequest使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
NettyHttpRequest类属于org.elasticsearch.http.netty包,在下文中一共展示了NettyHttpRequest类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateRequestIndex
import org.elasticsearch.http.netty.NettyHttpRequest; //导入依赖的package包/类
private RestRequest updateRequestIndex(RestRequest request, String oldIndex, String newIndex) {
String uri = request.uri();
String replaced = uri.replace(oldIndex, newIndex);
NettyHttpRequest nettyRequest = (NettyHttpRequest) request;
HttpRequest httpRequest = nettyRequest.request();
httpRequest.setUri(replaced);
RestRequest updatedRequest = new NettyHttpRequest(httpRequest, nettyRequest.getChannel());
updatedRequest.copyContextAndHeadersFrom(request);
return updatedRequest;
}
示例2: modifyRequest
import org.elasticsearch.http.netty.NettyHttpRequest; //导入依赖的package包/类
/**
* Modify the request of needed
* @param request the original request
* @param context the Openshift context
* @return a modified request
*/
public RestRequest modifyRequest(RestRequest request, OpenshiftRequestContext context) {
if(!getUser(request).equals(context.getUser()) && request instanceof NettyHttpRequest) {
NettyHttpRequest netty = (NettyHttpRequest)request;
HttpRequest httpRequest = netty.request();
httpRequest.headers().set(proxyUserHeader, context.getUser());
return new NettyHttpRequest(httpRequest, netty.getChannel());
}
return request;
}
示例3: authenticate
import org.elasticsearch.http.netty.NettyHttpRequest; //导入依赖的package包/类
@SuppressWarnings("restriction")
@Override
public User authenticate(final RestRequest request, final RestChannel channel, final AuthenticationBackend backend,
final Authorizator authorizator) throws AuthException {
String dn = null;
sun.security.x509.X500Name x500Principal = null;
try {
final NettyHttpRequest nettyRequest = (NettyHttpRequest) request;
final DefaultHttpsRequest httpsRequest = (DefaultHttpsRequest) nettyRequest.request();
x500Principal = (sun.security.x509.X500Name) httpsRequest.getPrincipal();
dn = String.valueOf(x500Principal);// request.header(MutualSSLHandler.SEARCHGUARD_MUTUAL_SSL_AUTH);
} catch (final Exception e) {
log.error("Invalid request or invalid principal. Pls. check settings, this authenticater works only with https/ssl", e);
}
if (dn == null || dn.isEmpty() || dn.equals("null")) {
throw new AuthException("No x500 principal found in request");
}
final String userAttribute = settings.get(ConfigConstants.ARMOR_AUTHENTICATION_HTTPS_CLIENTCERT_ATTRIBUTENAME, "cn")
.toLowerCase();
final int index = dn.toLowerCase().indexOf(userAttribute + "=");
String userName = dn;
if (index > -1) {
final int start = index + userAttribute.length() + 1;
userName = dn.substring(start, dn.indexOf(",", start));
}
final User authenticatedUser = backend.authenticate(new AuthCredentials(userName, x500Principal));
authorizator.fillRoles(authenticatedUser, new AuthCredentials(authenticatedUser.getName(), x500Principal));
log.debug("User '{}' is authenticated", authenticatedUser);
return authenticatedUser;
}
示例4: sendResponse
import org.elasticsearch.http.netty.NettyHttpRequest; //导入依赖的package包/类
@Override
public void sendResponse(final RestResponse response) {
final User user = this.request.getFromContext("armor_authenticated_user");
final Session _session = sessionStore.getSession(SecurityUtil.getSearchGuardSessionIdFromCookie(request));
if (user != null) {
if (_session == null) {
final Session session = sessionStore.createSession(user);
log.trace("Create session and set cookie for {}", user.getName());
final CookieEncoder encoder = new CookieEncoder(true);
final Cookie cookie = new DefaultCookie("es_armor_session", session.getId());
//TODO FUTURE check cookie domain/path
//cookie.setDomain(arg0);
//cookie.setPath(arg0);
cookie.setDiscard(true);
cookie.setSecure(((NettyHttpRequest) request).request() instanceof DefaultHttpsRequest);
cookie.setMaxAge(60 * 60); //1h
cookie.setHttpOnly(true);
encoder.addCookie(cookie);
response.addHeader("Set-Cookie", encoder.encode());
} else {
//Set-Cookie: token=deleted; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT
log.trace("There is already a session");
//TODO FUTURE check cookie seesion validity, expire, ...
}
}
channel.sendResponse(response);
}
示例5: updateMGetRequest
import org.elasticsearch.http.netty.NettyHttpRequest; //导入依赖的package包/类
private RestRequest updateMGetRequest(RestRequest request, String oldIndex, String newIndex) {
BytesReference content = request.content();
String stringContent = content.toUtf8();
String replaced = stringContent.replaceAll("_index\":\"" + oldIndex + "\"", "_index\":\"" + newIndex + "\"");
NettyHttpRequest nettyRequest = (NettyHttpRequest) request;
HttpRequest httpRequest = nettyRequest.request();
BytesReference replacedContent = new BytesArray(replaced);
BigEndianHeapChannelBuffer buffer = new BigEndianHeapChannelBuffer(replacedContent.array());
httpRequest.setContent(buffer);
RestRequest updatedRequest = new NettyHttpRequest(httpRequest, nettyRequest.getChannel());
updatedRequest.copyContextAndHeadersFrom(request);
return updatedRequest;
}