@Test(expected = CustomException.class) public void shouldAbortWhenUserDoesNotHaveAnyAuthorizedURI() throws Throwable { MonitoringHelper.initMocks(); RequestContext ctx = RequestContext.getCurrentContext(); request.setRequestURI("/hr-masters/do/something"); ctx.setRequest(request); User user = new User(); user.setActions(new ArrayList<>()); user.setRoles(Collections.singletonList(new Role(10L, "CITIZEN", "CITIZEN", "default"))); ctx.set(USER_INFO_KEY, user); mockServer.expect(requestTo("http: .andRespond(withUnauthorizedRequest()); try { rbacFilter.run(); } catch (RuntimeException ex) { CustomException e = (CustomException)ex.getCause(); assertThat(e.nStatusCode, is(403)); throw ex.getCause(); } assertForbiddenResponse(ctx); }
@Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); final boolean isIncomingURIInAuthorizedActionList = isIncomingURIInAuthorizedActionList(ctx); if (isIncomingURIInAuthorizedActionList) return null; ExceptionUtils.raiseCustomException(HttpStatus.FORBIDDEN, FORBIDDEN_MESSAGE); return null; }
RbacFilter extends ZuulFilter { @Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); final boolean isIncomingURIInAuthorizedActionList = isIncomingURIInAuthorizedActionList(ctx); if (isIncomingURIInAuthorizedActionList) return null; ExceptionUtils.raiseCustomException(HttpStatus.FORBIDDEN, FORBIDDEN_MESSAGE); return null; } }
RbacFilter extends ZuulFilter { @Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); final boolean isIncomingURIInAuthorizedActionList = isIncomingURIInAuthorizedActionList(ctx); if (isIncomingURIInAuthorizedActionList) return null; ExceptionUtils.raiseCustomException(HttpStatus.FORBIDDEN, FORBIDDEN_MESSAGE); return null; } @Autowired  RbacFilter(RestTemplate restTemplate, String authorizationUrl, ObjectMapper objectMapper); }
RbacFilter extends ZuulFilter { @Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); final boolean isIncomingURIInAuthorizedActionList = isIncomingURIInAuthorizedActionList(ctx); if (isIncomingURIInAuthorizedActionList) return null; ExceptionUtils.raiseCustomException(HttpStatus.FORBIDDEN, FORBIDDEN_MESSAGE); return null; } @Autowired  RbacFilter(RestTemplate restTemplate, String authorizationUrl, ObjectMapper objectMapper); @Override String filterType(); @Override int filterOrder(); @Override boolean shouldFilter(); @Override Object run(); }
RbacFilter extends ZuulFilter { @Override public Object run() { RequestContext ctx = RequestContext.getCurrentContext(); final boolean isIncomingURIInAuthorizedActionList = isIncomingURIInAuthorizedActionList(ctx); if (isIncomingURIInAuthorizedActionList) return null; ExceptionUtils.raiseCustomException(HttpStatus.FORBIDDEN, FORBIDDEN_MESSAGE); return null; } @Autowired  RbacFilter(RestTemplate restTemplate, String authorizationUrl, ObjectMapper objectMapper); @Override String filterType(); @Override int filterOrder(); @Override boolean shouldFilter(); @Override Object run();  }