Skip to content

Commit

Permalink
Merge branch 'feature/register_oauth_provider' into develop
Browse files Browse the repository at this point in the history
[#115081903] https://www.pivotaltracker.com/story/show/115081903

Signed-off-by: Priyata Agrawal <pagrawal@pivotal.io>
  • Loading branch information
mbhave authored and Priyata25 committed Mar 10, 2016
2 parents 8099997 + e5c82f6 commit 896ffae
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ private void addOauthProviders() {
return;
}
for (Map.Entry<String, OauthIdentityProviderDefinition> definition : oauthIdpDefintions.entrySet()) {
validateDuplicateAlias(definition.getKey());
IdentityProvider provider = new IdentityProvider();
if (definition.getValue().getUserInfoUrl()==null) {
provider.setType(OriginKeys.OAUTH20);
Expand All @@ -90,6 +91,14 @@ private void addOauthProviders() {
}
}

public void validateDuplicateAlias(String originKey) {
for (IdentityProvider provider: providers) {
if (provider.getOriginKey().equals(originKey)) {
throw new IllegalArgumentException("Provider alias " + originKey + " is not unique.");
}
}
}

public void setSamlProviders(SamlIdentityProviderConfigurator configurator) {
this.configurator = configurator;
}
Expand All @@ -98,6 +107,7 @@ protected void addSamlProviders() {
return;
}
for (SamlIdentityProviderDefinition def : configurator.getIdentityProviderDefinitions()) {
validateDuplicateAlias(def.getIdpEntityAlias());
IdentityProvider provider = new IdentityProvider();
provider.setType(OriginKeys.SAML);
provider.setOriginKey(def.getIdpEntityAlias());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,30 @@ public void testRemovedOAuthIdentityProviderIsInactive() throws Exception {
}
}

@Test(expected = IllegalArgumentException.class)
public void bootstrap_failsIf_samlAndOauth_haveTheSameAlias() throws Exception {
OauthIdentityProviderDefinition oauthProvider = getOauthProviderDefinition(null);
IdentityProviderProvisioning provisioning = new JdbcIdentityProviderProvisioning(jdbcTemplate);
IdentityProviderBootstrap bootstrap = new IdentityProviderBootstrap(provisioning, new MockEnvironment());
HashMap<String, OauthIdentityProviderDefinition> oauthProviderConfig = new HashMap<>();
oauthProviderConfig.put("same-alias", oauthProvider);

SamlIdentityProviderDefinition definition = new SamlIdentityProviderDefinition();
definition.setIdpEntityAlias("same-alias");
definition.setLinkText("text");
definition.setMetaDataLocation("http://location");
definition.setNameID("nameId");
definition.setShowSamlLink(true);
definition.setMetadataTrustCheck(true);

SamlIdentityProviderConfigurator configurator = mock(SamlIdentityProviderConfigurator.class);
when(configurator.getIdentityProviderDefinitions()).thenReturn(Arrays.asList(definition));

bootstrap.setOauthIdpDefintions(oauthProviderConfig);
bootstrap.setSamlProviders(configurator);
bootstrap.afterPropertiesSet();
}

protected OauthIdentityProviderDefinition getOauthProviderDefinition(String userInfoUrl) throws MalformedURLException {
return new OauthIdentityProviderDefinition()
.setAuthUrl(new URL("http://auth.url"))
Expand Down

0 comments on commit 896ffae

Please sign in to comment.