@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); }
public void assertAuthorized(Annotation a) throws AuthorizationException { if (!(a instanceof RequiresRoles)) return; RequiresRoles rrAnnotation = (RequiresRoles) a; String[] roles = rrAnnotation.value(); if (roles.length == 1) { getSubject().checkRole(roles[0]); return; } if (Logical.AND.equals(rrAnnotation.logical())) { getSubject().checkRoles(Arrays.asList(roles)); return; } if (Logical.OR.equals(rrAnnotation.logical())) { boolean hasAtLeastOneRole = false; for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true; if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]); } }
RoleAnnotationHandler extends AuthorizingAnnotationHandler { public void assertAuthorized(Annotation a) throws AuthorizationException { if (!(a instanceof RequiresRoles)) return; RequiresRoles rrAnnotation = (RequiresRoles) a; String[] roles = rrAnnotation.value(); if (roles.length == 1) { getSubject().checkRole(roles[0]); return; } if (Logical.AND.equals(rrAnnotation.logical())) { getSubject().checkRoles(Arrays.asList(roles)); return; } if (Logical.OR.equals(rrAnnotation.logical())) { boolean hasAtLeastOneRole = false; for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true; if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]); } } }
RoleAnnotationHandler extends AuthorizingAnnotationHandler { public void assertAuthorized(Annotation a) throws AuthorizationException { if (!(a instanceof RequiresRoles)) return; RequiresRoles rrAnnotation = (RequiresRoles) a; String[] roles = rrAnnotation.value(); if (roles.length == 1) { getSubject().checkRole(roles[0]); return; } if (Logical.AND.equals(rrAnnotation.logical())) { getSubject().checkRoles(Arrays.asList(roles)); return; } if (Logical.OR.equals(rrAnnotation.logical())) { boolean hasAtLeastOneRole = false; for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true; if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]); } } RoleAnnotationHandler(); }
RoleAnnotationHandler extends AuthorizingAnnotationHandler { public void assertAuthorized(Annotation a) throws AuthorizationException { if (!(a instanceof RequiresRoles)) return; RequiresRoles rrAnnotation = (RequiresRoles) a; String[] roles = rrAnnotation.value(); if (roles.length == 1) { getSubject().checkRole(roles[0]); return; } if (Logical.AND.equals(rrAnnotation.logical())) { getSubject().checkRoles(Arrays.asList(roles)); return; } if (Logical.OR.equals(rrAnnotation.logical())) { boolean hasAtLeastOneRole = false; for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true; if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]); } } RoleAnnotationHandler(); void assertAuthorized(Annotation a); }
RoleAnnotationHandler extends AuthorizingAnnotationHandler { public void assertAuthorized(Annotation a) throws AuthorizationException { if (!(a instanceof RequiresRoles)) return; RequiresRoles rrAnnotation = (RequiresRoles) a; String[] roles = rrAnnotation.value(); if (roles.length == 1) { getSubject().checkRole(roles[0]); return; } if (Logical.AND.equals(rrAnnotation.logical())) { getSubject().checkRoles(Arrays.asList(roles)); return; } if (Logical.OR.equals(rrAnnotation.logical())) { boolean hasAtLeastOneRole = false; for (String role : roles) if (getSubject().hasRole(role)) hasAtLeastOneRole = true; if (!hasAtLeastOneRole) getSubject().checkRole(roles[0]); } } RoleAnnotationHandler(); void assertAuthorized(Annotation a);  }