ValidationUtil { public static SortedMap<String, ApplicationScope> revalidateScope( final String[] requestedScopes, final SortedMap<String, ApplicationScope> originalScopes, final SortedMap<String, ApplicationScope> validScopes) { if (validScopes == null || originalScopes == null) { throw new InvalidScopeException(); } if (requestedScopes == null || requestedScopes.length == 0) { return new TreeMap<>(); } SortedMap<String, ApplicationScope> results = new TreeMap<>(); for (String scope : requestedScopes) { if (!originalScopes.containsKey(scope)) { throw new InvalidScopeException(); } else if (validScopes.containsKey(scope)) { results.put(scope, validScopes.get(scope)); } } return results; } private  ValidationUtil(); static void validateResponseType(final Client client,
                                            final String responseType); static URI requireValidRedirect(
            final URI redirect, final List<ClientRedirect> redirects); static URI requireValidRedirect(
            final String redirect, final List<ClientRedirect> redirects); static URI requireValidRedirect(final String redirect,
                                           final Set<URI> redirects); static URI validateRedirect(final URI redirect,
                                       final List<ClientRedirect> redirects); static URI validateRedirect(final String redirect,
                                       final List<ClientRedirect> redirects); static URI validateRedirect(final URI redirect,
                                       final Set<URI> redirects); static URI validateRedirect(final String redirect,
                                       final Set<URI> redirects); static SortedMap<String, ApplicationScope> validateScope(
            final String[] requestedScopes,
            final SortedMap<String, ApplicationScope> validScopes); static SortedMap<String, ApplicationScope> validateScope(
            final String requestedScopes,
            final SortedMap<String, ApplicationScope> validScopes); static SortedMap<String, ApplicationScope> validateScope(
            final SortedMap<String, ApplicationScope> requestedScopes,
            final Role role); static SortedMap<String, ApplicationScope> validateScope(
            final String requestedScopes, final Role role); static SortedMap<String, ApplicationScope> revalidateScope(
            final String[] requestedScopes,
            final SortedMap<String, ApplicationScope> originalScopes,
            final SortedMap<String, ApplicationScope> validScopes); static SortedMap<String, ApplicationScope> revalidateScope(
            final String requestedScopes,
            final SortedMap<String, ApplicationScope> originalScopes,
            final SortedMap<String, ApplicationScope> validScopes); static SortedMap<String, ApplicationScope> revalidateScope(
            final String requestedScopes,
            final SortedMap<String, ApplicationScope> originalScopes,
            final Role role); static Authenticator validateAuthenticator(
            final AuthenticatorType type,
            final List<Authenticator> authenticators);  }
@Test public void testRevalidateRequestArray() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope( new String[]{"debug1"}, validScopes, validScopes); assertEquals(1, scopes.size()); }
@Test public void testRevalidateRequestString() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope( "debug1", validScopes, validScopes); assertEquals(1, scopes.size()); }
@Test public void testRevalidateRequestRole() throws Exception { Role r = new Role(); r.setScopes(validScopes); SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope( "debug1", validScopes, r); assertEquals(1, scopes.size()); }
@Test(expected = InvalidScopeException.class) public void testRevalidateNullRole() throws Exception { ValidationUtil.revalidateScope("debug1", validScopes, (Role) null); }
@Test public void testRevalidateEmptyRequestString() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope( "", validScopes, validScopes); assertEquals(0, scopes.size()); }
@Test public void testRevalidateNullRequestString() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope((String) null, validScopes, validScopes); assertEquals(0, scopes.size()); }
@Test public void testRevalidateEmptyRequestArray() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope(new String[]{}, validScopes, validScopes); assertEquals(0, scopes.size()); }
@Test public void testRevalidateNullRequestArray() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope((String[]) null, validScopes, validScopes); assertEquals(0, scopes.size()); }
@Test public void testRevalidateEmptyOriginalScope() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope(new String[]{}, emptyScope, validScopes); assertEquals(0, scopes.size()); }
@Test(expected = InvalidScopeException.class) public void testRevalidateNullOriginalScope() throws Exception { ValidationUtil.revalidateScope(new String[]{}, null, validScopes); }
@Test public void testRevalidateEmptyValidScope() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope(new String[]{}, validScopes, emptyScope); assertEquals(0, scopes.size()); }
@Test(expected = InvalidScopeException.class) public void testRevalidateNullValidScope() throws Exception { ValidationUtil.revalidateScope(new String[]{"debug"}, validScopes, null); }
@Test(expected = InvalidScopeException.class) public void testRevalidateCannotEscalateRequestScope() throws Exception { SortedMap<String, ApplicationScope> granted = new TreeMap<>(); granted.put("debug1", new ApplicationScope()); ValidationUtil.revalidateScope( new String[]{"debug", "debug1"}, granted, validScopes); }
@Test public void testRevalidateValidScopesShrank() throws Exception { SortedMap<String, ApplicationScope> shrunkScopes = new TreeMap<>(); shrunkScopes.put("debug1", new ApplicationScope()); SortedMap<String, ApplicationScope> scopes = ValidationUtil.revalidateScope( new String[]{"debug", "debug1"}, validScopes, shrunkScopes); assertEquals(1, scopes.size()); }