Search in sources :

Example 1 with TJSONProtocol

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

the class SimbaFilter method doFilter.

private void doFilter(final HttpServletRequest request, final HttpServletResponse response, final FilterChain chain) throws ServletException, IOException {
    if (isUrlExcluded(request)) {
        chain.doFilter(request, response);
        return;
    }
    RequestData requestData = RequestUtil.createRequestData(request, simbaWebURL, simbeEidSuccessUrl);
    FilterActionFactory actionFactory = new FilterActionFactory(request, response, chain);
    THttpClient tHttpClient = null;
    try {
        tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL());
        TProtocol tProtocol = new TJSONProtocol(tHttpClient);
        AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client(tProtocol);
        ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, authenticationChainName);
        actionFactory.execute(actionDescriptor);
    } catch (Exception e) {
        throw new ServletException(e);
    } finally {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
    }
}
Also used : FilterActionFactory(org.simbasecurity.client.filter.action.FilterActionFactory) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) AuthenticationFilterService(org.simbasecurity.api.service.thrift.AuthenticationFilterService) TProtocol(org.apache.thrift.protocol.TProtocol) RequestData(org.simbasecurity.api.service.thrift.RequestData) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) IOException(java.io.IOException)

Example 2 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 3 with TJSONProtocol

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

the class SimbaJAXWSHandler method handleMessage.

@Override
public boolean handleMessage(final SOAPMessageContext context) {
    if (isInboundMessage(context)) {
        try {
            final SOAPHeader header = context.getMessage().getSOAPHeader();
            final HttpServletRequest httpServletRequest = (HttpServletRequest) context.get(MessageContext.SERVLET_REQUEST);
            final ServletContext servletContext = (ServletContext) context.get(MessageContext.SERVLET_CONTEXT);
            final RequestData requestData = RequestUtil.createWSSERequestData(httpServletRequest, header, getSimbaWebURL(servletContext));
            THttpClient tHttpClient = null;
            try {
                tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL());
                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 SimbaWSAuthenticationException("Authentication Failed");
                }
                String username = actionDescriptor.getPrincipal();
                Principal principal = null;
                if (username != null) {
                    principal = new UserPrincipal(username);
                }
                if (principal != null) {
                    context.put(SimbaPrincipal.SIMBA_USER_CTX_KEY, principal);
                    context.setScope(SimbaPrincipal.SIMBA_USER_CTX_KEY, MessageContext.Scope.APPLICATION);
                }
            } finally {
                if (tHttpClient != null) {
                    tHttpClient.close();
                }
            }
        } catch (Exception e) {
            throw new SimbaWSAuthenticationException("Authentication Failed", e);
        }
    }
    return true;
}
Also used : AuthenticationFilterService(org.simbasecurity.api.service.thrift.AuthenticationFilterService) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) THttpClient(org.apache.thrift.transport.THttpClient) UserPrincipal(com.sun.security.auth.UserPrincipal) HttpServletRequest(javax.servlet.http.HttpServletRequest) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) RequestData(org.simbasecurity.api.service.thrift.RequestData) ServletContext(javax.servlet.ServletContext) THttpClient(org.apache.thrift.transport.THttpClient) SOAPHeader(javax.xml.soap.SOAPHeader) SimbaPrincipal(org.simbasecurity.client.principal.SimbaPrincipal) UserPrincipal(com.sun.security.auth.UserPrincipal) Principal(java.security.Principal)

Example 4 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(SimbaConfiguration.getSimbaAuthenticationURL());
    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 5 with TJSONProtocol

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

the class ZKAccessControl method deserialize.

static AccessControlEntry deserialize(String zkPath, byte[] data) throws IOException {
    if (data.length == 0) {
        return DEFAULT_ACCESS_CONTROL_ENTRY;
    }
    AccessControlEntry ace = new AccessControlEntry();
    TMemoryInputTransport transport = new TMemoryInputTransport(data);
    TJSONProtocol protocol = new TJSONProtocol(transport);
    try {
        ace.read(protocol);
    } catch (TException e) {
        throw new CorruptedAccessControlException(zkPath, e);
    }
    return ace;
}
Also used : TException(org.apache.thrift.TException) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) AccessControlEntry(org.apache.distributedlog.thrift.AccessControlEntry) TMemoryInputTransport(org.apache.thrift.transport.TMemoryInputTransport)

Aggregations

TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)18 TException (org.apache.thrift.TException)9 TProtocol (org.apache.thrift.protocol.TProtocol)9 THttpClient (org.apache.thrift.transport.THttpClient)9 IOException (java.io.IOException)7 TMemoryBuffer (org.apache.thrift.transport.TMemoryBuffer)5 UnsupportedEncodingException (java.io.UnsupportedEncodingException)4 TMemoryInputTransport (org.apache.thrift.transport.TMemoryInputTransport)4 ActionDescriptor (org.simbasecurity.api.service.thrift.ActionDescriptor)3 AuthenticationFilterService (org.simbasecurity.api.service.thrift.AuthenticationFilterService)3 RequestData (org.simbasecurity.api.service.thrift.RequestData)3 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