use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.
the class ScimUserEndpointsMockMvcTests method testCreateUserWithEmailDomainNotAllowedForOriginUaa.
@Test
void testCreateUserWithEmailDomainNotAllowedForOriginUaa() throws Exception {
ScimUser user = new ScimUser(null, "abc@example.org", "First", "Last");
user.addEmail("abc@example.org");
user.setPassword(new RandomValueStringGenerator(2).generate());
user.setOrigin("uaa");
byte[] requestBody = JsonUtils.writeValueAsBytes(user);
IdentityProvider oidcProvider = new IdentityProvider().setActive(true).setName("OIDC_test").setType(OriginKeys.OIDC10).setOriginKey(OriginKeys.OIDC10).setConfig(new OIDCIdentityProviderDefinition());
oidcProvider.setIdentityZoneId(IdentityZoneHolder.getUaaZone().getId());
oidcProvider.getConfig().setEmailDomain(Collections.singletonList("example.org"));
identityProviderProvisioning.create(oidcProvider, oidcProvider.getIdentityZoneId());
try {
MockHttpServletRequestBuilder post = post("/Users").header("Authorization", "Bearer " + scimCreateToken).contentType(APPLICATION_JSON).content(requestBody);
mockMvc.perform(post).andExpect(status().isBadRequest()).andExpect(jsonPath("$.message").value("The user account is set up for single sign-on. Please use one of these origin(s) : [oidc1.0]"));
} finally {
identityProviderProvisioning.deleteByOrigin(oidcProvider.getOriginKey(), IdentityZoneHolder.getUaaZone().getId());
}
}
use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.
the class ScimUserEndpointsTests method create_with_non_uaa_origin_does_not_validate_password.
@Test
void create_with_non_uaa_origin_does_not_validate_password() {
ScimUser user = spy(new ScimUser(null, "dave", "David", "Syer"));
user.addEmail(new RandomValueStringGenerator().generate() + "@test.org");
user.setOrigin("google");
user.setPassword("bla bla");
MockHttpServletRequest request = new MockHttpServletRequest();
scimUserEndpoints.createUser(user, request, new MockHttpServletResponse());
ArgumentCaptor<String> passwords = ArgumentCaptor.forClass(String.class);
verify(user, atLeastOnce()).setPassword(passwords.capture());
// 1. this method, 2. user scimUserEndpoints, 3. user provisioning
assertEquals(3, passwords.getAllValues().size());
assertEquals("bla bla", passwords.getAllValues().get(0));
assertEquals("", passwords.getAllValues().get(1));
}
use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.
the class ScimUserEndpointsTests method createUserWhenInternalUserManagementIsDisabled.
private void createUserWhenInternalUserManagementIsDisabled(String origin) {
ScimUser user = new ScimUser(null, "dave", "David", "Syer");
user.addEmail(new RandomValueStringGenerator().generate() + "@test.org");
user.setOrigin(origin);
MockHttpServletRequest request = new MockHttpServletRequest();
request.setAttribute(DisableInternalUserManagementFilter.DISABLE_INTERNAL_USER_MANAGEMENT, true);
scimUserEndpoints.createUser(user, request, new MockHttpServletResponse());
}
use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.
the class ScimUserLookupMockMvcTests method createInactiveIdp.
private ScimUser createInactiveIdp(String originKey) throws Exception {
String tokenToCreateIdp = testClient.getClientCredentialsOAuthAccessToken("login", "loginsecret", "idps.write");
IdentityProvider inactiveIdentityProvider = MultitenancyFixture.identityProvider(originKey, "uaa");
inactiveIdentityProvider.setActive(false);
MockMvcUtils.createIdpUsingWebRequest(mockMvc, null, tokenToCreateIdp, inactiveIdentityProvider, status().isCreated());
ScimUser scimUser = new ScimUser(null, new RandomValueStringGenerator().generate() + "@test.org", "test", "test");
scimUser.setPrimaryEmail(scimUser.getUserName());
scimUser.setPassword("secr3T");
scimUser.setOrigin(originKey);
scimUser = MockMvcUtils.createUserInZone(mockMvc, adminToken, scimUser, "");
return scimUser;
}
use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.
the class ScimUserLookupMockMvcTests method setUp.
@BeforeEach
void setUp(@Autowired WebApplicationContext webApplicationContext, @Autowired TestClient testClient, @Autowired MockMvc mockMvc) throws Exception {
this.webApplicationContext = webApplicationContext;
this.mockMvc = mockMvc;
this.testClient = testClient;
adminToken = testClient.getClientCredentialsOAuthAccessToken("admin", "adminsecret", "clients.read clients.write clients.secret scim.read scim.write clients.admin");
user = new ScimUser(null, new RandomValueStringGenerator().generate() + "@test.org", "PasswordResetUserFirst", "PasswordResetUserLast");
user.setPrimaryEmail(user.getUserName());
user.setPassword("secr3T");
user = MockMvcUtils.createUser(this.mockMvc, adminToken, user);
List<String> scopes = Arrays.asList("scim.userids", "cloud_controller.read");
MockMvcUtils.createClient(this.mockMvc, adminToken, clientId, clientSecret, Collections.singleton("scim"), scopes, Arrays.asList("client_credentials", "password"), "uaa.none");
scimLookupIdUserToken = testClient.getUserOAuthAccessToken(clientId, clientSecret, user.getUserName(), "secr3T", "scim.userids");
if (testUsers == null) {
testUsers = createUsers(adminToken);
}
}
Aggregations