@Test(expected = UnauthenticatedException.class) public void testGuestMultipleRolesAssertion() throws Throwable { RoleAnnotationHandler handler = new RoleAnnotationHandler(); Annotation requiresRolesAnnotation = new RequiresRoles() { public String[] value() { return new String[]{"blah", "blah2"}; } public Class<? extends Annotation> annotationType() { return RequiresRoles.class; } public Logical logical() { return Logical.AND; } }; handler.assertAuthorized(requiresRolesAnnotation); }
@Test public void testOneOfTheRolesRequired() throws Throwable { subject = createMock(Subject.class); expect(subject.hasRole("blah")).andReturn(true); expect(subject.hasRole("blah2")).andReturn(false); replay(subject); RoleAnnotationHandler handler = new RoleAnnotationHandler() { @Override protected Subject getSubject() { return subject; } }; Annotation requiresRolesAnnotation = new RequiresRoles() { public String[] value() { return new String[]{"blah", "blah2"}; } public Class<? extends Annotation> annotationType() { return RequiresRoles.class; } public Logical logical() { return Logical.OR; } }; handler.assertAuthorized(requiresRolesAnnotation); } }
@Test(expected = UnauthenticatedException.class) public void testGuestSingleRoleAssertion() throws Throwable { RoleAnnotationHandler handler = new RoleAnnotationHandler(); Annotation requiresRolesAnnotation = new RequiresRoles() { public String[] value() { return new String[]{"blah"}; } public Class<? extends Annotation> annotationType() { return RequiresRoles.class; } public Logical logical() { return Logical.AND; } }; handler.assertAuthorized(requiresRolesAnnotation); }