Search in sources :

Example 6 with UserGoogleMfaCredentials

use of org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method testDeleteMfaUserCredentialsMfaNotEnabled.

@Test
void testDeleteMfaUserCredentialsMfaNotEnabled() throws Exception {
    ScimUser user = createUser(uaaAdminToken);
    MfaProvider provider = createMfaProvider(IdentityZoneHolder.get().getId());
    IdentityZoneHolder.get().getConfig().setMfaConfig(new MfaConfig().setEnabled(false));
    UserGoogleMfaCredentials creds = new UserGoogleMfaCredentials(user.getId(), "ABCDEFGHIJKLMNOP", 1234, Collections.singletonList(123456)).setMfaProviderId(provider.getId());
    mfaCredentialsProvisioning.save(creds, IdentityZoneHolder.get().getId());
    assertNotNull(mfaCredentialsProvisioning.retrieve(user.getId(), provider.getId()));
    MockHttpServletRequestBuilder delete = delete("/Users/" + user.getId() + "/mfa").header("Authorization", "Bearer " + uaaAdminToken).contentType(APPLICATION_JSON);
    mockMvc.perform(delete).andExpect(status().isOk());
    assertMfaCredentialsNotExisting(user, provider);
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) MfaConfig(org.cloudfoundry.identity.uaa.zone.MfaConfig) UserGoogleMfaCredentials(org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.jupiter.api.Test)

Example 7 with UserGoogleMfaCredentials

use of org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials in project uaa by cloudfoundry.

the class ScimUserEndpointsMockMvcTests method testDeleteMfaUserCredentialsWithZoneSwitching.

@Test
void testDeleteMfaUserCredentialsWithZoneSwitching() throws Exception {
    IdentityZone identityZone = getIdentityZone();
    String authorities = "zones." + identityZone.getId() + ".admin";
    clientDetails = MockMvcUtils.createClient(mockMvc, uaaAdminToken, "switchClientId", "switchClientSecret", null, null, Collections.singletonList("client_credentials"), authorities, null, IdentityZone.getUaa());
    String uaaAdminTokenFromOtherZone = testClient.getClientCredentialsOAuthAccessToken("switchClientId", "switchClientSecret", authorities);
    ScimUser user = setUpScimUser(identityZone);
    MfaProvider provider = createMfaProvider(identityZone.getId());
    identityZone.getConfig().setMfaConfig(new MfaConfig().setEnabled(true).setProviderName("mfaProvider"));
    MockMvcUtils.updateIdentityZone(identityZone, webApplicationContext);
    UserGoogleMfaCredentials creds = new UserGoogleMfaCredentials(user.getId(), "ABCDEFGHIJKLMNOP", 1234, Collections.singletonList(123456)).setMfaProviderId(provider.getId());
    mfaCredentialsProvisioning.save(creds, identityZone.getId());
    assertNotNull(mfaCredentialsProvisioning.retrieve(user.getId(), provider.getId()));
    MockHttpServletRequestBuilder delete = delete("/Users/" + user.getId() + "/mfa").header("Authorization", "Bearer " + uaaAdminTokenFromOtherZone).header(HEADER, identityZone.getId()).contentType(APPLICATION_JSON);
    mockMvc.perform(delete).andExpect(status().isOk());
    assertMfaCredentialsNotExisting(user, provider);
}
Also used : ScimUser(org.cloudfoundry.identity.uaa.scim.ScimUser) MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) MfaConfig(org.cloudfoundry.identity.uaa.zone.MfaConfig) UserGoogleMfaCredentials(org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

UserGoogleMfaCredentials (org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials)7 Test (org.junit.jupiter.api.Test)6 MfaProvider (org.cloudfoundry.identity.uaa.mfa.MfaProvider)3 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)3 MfaConfig (org.cloudfoundry.identity.uaa.zone.MfaConfig)3 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)3 MockHttpSession (org.springframework.mock.web.MockHttpSession)2 MockMvcResultHandlers.print (org.springframework.test.web.servlet.result.MockMvcResultHandlers.print)2 UaaPrincipal (org.cloudfoundry.identity.uaa.authentication.UaaPrincipal)1 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1