AccessForbiddenController { @RequestMapping(value="forbidden", method = RequestMethod.GET) public String getInactiveUserPage(ModelMap model, Principal principal) { Authentication auth = SecurityContextHolder.getContext().getAuthentication(); Collection<? extends GrantedAuthority> authorities = auth.getAuthorities(); for (GrantedAuthority ga : authorities) { if (ga.getAuthority().equals(RoleNames.ROLE_QUADRIGA_DEACTIVATED)) { String sUserId = principal.getName(); model.addAttribute("username", sUserId); return "inactiveuser"; } if (ga.getAuthority().equals(RoleNames.ROLE_QUADRIGA_NOACCOUNT)) { String sUserId = principal.getName(); model.addAttribute("username", sUserId); return "nouser"; } } String sUserId = principal.getName(); model.addAttribute("username", sUserId); return "forbidden"; }  @RequestMapping(value="forbidden", method = RequestMethod.GET) String getInactiveUserPage(ModelMap model, Principal principal);  }
@Test public void testGetInactiveUserPage() { SecurityContextHolder.getContext().setAuthentication(authenticationNoAccount); assertEquals(accessForbiddenController.getInactiveUserPage(model, principal), "nouser"); SecurityContextHolder.clearContext(); SecurityContextHolder.getContext().setAuthentication(authenticationDeactivated); assertEquals(accessForbiddenController.getInactiveUserPage(model, principal), "inactiveuser"); SecurityContextHolder.clearContext(); SecurityContextHolder.getContext().setAuthentication(authenticationFailed); assertEquals(accessForbiddenController.getInactiveUserPage(model, principal), "forbidden"); SecurityContextHolder.clearContext(); }