@Test public void validateGrantTypes_refreshToken_ko() { Application application = new Application(); ApplicationOAuthSettings oAuthSettings = new ApplicationOAuthSettings(); oAuthSettings.setGrantTypes(Arrays.asList("refresh_token")); oAuthSettings.setResponseTypes(Collections.emptyList()); ApplicationSettings settings = new ApplicationSettings(); settings.setOauth(oAuthSettings); application.setSettings(settings); TestObserver<Application> testObserver = GrantTypeUtils.validateGrantTypes(application).test(); testObserver.assertError(InvalidClientMetadataException.class); testObserver.assertError(err -> ((Throwable)err).getMessage().startsWith("refresh_token grant type must be associated with")); testObserver.assertNotComplete(); }
public static Single<Application> validateGrantTypes(Application application) { if (application==null) { return Single.error(new InvalidClientMetadataException("No application to validate grant")); } if (application.getSettings() == null) { return Single.just(application); } if (application.getSettings().getOauth() == null) { return Single.just(application); } ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); List<String> formattedClientGrantTypes = oAuthSettings.getGrantTypes() == null ? null : oAuthSettings.getGrantTypes().stream().map(str -> str.split(EXTENSION_GRANT_SEPARATOR)[0]).collect(Collectors.toList()); if(!isSupportedGrantType(formattedClientGrantTypes)) { return Single.error(new InvalidClientMetadataException("Missing or invalid grant type.")); } completeGrantTypeCorrespondance(application); Set<String> grantTypeSet = Collections.unmodifiableSet(new HashSet<>(oAuthSettings.getGrantTypes())); if(grantTypeSet.contains(REFRESH_TOKEN)) { List<String> allowedRefreshTokenGrant = Arrays.asList(AUTHORIZATION_CODE, PASSWORD, JWT_BEARER); if(Collections.disjoint(formattedClientGrantTypes, allowedRefreshTokenGrant)) { return Single.error(new InvalidClientMetadataException( REFRESH_TOKEN+" grant type must be associated with one of "+String.join(", ",allowedRefreshTokenGrant) )); } } return Single.just(application); }
GrantTypeUtils { public static Single<Application> validateGrantTypes(Application application) { if (application==null) { return Single.error(new InvalidClientMetadataException("No application to validate grant")); } if (application.getSettings() == null) { return Single.just(application); } if (application.getSettings().getOauth() == null) { return Single.just(application); } ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); List<String> formattedClientGrantTypes = oAuthSettings.getGrantTypes() == null ? null : oAuthSettings.getGrantTypes().stream().map(str -> str.split(EXTENSION_GRANT_SEPARATOR)[0]).collect(Collectors.toList()); if(!isSupportedGrantType(formattedClientGrantTypes)) { return Single.error(new InvalidClientMetadataException("Missing or invalid grant type.")); } completeGrantTypeCorrespondance(application); Set<String> grantTypeSet = Collections.unmodifiableSet(new HashSet<>(oAuthSettings.getGrantTypes())); if(grantTypeSet.contains(REFRESH_TOKEN)) { List<String> allowedRefreshTokenGrant = Arrays.asList(AUTHORIZATION_CODE, PASSWORD, JWT_BEARER); if(Collections.disjoint(formattedClientGrantTypes, allowedRefreshTokenGrant)) { return Single.error(new InvalidClientMetadataException( REFRESH_TOKEN+" grant type must be associated with one of "+String.join(", ",allowedRefreshTokenGrant) )); } } return Single.just(application); } }
GrantTypeUtils { public static Single<Application> validateGrantTypes(Application application) { if (application==null) { return Single.error(new InvalidClientMetadataException("No application to validate grant")); } if (application.getSettings() == null) { return Single.just(application); } if (application.getSettings().getOauth() == null) { return Single.just(application); } ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); List<String> formattedClientGrantTypes = oAuthSettings.getGrantTypes() == null ? null : oAuthSettings.getGrantTypes().stream().map(str -> str.split(EXTENSION_GRANT_SEPARATOR)[0]).collect(Collectors.toList()); if(!isSupportedGrantType(formattedClientGrantTypes)) { return Single.error(new InvalidClientMetadataException("Missing or invalid grant type.")); } completeGrantTypeCorrespondance(application); Set<String> grantTypeSet = Collections.unmodifiableSet(new HashSet<>(oAuthSettings.getGrantTypes())); if(grantTypeSet.contains(REFRESH_TOKEN)) { List<String> allowedRefreshTokenGrant = Arrays.asList(AUTHORIZATION_CODE, PASSWORD, JWT_BEARER); if(Collections.disjoint(formattedClientGrantTypes, allowedRefreshTokenGrant)) { return Single.error(new InvalidClientMetadataException( REFRESH_TOKEN+" grant type must be associated with one of "+String.join(", ",allowedRefreshTokenGrant) )); } } return Single.just(application); }  }
GrantTypeUtils { public static Single<Application> validateGrantTypes(Application application) { if (application==null) { return Single.error(new InvalidClientMetadataException("No application to validate grant")); } if (application.getSettings() == null) { return Single.just(application); } if (application.getSettings().getOauth() == null) { return Single.just(application); } ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); List<String> formattedClientGrantTypes = oAuthSettings.getGrantTypes() == null ? null : oAuthSettings.getGrantTypes().stream().map(str -> str.split(EXTENSION_GRANT_SEPARATOR)[0]).collect(Collectors.toList()); if(!isSupportedGrantType(formattedClientGrantTypes)) { return Single.error(new InvalidClientMetadataException("Missing or invalid grant type.")); } completeGrantTypeCorrespondance(application); Set<String> grantTypeSet = Collections.unmodifiableSet(new HashSet<>(oAuthSettings.getGrantTypes())); if(grantTypeSet.contains(REFRESH_TOKEN)) { List<String> allowedRefreshTokenGrant = Arrays.asList(AUTHORIZATION_CODE, PASSWORD, JWT_BEARER); if(Collections.disjoint(formattedClientGrantTypes, allowedRefreshTokenGrant)) { return Single.error(new InvalidClientMetadataException( REFRESH_TOKEN+" grant type must be associated with one of "+String.join(", ",allowedRefreshTokenGrant) )); } } return Single.just(application); }  static Single<Application> validateGrantTypes(Application application); static List<String> getSupportedGrantTypes(); static boolean isSupportedGrantType(List<String> grantTypes); static boolean isSupportedGrantType(String grantType); static boolean isRedirectUriRequired(List<String> grantTypes); static Application completeGrantTypeCorrespondance(Application application); static Client completeGrantTypeCorrespondance(Client client); }
GrantTypeUtils { public static Single<Application> validateGrantTypes(Application application) { if (application==null) { return Single.error(new InvalidClientMetadataException("No application to validate grant")); } if (application.getSettings() == null) { return Single.just(application); } if (application.getSettings().getOauth() == null) { return Single.just(application); } ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); List<String> formattedClientGrantTypes = oAuthSettings.getGrantTypes() == null ? null : oAuthSettings.getGrantTypes().stream().map(str -> str.split(EXTENSION_GRANT_SEPARATOR)[0]).collect(Collectors.toList()); if(!isSupportedGrantType(formattedClientGrantTypes)) { return Single.error(new InvalidClientMetadataException("Missing or invalid grant type.")); } completeGrantTypeCorrespondance(application); Set<String> grantTypeSet = Collections.unmodifiableSet(new HashSet<>(oAuthSettings.getGrantTypes())); if(grantTypeSet.contains(REFRESH_TOKEN)) { List<String> allowedRefreshTokenGrant = Arrays.asList(AUTHORIZATION_CODE, PASSWORD, JWT_BEARER); if(Collections.disjoint(formattedClientGrantTypes, allowedRefreshTokenGrant)) { return Single.error(new InvalidClientMetadataException( REFRESH_TOKEN+" grant type must be associated with one of "+String.join(", ",allowedRefreshTokenGrant) )); } } return Single.just(application); }  static Single<Application> validateGrantTypes(Application application); static List<String> getSupportedGrantTypes(); static boolean isSupportedGrantType(List<String> grantTypes); static boolean isSupportedGrantType(String grantType); static boolean isRedirectUriRequired(List<String> grantTypes); static Application completeGrantTypeCorrespondance(Application application); static Client completeGrantTypeCorrespondance(Client client);  }