Search in sources :

Example 21 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator 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 22 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class IdentityZoneEndpointsIntegrationTests method testCreateZone.

@Test
public void testCreateZone() {
    zoneId = UUID.randomUUID().toString();
    String requestBody = "{\"id\":\"" + zoneId + "\", \"subdomain\":\"" + zoneId + "\", \"name\":\"testCreateZone() " + zoneId + "\"}";
    HttpHeaders headers = new HttpHeaders();
    headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);
    headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
    ResponseEntity<Void> response = client.exchange(serverRunning.getUrl("/identity-zones"), HttpMethod.POST, new HttpEntity<>(requestBody, headers), new ParameterizedTypeReference<Void>() {
    });
    assertEquals(HttpStatus.CREATED, response.getStatusCode());
    RestTemplate adminClient = IntegrationTestUtils.getClientCredentialsTemplate(IntegrationTestUtils.getClientCredentialsResource(serverRunning.getBaseUrl(), new String[0], "admin", "adminsecret"));
    String email = new RandomValueStringGenerator().generate() + "@samltesting.org";
    ScimUser user = IntegrationTestUtils.createUser(adminClient, serverRunning.getBaseUrl(), email, "firstname", "lastname", email, true);
    ScimGroup scimGroup = new ScimGroup(null, String.format("zones.%s.admin", zoneId), null);
    String clientCredentialsToken = IntegrationTestUtils.getClientCredentialsToken(serverRunning, "admin", "adminsecret");
    ScimGroup group = IntegrationTestUtils.createGroup(clientCredentialsToken, "", serverRunning.getBaseUrl(), scimGroup);
    IntegrationTestUtils.addMemberToGroup(adminClient, serverRunning.getBaseUrl(), user.getId(), group.getId());
    String zoneAdminToken = IntegrationTestUtils.getAccessTokenByAuthCode(serverRunning, UaaTestAccounts.standard(serverRunning), "identity", "identitysecret", email, "secr3T");
    headers.add("Authorization", "bearer " + zoneAdminToken);
    headers.add(IdentityZoneSwitchingFilter.HEADER, zoneId);
    ResponseEntity<List<IdentityProvider>> idpList = new RestTemplate().exchange(serverRunning.getUrl("/identity-providers"), HttpMethod.GET, new HttpEntity<>(null, headers), new ParameterizedTypeReference<List<IdentityProvider>>() {
    });
    IdentityProvider identityProvider = idpList.getBody().get(0);
    assertThat(identityProvider.getIdentityZoneId(), is(zoneId));
    assertThat(identityProvider.getOriginKey(), is(OriginKeys.UAA));
    // the default created zone does have a definition, but no policy
    assertNotNull(identityProvider.getConfig());
    assertNull(ObjectUtils.castInstance(identityProvider.getConfig(), UaaIdentityProviderDefinition.class).getPasswordPolicy());
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) HttpHeaders(org.springframework.http.HttpHeaders) IdentityProvider(org.cloudfoundry.identity.uaa.provider.IdentityProvider) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate) RestTemplate(org.springframework.web.client.RestTemplate) List(java.util.List) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ScimGroup(org.cloudfoundry.identity.uaa.scim.ScimGroup) Test(org.junit.Test)

Example 23 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class ScimUserEndpointsIntegrationTests method findUsersWithExtremePagination.

@Test
public void findUsersWithExtremePagination() {
    for (int i = 0; i < 501; i++) {
        ResponseEntity<ScimUser> scimUserResponseEntity = createUser(new RandomValueStringGenerator().generate().toLowerCase(), new RandomValueStringGenerator().generate().toLowerCase(), new RandomValueStringGenerator().generate().toLowerCase(), new RandomValueStringGenerator().generate().toLowerCase());
        scimUsers.add(scimUserResponseEntity.getBody());
    }
    @SuppressWarnings("rawtypes") ResponseEntity<Map> response = serverRunning.getForObject(usersEndpoint + "?startIndex=0&count=501", Map.class);
    @SuppressWarnings("unchecked") Map<String, Object> results = response.getBody();
    assertEquals(HttpStatus.OK, response.getStatusCode());
    assertThat((Integer) results.get("totalResults"), greaterThan(500));
    assertThat(results.get("itemsPerPage"), is(500));
    assertThat(results.get("startIndex"), is(1));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) Test(org.junit.Test)

Example 24 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class ScimGroupEndpointsIntegrationTests method testExtremeGroupPagination.

@Test
public void testExtremeGroupPagination() {
    for (int i = 0; i < 502; i++) {
        ScimUser user = createUser("deleteme_" + new RandomValueStringGenerator().generate().toLowerCase(), "Passwo3d");
        scimGroups.add(createGroup("cfid_" + new RandomValueStringGenerator().generate().toLowerCase(), new ScimGroupMember(user.getId())));
    }
    ResponseEntity<Map> response = client.getForEntity(serverRunning.getUrl(groupEndpoint + "?count=502"), Map.class);
    Map results = response.getBody();
    assertThat(response.getStatusCode(), is(HttpStatus.OK));
    assertThat((Integer) results.get("totalResults"), greaterThan(500));
    assertThat((List<?>) results.get("resources"), hasSize(500));
    assertThat(results.get("itemsPerPage"), is(500));
    assertThat(results.get("startIndex"), is(1));
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) ScimGroupMember(org.cloudfoundry.identity.uaa.scim.ScimGroupMember) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) MultiValueMap(org.springframework.util.MultiValueMap) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) Test(org.junit.Test)

Example 25 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class MfaProviderTest method createValidGoogleMfaProvider.

private MfaProvider createValidGoogleMfaProvider() {
    MfaProvider<GoogleMfaProviderConfig> res = new MfaProvider();
    res.setName(new RandomValueStringGenerator(5).generate()).setConfig(createValidGoogleMfaConfig()).setIdentityZoneId(IdentityZone.getUaaZoneId()).setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR);
    return res;
}
Also used : RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator)

Aggregations

RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)271 Test (org.junit.jupiter.api.Test)111 Matchers.containsString (org.hamcrest.Matchers.containsString)92 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)81 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)76 Test (org.junit.Test)52 BeforeEach (org.junit.jupiter.api.BeforeEach)45 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)40 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)36 RestTemplate (org.springframework.web.client.RestTemplate)34 IdentityProvider (org.cloudfoundry.identity.uaa.provider.IdentityProvider)30 SamlIdentityProviderDefinition (org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition)29 MvcResult (org.springframework.test.web.servlet.MvcResult)26 SetServerNameRequestPostProcessor (org.cloudfoundry.identity.uaa.util.SetServerNameRequestPostProcessor)16 IdentityZoneConfiguration (org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration)16 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 ScimGroup (org.cloudfoundry.identity.uaa.scim.ScimGroup)14 KeyWithCertTest (org.cloudfoundry.identity.uaa.util.KeyWithCertTest)14 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)14