DefaultSecureProvider implements SecureProvider { @Override public void checkAccess(InvocationContext ctx, String[] roles) throws IllegalAccessException { boolean allowed = roles.length == 0; for (String role : roles) { allowed |= context.isUserInRole(role); if(allowed) { break; } } if(!allowed) { throw new IllegalAccessException(context.getPrincipal().getName()+" no access to "+ctx); } }  @Override void checkAccess(InvocationContext ctx, String[] roles);  }
@Test public void testCheckAccess1() throws Exception { System.out.println("checkAccess"); when(context.isUserInRole("ROLE1")).thenReturn(true); when(context.isUserInRole("ROLE2")).thenReturn(false); instance.checkAccess(getCtx(), new String[] {"ROLE1", "ROLE2"}); }
@Test public void testCheckAccess2() throws Exception { System.out.println("checkAccess"); when(context.isUserInRole("ROLE1")).thenReturn(false); when(context.isUserInRole("ROLE2")).thenReturn(true); instance.checkAccess(getCtx(), new String[] {"ROLE1", "ROLE2"}); }
@Test public void testCheckAccess3() throws Exception { System.out.println("checkAccess"); instance.checkAccess(getCtx(), new String[] {}); }
@Test(expected = IllegalAccessException.class) public void testCheckAccess4() throws Exception { System.out.println("checkAccess"); when(context.isUserInRole("ROLE1")).thenReturn(false); when(context.isUserInRole("ROLE2")).thenReturn(false); instance.checkAccess(getCtx(), new String[] {"ROLE1", "ROLE2"}); }