Permalink
Browse files

Merge branch hotfix/1.1.2

Change-Id: I6130a64f8c5cf06d6217e421f90c8c82b1dcddea
  • Loading branch information...
2 parents b71ea39 + 70b3267 commit 7f500e7345e94a74b4db3458ae4fd0858dd597d4 @dsyer dsyer committed Aug 30, 2012
View
@@ -6,7 +6,7 @@
<parent>
<groupId>org.cloudfoundry.identity</groupId>
<artifactId>cloudfoundry-identity-parent</artifactId>
- <version>1.1.1</version>
+ <version>1.1.2</version>
<relativePath>..</relativePath>
</parent>
@@ -46,10 +46,6 @@
private ClientRegistrationService clientRegistrationService;
- private Set<String> clientsToOverride = Collections.emptySet();
-
- private boolean override = false;
-
private Map<String, String> authoritiesToScopes = new HashMap<String, String>();
private Collection<String> validScopes = Arrays.asList("password.write", "openid", "cloud_controller.read",
@@ -67,7 +63,8 @@
/**
* 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
*/
@@ -76,13 +73,6 @@ public void setDomain(String domain) {
}
/**
- * @param override the override to set
- */
- public void setOverride(boolean override) {
- this.override = override;
- }
-
- /**
* @param clients the clients to set
*/
public void setClients(Map<String, Map<String, Object>> clients) {
@@ -91,15 +81,6 @@ public void setClients(Map<String, Map<String, Object>> clients) {
}
/**
- * A set of client ids to attempt an update if they already exist (overriding changes made online)
- *
- * @param clientsToOverride the clients to override to set
- */
- public void setClientsToOverride(Set<String> clientsToOverride) {
- this.clientsToOverride = clientsToOverride;
- }
-
- /**
* @param clientRegistrationService the clientRegistrationService to set
*/
public void setClientRegistrationService(ClientRegistrationService clientRegistrationService) {
@@ -253,24 +234,30 @@ private void addNewClients() throws Exception {
(String) map.get("authorities"), (String) map.get("redirect-uri"));
client.setClientSecret((String) map.get("secret"));
Integer validity = (Integer) map.get("access-token-validity");
+ Boolean override = (Boolean) map.get("override");
+ Map<String, Object> info = new HashMap<String, Object>(map);
if (validity != null) {
client.setAccessTokenValiditySeconds(validity);
}
validity = (Integer) map.get("refresh-token-validity");
if (validity != null) {
client.setRefreshTokenValiditySeconds(validity);
}
+ for (String key : Arrays.asList("resource-ids", "scope", "authorized-grant-types", "authorities",
+ "redirect-uri", "secret", "id", "override", "access-token-validity", "refresh-token-validity")) {
+ info.remove(key);
+ }
+ client.setResourceIds(Collections.singleton("none"));
+ client.setAdditionalInformation(info);
try {
clientRegistrationService.addClientDetails(client);
}
catch (ClientAlreadyExistsException e) {
- if (clientsToOverride.contains(clientId)) {
- if (override) {
- logger.info("Overriding client details for " + clientId);
- clientRegistrationService.updateClientDetails(client);
- clientRegistrationService.updateClientSecret(clientId, client.getClientSecret());
- return;
- }
+ if (override!=null && override) {
+ logger.info("Overriding client details for " + clientId);
+ clientRegistrationService.updateClientDetails(client);
+ clientRegistrationService.updateClientSecret(clientId, client.getClientSecret());
+ return;
}
// ignore it
logger.debug(e.getMessage());
@@ -24,101 +24,151 @@
import org.springframework.security.oauth2.provider.ClientAlreadyExistsException;
import org.springframework.security.oauth2.provider.ClientDetails;
import org.springframework.security.oauth2.provider.ClientRegistrationService;
+import org.yaml.snakeyaml.Yaml;
/**
* @author Dave Syer
- *
+ *
*/
public class ClientAdminBootstrapTests {
-
+
private ClientAdminBootstrap bootstrap = new ClientAdminBootstrap();
-
+
private ClientRegistrationService clientRegistrationService = Mockito.mock(ClientRegistrationService.class);
@Test
+ public void testSimpleAddClient() throws Exception {
+ Map<String, Object> map = new HashMap<String, Object>();
+ map.put("id", "foo");
+ map.put("secret", "bar");
+ map.put("scope", "openid");
+ map.put("authorized-grant-types", "authorization_code");
+ map.put("authorities", "uaa.none");
+ BaseClientDetails output = new BaseClientDetails("foo", "none", "openid", "authorization_code", "uaa.none");
+ output.setClientSecret("bar");
+ doSimpleTest(map, output);
+ }
+
+ @Test
public void testClientWithOpenIdOnly() throws Exception {
BaseClientDetails input = new BaseClientDetails("foo", "openid", "openid", "authorization_code", "ROLE_CLIENT");
BaseClientDetails output = new BaseClientDetails("foo", "none", "openid", "authorization_code", "uaa.none");
- doSimpleTest(input, output);
+ doSimpleTestWithLegacyClient(input, output);
}
@Test
public void testAuthCodeClientWithCloudController() throws Exception {
- BaseClientDetails client = new BaseClientDetails("foo", "openid,cloud_controller", "openid,read,write", "authorization_code", "ROLE_CLIENT", null);
- BaseClientDetails output = new BaseClientDetails("foo", "none", "openid,cloud_controller.read,cloud_controller.write", "authorization_code", "uaa.none", null);
- doSimpleTest(client, output);
+ BaseClientDetails client = new BaseClientDetails("foo", "openid,cloud_controller", "openid,read,write",
+ "authorization_code", "ROLE_CLIENT", null);
+ BaseClientDetails output = new BaseClientDetails("foo", "none",
+ "openid,cloud_controller.read,cloud_controller.write", "authorization_code", "uaa.none", null);
+ doSimpleTestWithLegacyClient(client, output);
}
@Test
public void testAdminClient() throws Exception {
- BaseClientDetails input = new BaseClientDetails("foo", "clients,tokens", "read,write,password", "client_credentials", "ROLE_ADMIN", null);
- BaseClientDetails output = new BaseClientDetails("foo", "none", "uaa.none", "client_credentials", "clients.read,clients.secret,clients.write,tokens.read,tokens.write,uaa.admin", null);
- doSimpleTest(input, output);
+ BaseClientDetails input = new BaseClientDetails("foo", "clients,tokens", "read,write,password",
+ "client_credentials", "ROLE_ADMIN", null);
+ BaseClientDetails output = new BaseClientDetails("foo", "none", "uaa.none", "client_credentials",
+ "clients.read,clients.secret,clients.write,tokens.read,tokens.write,uaa.admin", null);
+ doSimpleTestWithLegacyClient(input, output);
}
-
+
@Test
public void testCloudController() throws Exception {
- BaseClientDetails input = new BaseClientDetails("foo", "password,scim,tokens", "read,write,password", "client_credentials", "ROLE_CLIENT,ROLE_ADMIN", null);
- BaseClientDetails output = new BaseClientDetails("foo", "none", "uaa.none", "client_credentials", "password.write,scim.read,scim.write,tokens.read,tokens.write,uaa.admin", null);
- doSimpleTest(input, output);
+ BaseClientDetails input = new BaseClientDetails("foo", "password,scim,tokens", "read,write,password",
+ "client_credentials", "ROLE_CLIENT,ROLE_ADMIN", null);
+ BaseClientDetails output = new BaseClientDetails("foo", "none", "uaa.none", "client_credentials",
+ "password.write,scim.read,scim.write,tokens.read,tokens.write,uaa.admin", null);
+ doSimpleTestWithLegacyClient(input, output);
}
-
+
@Test
public void testOverrideClient() throws Exception {
bootstrap.setClientRegistrationService(clientRegistrationService);
- bootstrap.setClientsToOverride(Collections.singleton("foo"));
- bootstrap.setOverride(true);
Map<String, Object> map = new HashMap<String, Object>();
map.put("secret", "bar");
- bootstrap.setClients(Collections.singletonMap("foo", map ));
- Mockito.doThrow(new ClientAlreadyExistsException("Planned")).when(clientRegistrationService).addClientDetails(Mockito.any(ClientDetails.class));
+ map.put("override", true);
+ bootstrap.setClients(Collections.singletonMap("foo", map));
+ Mockito.doThrow(new ClientAlreadyExistsException("Planned")).when(clientRegistrationService)
+ .addClientDetails(Mockito.any(ClientDetails.class));
+ bootstrap.afterPropertiesSet();
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).addClientDetails(Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).updateClientDetails(
+ Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).updateClientSecret("foo", "bar");
+ }
+
+ @Test
+ public void testOverrideClientWithYaml() throws Exception {
+ bootstrap.setClientRegistrationService(clientRegistrationService);
+ @SuppressWarnings("unchecked")
+ Map<String, Object> map = new Yaml().loadAs("id: foo\noverride: true\nsecret: bar\n"
+ + "access-token-validity: 100", Map.class);
+ bootstrap.setClients(Collections.singletonMap("foo", map));
+ Mockito.doThrow(new ClientAlreadyExistsException("Planned")).when(clientRegistrationService)
+ .addClientDetails(Mockito.any(ClientDetails.class));
bootstrap.afterPropertiesSet();
- Mockito.verify(clientRegistrationService, Mockito.times(1)).addClientDetails(Mockito.any(ClientDetails.class));
- Mockito.verify(clientRegistrationService, Mockito.times(1)).updateClientDetails(Mockito.any(ClientDetails.class));
- Mockito.verify(clientRegistrationService, Mockito.times(1)).updateClientSecret("foo", "bar");
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).addClientDetails(Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).updateClientDetails(
+ Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).updateClientSecret("foo", "bar");
}
-
+
@Test
public void testLegacySkippedController() throws Exception {
- BaseClientDetails input = new BaseClientDetails("legacy_foo", "password,scim,tokens", "read,write,password", "client_credentials", "ROLE_CLIENT,ROLE_ADMIN", null);
+ BaseClientDetails input = new BaseClientDetails("legacy_foo", "password,scim,tokens", "read,write,password",
+ "client_credentials", "ROLE_CLIENT,ROLE_ADMIN", null);
bootstrap.setClientRegistrationService(clientRegistrationService);
- Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Arrays.<ClientDetails>asList(input));
+ Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Arrays.<ClientDetails> asList(input));
bootstrap.afterPropertiesSet();
- Mockito.verify(clientRegistrationService, Mockito.times(0)).addClientDetails(Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(0)).addClientDetails(Mockito.any(ClientDetails.class));
}
-
+
@Test
public void testLegacyHttpsAdded() throws Exception {
bootstrap.setDomain("bar.com");
- BaseClientDetails input = new BaseClientDetails("foo", "password,scim,tokens", "read,write,password", "client_credentials", "ROLE_CLIENT,ROLE_ADMIN", "http://foo.bar.com/spam");
+ BaseClientDetails input = new BaseClientDetails("foo", "password,scim,tokens", "read,write,password",
+ "client_credentials", "ROLE_CLIENT,ROLE_ADMIN", "http://foo.bar.com/spam");
bootstrap.setClientRegistrationService(clientRegistrationService);
- Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Arrays.<ClientDetails>asList(input));
+ Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Arrays.<ClientDetails> asList(input));
bootstrap.afterPropertiesSet();
// legacy is added but the https is not re-added
- Mockito.verify(clientRegistrationService, Mockito.times(1)).addClientDetails(Mockito.any(ClientDetails.class));
- Mockito.verify(clientRegistrationService, Mockito.times(2)).updateClientDetails(Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).addClientDetails(Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(2)).updateClientDetails(
+ Mockito.any(ClientDetails.class));
}
-
+
@Test
public void testLegacyHttpsAlreadyPresent() throws Exception {
bootstrap.setDomain("bar.com");
- BaseClientDetails input = new BaseClientDetails("foo", "password,scim,tokens", "read,write,password", "client_credentials", "ROLE_CLIENT,ROLE_ADMIN", "http://foo.bar.com,https://foo.bar.com");
+ BaseClientDetails input = new BaseClientDetails("foo", "password,scim,tokens", "read,write,password",
+ "client_credentials", "ROLE_CLIENT,ROLE_ADMIN", "http://foo.bar.com,https://foo.bar.com");
bootstrap.setClientRegistrationService(clientRegistrationService);
- Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Arrays.<ClientDetails>asList(input));
+ Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Arrays.<ClientDetails> asList(input));
bootstrap.afterPropertiesSet();
// legacy is added but the https is not re-added
- Mockito.verify(clientRegistrationService, Mockito.times(1)).addClientDetails(Mockito.any(ClientDetails.class));
- Mockito.verify(clientRegistrationService, Mockito.times(1)).updateClientDetails(Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).addClientDetails(Mockito.any(ClientDetails.class));
+ Mockito.verify(clientRegistrationService, Mockito.times(1)).updateClientDetails(
+ Mockito.any(ClientDetails.class));
+ }
+
+ private void doSimpleTest(Map<String, Object> map, BaseClientDetails output) throws Exception {
+ bootstrap.setClientRegistrationService(clientRegistrationService);
+ Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Collections.<ClientDetails> emptyList());
+ bootstrap.setClients(Collections.singletonMap((String) map.get("id"), map));
+ bootstrap.afterPropertiesSet();
+ Mockito.verify(clientRegistrationService).addClientDetails(output);
}
-
- private void doSimpleTest(BaseClientDetails input, BaseClientDetails output) throws Exception {
+
+ private void doSimpleTestWithLegacyClient(BaseClientDetails input, BaseClientDetails output) throws Exception {
bootstrap.setClientRegistrationService(clientRegistrationService);
- Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Arrays.<ClientDetails>asList(input));
+ Mockito.when(clientRegistrationService.listClientDetails()).thenReturn(Arrays.<ClientDetails> asList(input));
bootstrap.afterPropertiesSet();
Mockito.verify(clientRegistrationService).updateClientDetails(output);
BaseClientDetails legacy = new BaseClientDetails(input);
legacy.setClientId("legacy_" + input.getClientId());
- Mockito.verify(clientRegistrationService).addClientDetails(legacy);
+ Mockito.verify(clientRegistrationService).addClientDetails(legacy);
}
}
@@ -59,7 +59,9 @@ class ClientCli < CommonCli
client_reg_request do |cr|
opts[:client_id] = clientname(name)
defaults = opts[:interact] ? cr.get(opts[:client_id]) : {}
- cr.update client_info(defaults, opts[:interact])
+ info = client_info(defaults, opts[:interact])
+ return cr.update info if info.length > 1
+ say "No options given, nothing to update. Use -i for interactive update."
end
end
@@ -86,10 +88,8 @@ def client_reg_request
return yield ClientReg.new(Config.target, auth_header)
rescue TargetError => e
say "\n#{e.message}:\n#{JSON.pretty_generate(e.info)}"
- nil
rescue Exception => e
say "\n#{e.class}: #{e.message}", (e.backtrace if trace?)
- nil
end
def client_info(defaults, interact)
View
@@ -52,10 +52,8 @@ def handle_request
return yield
rescue TargetError => e
say "\n#{e.message}:\n#{JSON.pretty_generate(e.info)}"
- nil
rescue Exception => e
say "\n#{e.class}: #{e.message}", (e.backtrace if trace?)
- nil
end
end
View
@@ -45,10 +45,8 @@ def group_request
#return yield UserAccount.new(cur_target_url, auth_header, trace?)
#rescue TargetError => e
#say "#{e.message}:\n#{JSON.pretty_generate(e.info)}"
- #nil
#rescue Exception => e
#say e.message, (e.backtrace if trace?)
- #nil
end
end
Oops, something went wrong.

0 comments on commit 7f500e7

Please sign in to comment.