ValidationUtil { public static SortedMap<String, ApplicationScope> validateScope( final String[] requestedScopes, final SortedMap<String, ApplicationScope> validScopes) { if (requestedScopes == null || requestedScopes.length == 0) { return new TreeMap<>(); } if (validScopes == null) { throw new InvalidScopeException(); } SortedMap<String, ApplicationScope> results = new TreeMap<>(); for (String scope : requestedScopes) { 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 testValidScopeString() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope("debug1", validScopes); assertEquals(1, scopes.size()); }
@Test public void testEncodedValidScopeString() throws Exception { String scope = "encodable:scope"; String encoded = URLEncoder.encode(scope, "UTF-8"); SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope(encoded, validScopes); assertEquals(1, scopes.size()); }
@Test public void testValidScopeArray() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil .validateScope(new String[]{"debug1"}, validScopes); assertEquals(1, scopes.size()); }
@Test public void testInvalidScope() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope(new String[]{"invalid"}, validScopes); assertEquals(0, scopes.size()); }
@Test public void testNullScopeString() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope((String) null, validScopes); assertEquals(0, scopes.size()); }
@Test public void testEmptyScopeString() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope("", validScopes); assertEquals(0, scopes.size()); }
@Test public void testNullScopeArray() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope((String[]) null, validScopes); assertEquals(0, scopes.size()); }
@Test public void testEmptyScopeArray() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope(new String[]{}, validScopes); assertEquals(0, scopes.size()); }
@Test(expected = InvalidScopeException.class) public void testNullValidScopes() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope(new String[]{"debug1"}, null); assertEquals(0, scopes.size()); }
@Test public void testEmptyValidScopes() throws Exception { SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope(new String[]{"debug1"}, new TreeMap<>()); assertEquals(0, scopes.size()); }
@Test(expected = InvalidScopeException.class) public void testValidateScopeStringNullRole() throws Exception { ValidationUtil.validateScope("debug1", (Role) null); }
@Test public void testValidateScopeStringNoScopeRole() throws Exception { SortedMap<String, ApplicationScope> roleScopes = new TreeMap<>(); Role r = new Role(); r.setScopes(roleScopes); SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope("", r); assertEquals(0, scopes.size()); }
@Test public void testValidateScopeStringValidScopesInRole() throws Exception { SortedMap<String, ApplicationScope> roleScopes = new TreeMap<>(); ApplicationScope debug1Scope = new ApplicationScope(); debug1Scope.setName("debug1"); roleScopes.put(debug1Scope.getName(), debug1Scope); ApplicationScope debug2Scope = new ApplicationScope(); debug2Scope.setName("debug2"); roleScopes.put(debug2Scope.getName(), debug2Scope); Role r = new Role(); r.setScopes(roleScopes); SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope("debug2", r); assertEquals(1, scopes.size()); }
@Test public void testValidateScopeStringMismatchScopesInRole() throws Exception { SortedMap<String, ApplicationScope> roleScopes = new TreeMap<>(); ApplicationScope debug1Scope = new ApplicationScope(); debug1Scope.setName("debug1"); roleScopes.put(debug1Scope.getName(), debug1Scope); ApplicationScope debug2Scope = new ApplicationScope(); debug2Scope.setName("debug2"); roleScopes.put(debug2Scope.getName(), debug2Scope); Role r = new Role(); r.setScopes(roleScopes); SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope("debug1 debug3", r); assertEquals(1, scopes.size()); }
@Test(expected = InvalidScopeException.class) public void testValidateScopeMapNullRole() throws Exception { ValidationUtil.validateScope(new TreeMap<>(), (Role) null); }
@Test public void testValidateScopeMapNoScopeRole() throws Exception { SortedMap<String, ApplicationScope> roleScopes = new TreeMap<>(); Role r = new Role(); r.setScopes(roleScopes); SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope(new TreeMap<>(), r); assertEquals(0, scopes.size()); }
@Test public void testValidateScopeMapValidScopesInRole() throws Exception { SortedMap<String, ApplicationScope> roleScopes = new TreeMap<>(); ApplicationScope debug1Scope = new ApplicationScope(); debug1Scope.setName("debug1"); roleScopes.put(debug1Scope.getName(), debug1Scope); ApplicationScope debug2Scope = new ApplicationScope(); debug2Scope.setName("debug2"); roleScopes.put(debug2Scope.getName(), debug2Scope); SortedMap<String, ApplicationScope> requestedScopes = new TreeMap<>(); requestedScopes.put(debug2Scope.getName(), debug2Scope); Role r = new Role(); r.setScopes(roleScopes); SortedMap<String, ApplicationScope> scopes = ValidationUtil.validateScope(requestedScopes, r); assertEquals(1, scopes.size()); }
@Test(expected = InvalidScopeException.class) public void testValidateScopeMapMismatchScopesInRole() throws Exception { SortedMap<String, ApplicationScope> roleScopes = new TreeMap<>(); ApplicationScope debug1Scope = new ApplicationScope(); debug1Scope.setName("debug1"); roleScopes.put(debug1Scope.getName(), debug1Scope); ApplicationScope debug2Scope = new ApplicationScope(); debug2Scope.setName("debug2"); roleScopes.put(debug2Scope.getName(), debug2Scope); ApplicationScope debug3Scope = new ApplicationScope(); debug3Scope.setName("debug3"); SortedMap<String, ApplicationScope> requestedScopes = new TreeMap<>(); requestedScopes.put(debug2Scope.getName(), debug2Scope); requestedScopes.put(debug3Scope.getName(), debug3Scope); Role r = new Role(); r.setScopes(roleScopes); ValidationUtil.validateScope(requestedScopes, r); }