Search in sources :

Example 76 with TProtocol

use of org.apache.thrift.protocol.TProtocol 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)

Example 77 with TProtocol

use of org.apache.thrift.protocol.TProtocol 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 78 with TProtocol

use of org.apache.thrift.protocol.TProtocol 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

TProtocol (org.apache.thrift.protocol.TProtocol)78 TBinaryProtocol (org.apache.thrift.protocol.TBinaryProtocol)29 TTransport (org.apache.thrift.transport.TTransport)28 TSocket (org.apache.thrift.transport.TSocket)23 TException (org.apache.thrift.TException)22 TFramedTransport (org.apache.thrift.transport.TFramedTransport)17 IOException (java.io.IOException)15 TCompactProtocol (org.apache.thrift.protocol.TCompactProtocol)10 TIOStreamTransport (org.apache.thrift.transport.TIOStreamTransport)10 THttpClient (org.apache.thrift.transport.THttpClient)9 TTransportException (org.apache.thrift.transport.TTransportException)8 ByteArrayOutputStream (java.io.ByteArrayOutputStream)7 TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)7 RDF_Term (org.apache.jena.riot.thrift.wire.RDF_Term)6 InputStream (java.io.InputStream)5 ArrayList (java.util.ArrayList)5 TProcessor (org.apache.thrift.TProcessor)5 Hbase (org.apache.hadoop.hbase.thrift.generated.Hbase)4 TTransportFactory (org.apache.thrift.transport.TTransportFactory)4 OutputStream (java.io.OutputStream)3