Search in sources :

Example 6 with TJSONProtocol

use of org.apache.thrift.protocol.TJSONProtocol in project simba-os by cegeka.

the class BaseRESTService method cl.

T cl() throws TException {
    THttpClient tHttpClient = new THttpClient(serviceURL);
    TProtocol tProtocol = new TJSONProtocol(tHttpClient);
    return clientFactory.getClient(tProtocol);
}
Also used : TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) THttpClient(org.apache.thrift.transport.THttpClient)

Example 7 with TJSONProtocol

use of org.apache.thrift.protocol.TJSONProtocol in project simba-os by cegeka.

the class ManagerSecurityInterceptor method authenticationService.

private AuthenticationFilterService.Iface authenticationService() throws TTransportException {
    THttpClient tHttpClient = new THttpClient(SystemConfiguration.getSimbaServiceURL());
    TProtocol tProtocol = new TJSONProtocol(tHttpClient);
    return new AuthenticationFilterService.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 8 with TJSONProtocol

use of org.apache.thrift.protocol.TJSONProtocol in project hive by apache.

the class QueryPlan method toThriftJSONString.

public String toThriftJSONString() throws IOException {
    org.apache.hadoop.hive.ql.plan.api.Query q = getQueryPlan();
    TMemoryBuffer tmb = new TMemoryBuffer(q.toString().length() * 5);
    TJSONProtocol oprot = new TJSONProtocol(tmb);
    try {
        q.write(oprot);
    } catch (TException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return q.toString();
    }
    return tmb.toString("UTF-8");
}
Also used : TException(org.apache.thrift.TException) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TMemoryBuffer(org.apache.thrift.transport.TMemoryBuffer)

Example 9 with TJSONProtocol

use of org.apache.thrift.protocol.TJSONProtocol in project distributedlog by twitter.

the class ZKAccessControl method serialize.

static byte[] serialize(AccessControlEntry ace) throws IOException {
    TMemoryBuffer transport = new TMemoryBuffer(BUFFER_SIZE);
    TJSONProtocol protocol = new TJSONProtocol(transport);
    try {
        ace.write(protocol);
        transport.flush();
        return transport.toString(UTF_8.name()).getBytes(UTF_8);
    } catch (TException e) {
        throw new IOException("Failed to serialize access control entry : ", e);
    } catch (UnsupportedEncodingException uee) {
        throw new IOException("Failed to serialize acesss control entry : ", uee);
    }
}
Also used : TException(org.apache.thrift.TException) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TMemoryBuffer(org.apache.thrift.transport.TMemoryBuffer) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException)

Example 10 with TJSONProtocol

use of org.apache.thrift.protocol.TJSONProtocol in project simba-os by cegeka.

the class JerseyBasicAuthenticationFilter method filter.

@Override
public void filter(ContainerRequestContext containerRequestContext) throws IOException {
    ContainerRequest containerRequest = (ContainerRequest) containerRequestContext.getRequest();
    Map<String, String> requestParameters = toMap(containerRequestContext.getUriInfo().getQueryParameters());
    List<String> auth = containerRequest.getRequestHeader("authorization");
    if (auth == null || auth.isEmpty()) {
        throw new WebApplicationException(Response.Status.UNAUTHORIZED);
    }
    String[] credentials = decode(auth.get(0));
    requestParameters.put(AuthenticationConstants.USERNAME, credentials[0]);
    requestParameters.put(AuthenticationConstants.PASSWORD, credentials[1]);
    RequestData requestData = new RequestData(requestParameters, toMap(containerRequest.getRequestHeaders()), containerRequest.getAbsolutePath().toString(), simbaWebURL, null, /* SSO Token */
    null, /* Client IP */
    false, false, false, false, false, containerRequest.getMethod(), RequestUtil.HOST_SERVER_NAME, null, null);
    THttpClient tHttpClient = null;
    try {
        tHttpClient = new THttpClient(simbaWebURL + "/authenticationService");
        TProtocol tProtocol = new TJSONProtocol(tHttpClient);
        AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client(tProtocol);
        ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, "wsLoginChain");
        if (!actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL)) {
            throw new WebApplicationException(Response.Status.UNAUTHORIZED);
        }
    } catch (Exception e) {
        e.printStackTrace();
        throw new WebApplicationException(e, Response.Status.UNAUTHORIZED);
    } finally {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
    }
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) AuthenticationFilterService(org.simbasecurity.api.service.thrift.AuthenticationFilterService) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) THttpClient(org.apache.thrift.transport.THttpClient) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) RequestData(org.simbasecurity.api.service.thrift.RequestData) ContainerRequest(org.glassfish.jersey.server.ContainerRequest) THttpClient(org.apache.thrift.transport.THttpClient)

Aggregations

TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)12 TProtocol (org.apache.thrift.protocol.TProtocol)7 THttpClient (org.apache.thrift.transport.THttpClient)7 IOException (java.io.IOException)5 TException (org.apache.thrift.TException)5 TMemoryBuffer (org.apache.thrift.transport.TMemoryBuffer)3 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)3 AuthenticationFilterService (org.simbasecurity.api.service.thrift.AuthenticationFilterService)3 RequestData (org.simbasecurity.api.service.thrift.RequestData)3 UnsupportedEncodingException (java.io.UnsupportedEncodingException)2 TMemoryInputTransport (org.apache.thrift.transport.TMemoryInputTransport)2 UserPrincipal (com.sun.security.auth.UserPrincipal)1 AccessControlEntry (com.twitter.distributedlog.thrift.AccessControlEntry)1 BKDLConfigFormat (com.twitter.distributedlog.thrift.BKDLConfigFormat)1 Principal (java.security.Principal)1 ServletContext (javax.servlet.ServletContext)1 ServletException (javax.servlet.ServletException)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 WebApplicationException (javax.ws.rs.WebApplicationException)1 SOAPHeader (javax.xml.soap.SOAPHeader)1