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();
}
}
}
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);
}
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");
}
}
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);
}
}
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();
}
}
}
Aggregations