use of org.apache.thrift.transport.THttpClient in project hive by apache.
the class TestThriftHttpCLIServiceFeatures method verifyForwardedHeaders.
private void verifyForwardedHeaders(ArrayList<String> headerIPs, String cmd) throws Exception {
TTransport transport;
DefaultHttpClient hClient = new DefaultHttpClient();
String httpUrl = getHttpUrl();
// add an interceptor that adds the X-Forwarded-For header with given ips
if (!headerIPs.isEmpty()) {
Header xForwardHeader = new BasicHeader("X-Forwarded-For", Joiner.on(",").join(headerIPs));
RequestDefaultHeaders headerInterceptor = new RequestDefaultHeaders(Arrays.asList(xForwardHeader));
hClient.addRequestInterceptor(headerInterceptor);
}
// interceptor for adding username, pwd
HttpBasicAuthInterceptor authInt = new HttpBasicAuthInterceptor(ThriftCLIServiceTest.USERNAME, ThriftCLIServiceTest.PASSWORD, null, null, false, null, null);
hClient.addRequestInterceptor(authInt);
transport = new THttpClient(httpUrl, hClient);
TCLIService.Client httpClient = getClient(transport);
// Create a new open session request object
TOpenSessionReq openReq = new TOpenSessionReq();
TOpenSessionResp openResp = httpClient.OpenSession(openReq);
// execute a query
TExecuteStatementReq execReq = new TExecuteStatementReq(openResp.getSessionHandle(), "show tables");
httpClient.ExecuteStatement(execReq);
// capture arguments to authorizer impl call and verify ip addresses passed
ArgumentCaptor<HiveAuthzContext> contextCapturer = ArgumentCaptor.forClass(HiveAuthzContext.class);
verify(mockedAuthorizer).checkPrivileges(any(HiveOperationType.class), Matchers.anyListOf(HivePrivilegeObject.class), Matchers.anyListOf(HivePrivilegeObject.class), contextCapturer.capture());
HiveAuthzContext context = contextCapturer.getValue();
System.err.println("Forwarded IP Addresses " + context.getForwardedAddresses());
List<String> auditIPAddresses = new ArrayList<String>(context.getForwardedAddresses());
Collections.sort(auditIPAddresses);
Collections.sort(headerIPs);
Assert.assertEquals("Checking forwarded IP Address", headerIPs, auditIPAddresses);
}
use of org.apache.thrift.transport.THttpClient in project hive by apache.
the class TestThriftHttpCLIServiceFeatures method getHttpTransport.
private static TTransport getHttpTransport() throws Exception {
DefaultHttpClient httpClient = new DefaultHttpClient();
String httpUrl = getHttpUrl();
httpClient.addRequestInterceptor(new HttpBasicAuthInterceptor(ThriftCLIServiceTest.USERNAME, ThriftCLIServiceTest.PASSWORD, null, null, false, null, null));
return new THttpClient(httpUrl, httpClient);
}
use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.
the class SimbaGateway method isSimbaAlive.
public boolean isSimbaAlive() {
THttpClient tHttpClient = null;
try {
tHttpClient = getTHttpClient();
tHttpClient.flush();
} catch (TTransportException e) {
if (e.getCause() != null && e.getCause().getClass().isAssignableFrom(SocketException.class)) {
if (tHttpClient != null) {
tHttpClient.close();
}
return false;
}
} finally {
if (tHttpClient != null) {
tHttpClient.close();
}
}
return true;
}
use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.
the class AuthorizationServiceClient method getAuthorizationServiceClient.
protected AuthorizationService.Iface getAuthorizationServiceClient() throws TTransportException {
THttpClient tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthorizationURL());
TProtocol tProtocol = new TJSONProtocol(tHttpClient);
return new AuthorizationService.Client(tProtocol);
}
use of org.apache.thrift.transport.THttpClient in project simba-os by cegeka.
the class FeedingServlet method doPost.
@Override
public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
THttpClient tHttpClient = null;
try {
tHttpClient = new THttpClient(SystemConfiguration.getSimbaServiceURL(getServletContext()) + "/authorizationService");
TProtocol tProtocol = new TJSONProtocol(tHttpClient);
AuthorizationService.Client authorizationClient = new AuthorizationService.Client(tProtocol);
PolicyDecision decision = authorizationClient.isResourceRuleAllowed(request.getUserPrincipal().getName(), "ANIMAL", "WRITE");
if (!decision.isAllowed()) {
response.sendError(HttpServletResponse.SC_UNAUTHORIZED);
return;
}
response.sendRedirect("jsp/feeding.jsp");
} catch (Exception e) {
throw new ServletException(e);
} finally {
if (tHttpClient != null) {
tHttpClient.close();
}
}
}
Aggregations