Search in sources :

Example 1 with ClientDetailsModification

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;
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) ClientDetailsModification(org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification)

Example 2 with ClientDetailsModification

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);
        }
    }
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) ClientDetails(org.springframework.security.oauth2.provider.ClientDetails) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ClientDetailsModification(org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification) Test(org.junit.Test)

Example 3 with ClientDetailsModification

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;
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ClientDetailsModification(org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification)

Example 4 with ClientDetailsModification

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;
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ClientDetailsModification(org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification)

Example 5 with ClientDetailsModification

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));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) DefaultOAuth2AccessToken(org.springframework.security.oauth2.common.DefaultOAuth2AccessToken) OAuth2AccessToken(org.springframework.security.oauth2.common.OAuth2AccessToken) Approval(org.cloudfoundry.identity.uaa.approval.Approval) ClientDetailsModification(org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification) Test(org.junit.Test)

Aggregations

ClientDetailsModification (org.cloudfoundry.identity.uaa.oauth.client.ClientDetailsModification)31 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)20 Test (org.junit.jupiter.api.Test)16 ClientDetailsHelper.clientFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientFromString)15 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)15 ResultActions (org.springframework.test.web.servlet.ResultActions)15 ClientDetailsHelper.arrayFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.arrayFromString)14 ClientDetailsHelper.clientArrayFromString (org.cloudfoundry.identity.uaa.mock.util.ClientDetailsHelper.clientArrayFromString)14 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)14 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)8 Approval (org.cloudfoundry.identity.uaa.approval.Approval)4 HashMap (java.util.HashMap)3 AbstractUaaEvent (org.cloudfoundry.identity.uaa.audit.event.AbstractUaaEvent)2 Test (org.junit.Test)2 Transactional (org.springframework.transaction.annotation.Transactional)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)2 ResponseStatus (org.springframework.web.bind.annotation.ResponseStatus)2 HashSet (java.util.HashSet)1 ApprovalStore (org.cloudfoundry.identity.uaa.approval.ApprovalStore)1