Search in sources :

Example 11 with TJSONProtocol

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

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

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