@Test public void completeGrantTypeCorrespondance_caseNoResponseType() { Application application = new Application(); ApplicationOAuthSettings oAuthSettings = new ApplicationOAuthSettings(); oAuthSettings.setGrantTypes(Arrays.asList("client_credentials")); oAuthSettings.setResponseTypes(Collections.emptyList()); ApplicationSettings settings = new ApplicationSettings(); settings.setOauth(oAuthSettings); application.setSettings(settings); application = GrantTypeUtils.completeGrantTypeCorrespondance(application); assertTrue("was expecting code grant type",application.getSettings().getOauth().getResponseTypes().isEmpty()); assertTrue("was expecting code grant type",application.getSettings().getOauth().getGrantTypes().contains("client_credentials")); }
public static Application completeGrantTypeCorrespondance(Application application) { boolean updatedGrantType = false; ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); Set responseType = oAuthSettings.getResponseTypes() != null ? new HashSet<>(oAuthSettings.getResponseTypes()) : new HashSet(); Set grantType = oAuthSettings.getGrantTypes() != null ? new HashSet<>(oAuthSettings.getGrantTypes()) : new HashSet(); if(mustHaveAuthorizationCode(responseType) && !grantType.contains(AUTHORIZATION_CODE)) { grantType.add(AUTHORIZATION_CODE); updatedGrantType=true; } if(mustHaveImplicit(responseType) && !grantType.contains(IMPLICIT)) { grantType.add(IMPLICIT); updatedGrantType=true; } if(grantType.contains(AUTHORIZATION_CODE) && !mustHaveAuthorizationCode(responseType)) { grantType.remove(AUTHORIZATION_CODE); updatedGrantType=true; } if(grantType.contains(IMPLICIT) && !mustHaveImplicit(responseType)) { grantType.remove(IMPLICIT); updatedGrantType=true; } if(responseType.isEmpty() && grantType.isEmpty()) { oAuthSettings.setResponseTypes(Client.DEFAULT_RESPONSE_TYPES); oAuthSettings.setGrantTypes(Client.DEFAULT_GRANT_TYPES); } else if(updatedGrantType) { oAuthSettings.setGrantTypes((List<String>)grantType.stream().collect(Collectors.toList())); } return application; }
GrantTypeUtils { public static Application completeGrantTypeCorrespondance(Application application) { boolean updatedGrantType = false; ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); Set responseType = oAuthSettings.getResponseTypes() != null ? new HashSet<>(oAuthSettings.getResponseTypes()) : new HashSet(); Set grantType = oAuthSettings.getGrantTypes() != null ? new HashSet<>(oAuthSettings.getGrantTypes()) : new HashSet(); if(mustHaveAuthorizationCode(responseType) && !grantType.contains(AUTHORIZATION_CODE)) { grantType.add(AUTHORIZATION_CODE); updatedGrantType=true; } if(mustHaveImplicit(responseType) && !grantType.contains(IMPLICIT)) { grantType.add(IMPLICIT); updatedGrantType=true; } if(grantType.contains(AUTHORIZATION_CODE) && !mustHaveAuthorizationCode(responseType)) { grantType.remove(AUTHORIZATION_CODE); updatedGrantType=true; } if(grantType.contains(IMPLICIT) && !mustHaveImplicit(responseType)) { grantType.remove(IMPLICIT); updatedGrantType=true; } if(responseType.isEmpty() && grantType.isEmpty()) { oAuthSettings.setResponseTypes(Client.DEFAULT_RESPONSE_TYPES); oAuthSettings.setGrantTypes(Client.DEFAULT_GRANT_TYPES); } else if(updatedGrantType) { oAuthSettings.setGrantTypes((List<String>)grantType.stream().collect(Collectors.toList())); } return application; } }
GrantTypeUtils { public static Application completeGrantTypeCorrespondance(Application application) { boolean updatedGrantType = false; ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); Set responseType = oAuthSettings.getResponseTypes() != null ? new HashSet<>(oAuthSettings.getResponseTypes()) : new HashSet(); Set grantType = oAuthSettings.getGrantTypes() != null ? new HashSet<>(oAuthSettings.getGrantTypes()) : new HashSet(); if(mustHaveAuthorizationCode(responseType) && !grantType.contains(AUTHORIZATION_CODE)) { grantType.add(AUTHORIZATION_CODE); updatedGrantType=true; } if(mustHaveImplicit(responseType) && !grantType.contains(IMPLICIT)) { grantType.add(IMPLICIT); updatedGrantType=true; } if(grantType.contains(AUTHORIZATION_CODE) && !mustHaveAuthorizationCode(responseType)) { grantType.remove(AUTHORIZATION_CODE); updatedGrantType=true; } if(grantType.contains(IMPLICIT) && !mustHaveImplicit(responseType)) { grantType.remove(IMPLICIT); updatedGrantType=true; } if(responseType.isEmpty() && grantType.isEmpty()) { oAuthSettings.setResponseTypes(Client.DEFAULT_RESPONSE_TYPES); oAuthSettings.setGrantTypes(Client.DEFAULT_GRANT_TYPES); } else if(updatedGrantType) { oAuthSettings.setGrantTypes((List<String>)grantType.stream().collect(Collectors.toList())); } return application; }  }
GrantTypeUtils { public static Application completeGrantTypeCorrespondance(Application application) { boolean updatedGrantType = false; ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); Set responseType = oAuthSettings.getResponseTypes() != null ? new HashSet<>(oAuthSettings.getResponseTypes()) : new HashSet(); Set grantType = oAuthSettings.getGrantTypes() != null ? new HashSet<>(oAuthSettings.getGrantTypes()) : new HashSet(); if(mustHaveAuthorizationCode(responseType) && !grantType.contains(AUTHORIZATION_CODE)) { grantType.add(AUTHORIZATION_CODE); updatedGrantType=true; } if(mustHaveImplicit(responseType) && !grantType.contains(IMPLICIT)) { grantType.add(IMPLICIT); updatedGrantType=true; } if(grantType.contains(AUTHORIZATION_CODE) && !mustHaveAuthorizationCode(responseType)) { grantType.remove(AUTHORIZATION_CODE); updatedGrantType=true; } if(grantType.contains(IMPLICIT) && !mustHaveImplicit(responseType)) { grantType.remove(IMPLICIT); updatedGrantType=true; } if(responseType.isEmpty() && grantType.isEmpty()) { oAuthSettings.setResponseTypes(Client.DEFAULT_RESPONSE_TYPES); oAuthSettings.setGrantTypes(Client.DEFAULT_GRANT_TYPES); } else if(updatedGrantType) { oAuthSettings.setGrantTypes((List<String>)grantType.stream().collect(Collectors.toList())); } return 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 Application completeGrantTypeCorrespondance(Application application) { boolean updatedGrantType = false; ApplicationOAuthSettings oAuthSettings = application.getSettings().getOauth(); Set responseType = oAuthSettings.getResponseTypes() != null ? new HashSet<>(oAuthSettings.getResponseTypes()) : new HashSet(); Set grantType = oAuthSettings.getGrantTypes() != null ? new HashSet<>(oAuthSettings.getGrantTypes()) : new HashSet(); if(mustHaveAuthorizationCode(responseType) && !grantType.contains(AUTHORIZATION_CODE)) { grantType.add(AUTHORIZATION_CODE); updatedGrantType=true; } if(mustHaveImplicit(responseType) && !grantType.contains(IMPLICIT)) { grantType.add(IMPLICIT); updatedGrantType=true; } if(grantType.contains(AUTHORIZATION_CODE) && !mustHaveAuthorizationCode(responseType)) { grantType.remove(AUTHORIZATION_CODE); updatedGrantType=true; } if(grantType.contains(IMPLICIT) && !mustHaveImplicit(responseType)) { grantType.remove(IMPLICIT); updatedGrantType=true; } if(responseType.isEmpty() && grantType.isEmpty()) { oAuthSettings.setResponseTypes(Client.DEFAULT_RESPONSE_TYPES); oAuthSettings.setGrantTypes(Client.DEFAULT_GRANT_TYPES); } else if(updatedGrantType) { oAuthSettings.setGrantTypes((List<String>)grantType.stream().collect(Collectors.toList())); } return 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);  }