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;
}
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());
}
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));
}
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));
}
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;
}
Aggregations