Search in sources :

Example 16 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)

Example 17 with TJSONProtocol

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

the class BaseRESTService method cl.

T cl(String ssoToken) throws TException {
    THttpClient tHttpClient = new THttpClient(serviceURL);
    tHttpClient.setCustomHeader("Cookie", SIMBA_SSO_TOKEN + "=" + ssoToken);
    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 18 with TJSONProtocol

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

the class BasicAuthenticationFilter method sendRequestAndContinueChain.

private void sendRequestAndContinueChain(RequestData requestData, FilterActionFactory actionFactory) {
    try (THttpClient tHttpClient = new THttpClient(SimbaConfiguration.getSimbaAuthenticationURL())) {
        TProtocol tProtocol = new TJSONProtocol(tHttpClient);
        AuthenticationFilterService.Client authenticationClient = new AuthenticationFilterService.Client(tProtocol);
        ActionDescriptor actionDescriptor = authenticationClient.processRequest(requestData, this.authenticationChainName);
        setPrincipalAndContinueChain(actionFactory, actionDescriptor);
        if (!actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL) && !actionDescriptor.getActionTypes().contains(ActionType.REDIRECT)) {
            throw new SimbaWSAuthenticationException("Authentication Failed");
        }
    } catch (Exception exception) {
        throw new SimbaWSAuthenticationException("Authentication Failed");
    }
}
Also used : TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) AuthenticationFilterService(org.simbasecurity.api.service.thrift.AuthenticationFilterService) TProtocol(org.apache.thrift.protocol.TProtocol) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) THttpClient(org.apache.thrift.transport.THttpClient) SimbaWSAuthenticationException(org.simbasecurity.client.interceptor.SimbaWSAuthenticationException) THttpClient(org.apache.thrift.transport.THttpClient) IOException(java.io.IOException) SimbaWSAuthenticationException(org.simbasecurity.client.interceptor.SimbaWSAuthenticationException)

Example 19 with TJSONProtocol

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

the class JerseyBasicAuthenticationFilter method sendRequest.

private void sendRequest(ContainerRequest containerRequest, UserNamePassword userNamePassword, RequestData requestData) {
    try (THttpClient 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(DO_FILTER_AND_SET_PRINCIPAL)) {
            throw new WebApplicationException(UNAUTHORIZED);
        }
        containerRequest.setSecurityContext(new SecurityContextWithPrincipal(containerRequest.getSecurityContext(), new SimbaPrincipal(userNamePassword.getUserName())));
    } catch (Exception e) {
        e.printStackTrace();
        throw new WebApplicationException(e, UNAUTHORIZED);
    }
}
Also used : TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) SimbaPrincipal(org.simbasecurity.client.principal.SimbaPrincipal) AuthenticationFilterService(org.simbasecurity.api.service.thrift.AuthenticationFilterService) WebApplicationException(javax.ws.rs.WebApplicationException) TProtocol(org.apache.thrift.protocol.TProtocol) ActionDescriptor(org.simbasecurity.api.service.thrift.ActionDescriptor) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) IOException(java.io.IOException) WebApplicationException(javax.ws.rs.WebApplicationException)

Example 20 with TJSONProtocol

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

the class SpringSecurityAuthenticationFilter method doFilter.

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
    HttpServletRequest servletRequest = (HttpServletRequest) request;
    HttpServletResponse servletResponse = (HttpServletResponse) response;
    RequestData requestData = RequestUtil.createRequestData(servletRequest, simbaWebURL, simbaEidSuccessUrl);
    FilterActionFactory actionFactory = new FilterActionFactory(servletRequest, servletResponse, 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);
        if (actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL)) {
            setSpringSecurityContext(servletRequest, actionDescriptor.getPrincipal());
        }
        actionFactory.execute(actionDescriptor);
        if (!actionDescriptor.getActionTypes().contains(ActionType.DO_FILTER_AND_SET_PRINCIPAL) && !actionDescriptor.getActionTypes().contains(ActionType.REDIRECT)) {
            servletResponse.setStatus(HttpStatus.UNAUTHORIZED.value());
        }
    } catch (Exception e) {
        e.printStackTrace();
        servletResponse.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
    } finally {
        if (tHttpClient != null) {
            tHttpClient.close();
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) FilterActionFactory(org.simbasecurity.client.filter.action.FilterActionFactory) TJSONProtocol(org.apache.thrift.protocol.TJSONProtocol) TProtocol(org.apache.thrift.protocol.TProtocol) HttpServletResponse(javax.servlet.http.HttpServletResponse) THttpClient(org.apache.thrift.transport.THttpClient) THttpClient(org.apache.thrift.transport.THttpClient) TException(org.apache.thrift.TException) IOException(java.io.IOException)

Aggregations

TJSONProtocol (org.apache.thrift.protocol.TJSONProtocol)21 TProtocol (org.apache.thrift.protocol.TProtocol)12 THttpClient (org.apache.thrift.transport.THttpClient)12 TException (org.apache.thrift.TException)11 IOException (java.io.IOException)9 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)4 AuthenticationFilterService (org.simbasecurity.api.service.thrift.AuthenticationFilterService)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 RequestData (org.simbasecurity.api.service.thrift.RequestData)2 FilterActionFactory (org.simbasecurity.client.filter.action.FilterActionFactory)2 SimbaPrincipal (org.simbasecurity.client.principal.SimbaPrincipal)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