DisjunctAuthScopeExpression extends AbstractAuthScopeExpression { @Override public boolean isAuthorized(Set<String> userScopes) { if (innerExpressions.isEmpty()) { return false; } for (AuthScopeExpression innerExpression : innerExpressions) { if (innerExpression.isAuthorized(userScopes)) { return true; } } return false; } DisjunctAuthScopeExpression(List<AbstractAuthScopeExpression> innerExpressions); @Override String[] getAllScopes(); @Override boolean isAuthorized(Set<String> userScopes); @Override String toLoggingForm(); @Override boolean equals(Object obj); @Override int hashCode();  }
@Test public void testIsAuthorizedWithNoInnerExpressions() { DisjunctAuthScopeExpression expression = new DisjunctAuthScopeExpression(ImmutableList.<AbstractAuthScopeExpression>of()); assertFalse(expression.isAuthorized(ImmutableSet.of("scope0"))); }
@Test public void testIsAuthorizedWithSuccess() { Set<String> scopes = ImmutableSet.of("scope0", "scope1", "scope2", "scope3"); AbstractAuthScopeExpression expression1 = mock(AbstractAuthScopeExpression.class); AbstractAuthScopeExpression expression2 = mock(AbstractAuthScopeExpression.class); when(expression2.isAuthorized(scopes)).thenReturn(true); AbstractAuthScopeExpression expression3 = mock(AbstractAuthScopeExpression.class); when(expression3.isAuthorized(scopes)).thenReturn(true); DisjunctAuthScopeExpression expression = new DisjunctAuthScopeExpression( ImmutableList.<AbstractAuthScopeExpression>of(expression1, expression2, expression3)); assertTrue(expression.isAuthorized(scopes)); }
@Test public void testIsAuthorizedWithFailure() { Set<String> scopes = ImmutableSet.of("scope0", "scope1", "scope2", "scope3"); AbstractAuthScopeExpression expression1 = mock(AbstractAuthScopeExpression.class); AbstractAuthScopeExpression expression2 = mock(AbstractAuthScopeExpression.class); AbstractAuthScopeExpression expression3 = mock(AbstractAuthScopeExpression.class); DisjunctAuthScopeExpression expression = new DisjunctAuthScopeExpression( ImmutableList.<AbstractAuthScopeExpression>of(expression1, expression2, expression3)); assertFalse(expression.isAuthorized(scopes)); }