use of org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification in project uaa by cloudfoundry.
the class ClientAdminEndpoints method updateClientNotSecret.
private ClientDetailsModification updateClientNotSecret(ClientDetailsModification c) {
ClientDetailsModification result = new ClientDetailsModification(clientDetailsService.retrieve(c.getClientId(), IdentityZoneHolder.get().getId()));
ClientDetails client = clientDetailsValidator.validate(c, Mode.MODIFY);
clientRegistrationService.updateClientDetails(client, IdentityZoneHolder.get().getId());
clientUpdates.incrementAndGet();
return result;
}
use of org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification in project uaa by cloudfoundry.
the class ClientAdminEndpointsIntegrationTests method testAddUpdateAndDeleteTx.
@Test
public void testAddUpdateAndDeleteTx() throws Exception {
ClientDetailsModification[] clients = doCreateClients();
for (int i = 1; i < clients.length; i++) {
clients[i] = new ClientDetailsModification(clients[i]);
clients[i].setRefreshTokenValiditySeconds(120);
clients[i].setAction(ClientDetailsModification.UPDATE);
clients[i].setClientSecret("secret");
}
clients[0].setClientId(new RandomValueStringGenerator().generate());
clients[0].setRefreshTokenValiditySeconds(60);
clients[0].setAction(ClientDetailsModification.ADD);
clients[0].setClientSecret("secret");
clients[0].setClientId(new RandomValueStringGenerator().generate());
clients[clients.length - 1].setAction(ClientDetailsModification.DELETE);
headers = getAuthenticatedHeaders(getClientCredentialsAccessToken("clients.admin"));
headers.add("Accept", "application/json");
String oldId = clients[clients.length - 1].getClientId();
ResponseEntity<BaseClientDetails[]> result = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/oauth/clients/tx/modify"), HttpMethod.POST, new HttpEntity<ClientDetailsModification[]>(clients, headers), BaseClientDetails[].class);
assertEquals(HttpStatus.OK, result.getStatusCode());
// set the deleted client ID so we can verify it is gone.
clients[clients.length - 1].setClientId(oldId);
for (int i = 0; i < clients.length; i++) {
ClientDetails client = getClient(clients[i].getClientId());
if (i == (clients.length - 1)) {
assertNull(client);
} else {
assertNotNull(client);
}
}
}
use of org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification in project uaa by cloudfoundry.
the class ClientAdminEndpointsIntegrationTests method createApprovalsClient.
private ClientDetailsModification createApprovalsClient(String... grantTypes) {
ClientDetailsModification detailsModification = new ClientDetailsModification();
detailsModification.setClientId(new RandomValueStringGenerator().generate());
detailsModification.setScope(Arrays.asList("oauth.login", "oauth.approvals", "foo", "bar"));
detailsModification.setAuthorizedGrantTypes(Arrays.asList(grantTypes));
detailsModification.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("uaa.none"));
detailsModification.setClientSecret("secret");
detailsModification.setAdditionalInformation(Collections.<String, Object>singletonMap("foo", Collections.singletonList("bar")));
detailsModification.setRegisteredRedirectUri(Collections.singleton("http://redirect.url"));
ResponseEntity<Void> result = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/oauth/clients"), HttpMethod.POST, new HttpEntity<BaseClientDetails>(detailsModification, headers), Void.class);
assertEquals(HttpStatus.CREATED, result.getStatusCode());
return detailsModification;
}
use of org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification in project uaa by cloudfoundry.
the class ClientAdminEndpointsIntegrationTests method createClientWithSecret.
private ClientDetailsModification createClientWithSecret(String secret, String... grantTypes) {
ClientDetailsModification client = new ClientDetailsModification();
client.setClientId(new RandomValueStringGenerator().generate());
client.setScope(Arrays.asList("oauth.approvals", "foo", "bar"));
client.setAuthorizedGrantTypes(Arrays.asList(grantTypes));
client.setAuthorities(AuthorityUtils.commaSeparatedStringToAuthorityList("uaa.none"));
client.setClientSecret(secret);
client.setAdditionalInformation(Collections.<String, Object>singletonMap("foo", Collections.singletonList("bar")));
client.setRegisteredRedirectUri(Collections.singleton("http://redirect.url"));
ResponseEntity<Void> result = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/oauth/clients"), HttpMethod.POST, new HttpEntity<BaseClientDetails>(client, headers), Void.class);
assertEquals(HttpStatus.CREATED, result.getStatusCode());
return client;
}
use of org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification in project uaa by cloudfoundry.
the class ClientAdminEndpointsIntegrationTests method testClientTxModifyApprovalsDeleted.
@Test
public void testClientTxModifyApprovalsDeleted() throws Exception {
// create client
ClientDetailsModification client = createClient("client_credentials", "password");
assertNotNull(getClient(client.getClientId()));
// issue a user token for this client
OAuth2AccessToken userToken = getUserAccessToken(client.getClientId(), "secret", testAccounts.getUserName(), testAccounts.getPassword(), "oauth.approvals");
// make sure we don't have any approvals
Approval[] approvals = getApprovals(userToken.getValue(), client.getClientId());
Assert.assertEquals(0, approvals.length);
// create three approvals
addApprovals(userToken.getValue(), client.getClientId());
approvals = getApprovals(userToken.getValue(), client.getClientId());
Assert.assertEquals(3, approvals.length);
// delete the client
client.setAction(ClientDetailsModification.DELETE);
ResponseEntity<Void> result = serverRunning.getRestTemplate().exchange(serverRunning.getUrl("/oauth/clients/tx/modify"), HttpMethod.POST, new HttpEntity<BaseClientDetails[]>(new BaseClientDetails[] { client }, getAuthenticatedHeaders(getClientCredentialsAccessToken("clients.admin"))), Void.class);
assertEquals(HttpStatus.OK, result.getStatusCode());
// create a client that can read another clients approvals
String deletedClientId = client.getClientId();
client = createApprovalsClient("password");
userToken = getUserAccessToken(client.getClientId(), "secret", testAccounts.getUserName(), testAccounts.getPassword(), "oauth.approvals");
// make sure we don't have any approvals
approvals = getApprovals(userToken.getValue(), deletedClientId);
Assert.assertEquals(0, approvals.length);
assertNull(getClient(deletedClientId));
}
Aggregations