diff --git a/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/ClientAdminBootstrap.java b/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/ClientAdminBootstrap.java index 319272aade5..891fba20672 100644 --- a/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/ClientAdminBootstrap.java +++ b/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/ClientAdminBootstrap.java @@ -27,6 +27,7 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.cloudfoundry.identity.uaa.user.UaaAuthority; import org.springframework.beans.factory.InitializingBean; import org.springframework.security.core.authority.AuthorityUtils; import org.springframework.security.oauth2.provider.BaseClientDetails; @@ -67,7 +68,8 @@ public class ClientAdminBootstrap implements InitializingBean { /** * The domain suffix (default "cloudfoundry.com") used to detect http redirects. If an http callback in this domain - * is found in a client registration and there is no corresponding value with https as well, then the https value will be added. + * is found in a client registration and there is no corresponding value with https as well, then the https value + * will be added. * * @param domain the domain to set */ @@ -260,6 +262,14 @@ private void addNewClients() throws Exception { if (validity != null) { client.setRefreshTokenValiditySeconds(validity); } + // UAA does not use the resource ids in client registrations + client.setResourceIds(Collections.singleton("none")); + if (client.getScope().isEmpty()) { + client.setScope(Collections.singleton("uaa.none")); + } + if (client.getAuthorities().isEmpty()) { + client.setAuthorities(Collections.singleton(UaaAuthority.UAA_NONE)); + } try { clientRegistrationService.addClientDetails(client); } diff --git a/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/ClientAdminEndpoints.java b/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/ClientAdminEndpoints.java index d29db340635..22b6c6df622 100644 --- a/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/ClientAdminEndpoints.java +++ b/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/ClientAdminEndpoints.java @@ -335,14 +335,18 @@ private ClientDetails validateClient(ClientDetails prototype, boolean create) { } } - if (client.getAuthorities().isEmpty()) { - client.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("uaa.none")); - } + } + if (client.getAuthorities().isEmpty()) { + client.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("uaa.none")); } // The UAA does not allow or require resource ids to be registered because they are determined dynamically - client.setResourceIds(StringUtils.commaDelimitedListToSet("none")); + client.setResourceIds(Collections.singleton("none")); + + if (client.getScope().isEmpty()) { + client.setScope(Collections.singleton("uaa.none")); + } if (requestedGrantTypes.contains("implicit")) { if (StringUtils.hasText(client.getClientSecret())) { diff --git a/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationRequestFactory.java b/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationRequestFactory.java index 4a09a4116e7..627b152349e 100644 --- a/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationRequestFactory.java +++ b/common/src/main/java/org/cloudfoundry/identity/uaa/oauth/UaaAuthorizationRequestFactory.java @@ -207,7 +207,7 @@ private Set checkUserScopes(Set scopes, Collection result = endpoints.removeClientDetails("foo"); @@ -355,7 +360,7 @@ public String getClientId() { @Test public void testAuthorityAllowedByCaller() throws Exception { - BaseClientDetails caller = new BaseClientDetails("caller", null, "none", "client_credentials,implicit", + BaseClientDetails caller = new BaseClientDetails("caller", null, "uaa.none", "client_credentials,implicit", "uaa.none"); when(clientDetailsService.loadClientByClientId("caller")).thenReturn(caller); endpoints.setSecurityContextAccessor(new StubSecurityContextAccessor() { @@ -421,6 +426,7 @@ public void nonImplicitClientWithEmptySecretIsRejected() throws Exception { @Test public void updateNonImplicitClientWithEmptySecretIsOk() throws Exception { + Mockito.when(securityContextAccessor.isAdmin()).thenReturn(true); details.setAuthorizedGrantTypes(Arrays.asList("authorization_code")); details.setClientSecret(null); endpoints.updateClientDetails(details, details.getClientId());