ValidationUtil { public static Authenticator validateAuthenticator( final AuthenticatorType type, final List<Authenticator> authenticators) { if (authenticators.size() == 0) { throw new InvalidRequestException(); } if (type == null) { if (authenticators.size() == 1) { return authenticators.get(0); } else { throw new InvalidRequestException(); } } for (Authenticator test : authenticators) { if (test.getType().equals(type)) { return test; } } throw new InvalidRequestException(); } 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 testValidateAuthenticator() throws Exception { List<Authenticator> testList = new ArrayList<>(); Authenticator one = new Authenticator(); one.setType(AuthenticatorType.Password); Authenticator two = new Authenticator(); two.setType(AuthenticatorType.Test); testList.add(one); testList.add(two); Authenticator result = ValidationUtil.validateAuthenticator( AuthenticatorType.Test, testList); assertEquals(result, two); }
@Test(expected = InvalidRequestException.class) public void testInvalidAuthenticator() throws Exception { List<Authenticator> testList = new ArrayList<>(); Authenticator one = new Authenticator(); one.setType(AuthenticatorType.Password); testList.add(one); ValidationUtil.validateAuthenticator(AuthenticatorType.Test, testList); }
@Test public void testValidateAuthenticatorDefault() throws Exception { List<Authenticator> testList = new ArrayList<>(); Authenticator one = new Authenticator(); one.setType(AuthenticatorType.Password); testList.add(one); Authenticator result = ValidationUtil.validateAuthenticator(null, testList); assertEquals(result, one); }
@Test(expected = InvalidRequestException.class) public void testValidateAuthenticatorDefaultTooMany() throws Exception { List<Authenticator> testList = new ArrayList<>(); Authenticator one = new Authenticator(); one.setType(AuthenticatorType.Password); Authenticator two = new Authenticator(); one.setType(AuthenticatorType.Test); testList.add(one); testList.add(two); ValidationUtil.validateAuthenticator(null, testList); }
@Test(expected = InvalidRequestException.class) public void testValidateAuthenticatorNoOptions() throws Exception { List<Authenticator> testList = new ArrayList<>(); ValidationUtil.validateAuthenticator(null, testList); }