Search in sources :

Example 26 with THttpClient

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);
}
Also used : RequestDefaultHeaders(org.apache.http.client.protocol.RequestDefaultHeaders) HiveAuthzContext(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveAuthzContext) ArrayList(java.util.ArrayList) THttpClient(org.apache.thrift.transport.THttpClient) TExecuteStatementReq(org.apache.hive.service.rpc.thrift.TExecuteStatementReq) HiveOperationType(org.apache.hadoop.hive.ql.security.authorization.plugin.HiveOperationType) HivePrivilegeObject(org.apache.hadoop.hive.ql.security.authorization.plugin.HivePrivilegeObject) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) TCLIService(org.apache.hive.service.rpc.thrift.TCLIService) Header(org.apache.http.Header) BasicHeader(org.apache.http.message.BasicHeader) TTransport(org.apache.thrift.transport.TTransport) TOpenSessionReq(org.apache.hive.service.rpc.thrift.TOpenSessionReq) TOpenSessionResp(org.apache.hive.service.rpc.thrift.TOpenSessionResp) BasicHeader(org.apache.http.message.BasicHeader) HttpBasicAuthInterceptor(org.apache.hive.jdbc.HttpBasicAuthInterceptor)

Example 27 with THttpClient

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);
}
Also used : THttpClient(org.apache.thrift.transport.THttpClient) DefaultHttpClient(org.apache.http.impl.client.DefaultHttpClient) HttpBasicAuthInterceptor(org.apache.hive.jdbc.HttpBasicAuthInterceptor)

Example 28 with THttpClient

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;
}
Also used : THttpClient(org.apache.thrift.transport.THttpClient) TTransportException(org.apache.thrift.transport.TTransportException)

Example 29 with THttpClient

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);
}
Also used : TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient)

Example 30 with THttpClient

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();
        }
    }
}
Also used : ServletException(javax.servlet.ServletException) PolicyDecision(org.simbasecurity.api.service.thrift.PolicyDecision) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) AuthorizationService(org.simbasecurity.api.service.thrift.AuthorizationService) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) ServletException(javax.servlet.ServletException) IOException(java.io.IOException)

Aggregations

THttpClient (org.apache.thrift.transport.THttpClient)51 TProtocol (org.apache.thrift.protocol.TProtocol)34 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)18 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)12 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)9 Test (org.junit.Test)9 TTransport (org.apache.thrift.transport.TTransport)8 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)5 DefaultHttpClient (org.apache.http.impl.client.DefaultHttpClient)5 RequestData (org.simbasecurity.api.service.thrift.RequestData)5 ApacheHttpTransport (com.google.api.client.http.apache.ApacheHttpTransport)4 IOException (java.io.IOException)4 PServiceCall (net.morimekta.providence.PServiceCall)4 TestService (net.morimekta.test.providence.service.TestService)4 Client (org.simbasecurity.api.service.thrift.AuthenticationFilterService.Client)4 HashMap (java.util.HashMap)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 TCLIService (org.apache.hive.service.rpc.thrift.TCLIService)3 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)3 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)3