ExternalOAuthIdentityProviderConfigValidator extends BaseIdentityProviderValidator { @Override public void validate(AbstractIdentityProviderDefinition definition) { if (definition == null) { throw new IllegalArgumentException("Config cannot be null OAUTH2.0/OIDC1.0 provider"); } if (!(definition instanceof AbstractExternalOAuthIdentityProviderDefinition)) { throw new IllegalArgumentException("Config is of wrong type for OAUTH2.0/OIDC1.0 provider:" + definition.getClass().getName()); } AbstractExternalOAuthIdentityProviderDefinition def = (AbstractExternalOAuthIdentityProviderDefinition) definition; List<String> errors = new ArrayList<>(); if (def instanceof OIDCIdentityProviderDefinition && ((OIDCIdentityProviderDefinition) definition).getDiscoveryUrl() != null) { } else { if (def.getAuthUrl() == null) { errors.add("Authorization URL must be a valid URL"); } if (def.getTokenUrl() == null) { errors.add("Token URL must be a valid URL"); } if (!hasText(def.getTokenKey()) && def.getTokenKeyUrl() == null) { errors.add("Either token key or token key URL must be specified"); } } if (!hasText(def.getRelyingPartyId())) { errors.add("Relying Party Id must be the client-id for the UAA that is registered with the external IDP"); } if (!hasText(def.getRelyingPartySecret()) && !def.getResponseType().contains("token")) { errors.add("Relying Party Secret must be the client-secret for the UAA that is registered with the external IDP"); } if (def.isShowLinkText() && !hasText(def.getLinkText())) { errors.add("Link Text must be specified because showLinkText is true"); } if (!errors.isEmpty()) { String errorMessages = String.join(",", errors); throw new IllegalArgumentException("Invalid config for Identity Provider " + errorMessages); } }  @Override void validate(AbstractIdentityProviderDefinition definition);  }
@Test public void discovery_url_renders_other_urls_nullable() throws Exception { definition.setAuthUrl(null); definition.setTokenUrl(null); definition.setTokenKeyUrl(null); definition.setTokenKey(null); ((OIDCIdentityProviderDefinition)definition).setDiscoveryUrl(new URL("http: validator = new ExternalOAuthIdentityProviderConfigValidator(); validator.validate(definition); }
@Test(expected = IllegalArgumentException.class) public void configWithNullAuthUrl_ThrowsException() { definition.setAuthUrl(null); validator = new ExternalOAuthIdentityProviderConfigValidator(); validator.validate(definition); }
@Test(expected = IllegalArgumentException.class) public void configWithNullTokenUrl_ThrowsException() { definition.setTokenUrl(null); validator = new ExternalOAuthIdentityProviderConfigValidator(); validator.validate(definition); }
@Test(expected = IllegalArgumentException.class) public void configWithNullRelyingPartyId_ThrowsException() { definition.setRelyingPartyId(null); validator = new ExternalOAuthIdentityProviderConfigValidator(); validator.validate(definition); }
@Test(expected = IllegalArgumentException.class) public void configWithNullRelyingPartySecret_ThrowsException() { definition.setRelyingPartySecret(null); validator = new ExternalOAuthIdentityProviderConfigValidator(); validator.validate(definition); }
@Test(expected = IllegalArgumentException.class) public void configWithShowLinkTextTrue_mustHaveLinkText() { definition.setShowLinkText(true); definition.setLinkText(null); validator = new ExternalOAuthIdentityProviderConfigValidator(); validator.validate(definition); }
@Test public void configWithShowLinkTextFalse_doesNotNeedLinkText() { definition.setShowLinkText(false); definition.setLinkText(null); validator = new ExternalOAuthIdentityProviderConfigValidator(); validator.validate(definition); }
@Test public void no_client_secret_needed_for_implicit() { definition.setRelyingPartySecret(null); definition.setResponseType("code id_token"); validator = new ExternalOAuthIdentityProviderConfigValidator(); validator.validate(definition); }
@Test(expected = IllegalArgumentException.class) public void configCannotBeNull() { validator.validate((AbstractExternalOAuthIdentityProviderDefinition)null); }
@Test(expected = IllegalArgumentException.class) public void tokenKeyUrl_orTokenKeyMustBeSpecified() { definition.setTokenKey(null); definition.setTokenKeyUrl(null); validator.validate(definition); }