Search in sources :

Example 26 with MfaProvider

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

the class MfaProviderEndpointsMockMvcTests method testDeleteZoneActiveMfaProviderShouldFail.

@Test
void testDeleteZoneActiveMfaProviderShouldFail() throws Exception {
    IdentityZone identityZone = MockMvcUtils.createZoneUsingWebRequest(mockMvc, adminToken);
    MfaProvider<GoogleMfaProviderConfig> mfaProvider = constructGoogleMfaProvider();
    mfaProvider = JsonUtils.readValue(mockMvc.perform(post("/mfa-providers").header("Authorization", "Bearer " + adminToken).header("X-Identity-Zone-Id", identityZone.getId()).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(mfaProvider))).andReturn().getResponse().getContentAsString(), MfaProvider.class);
    identityZone.getConfig().getMfaConfig().setEnabled(true).setProviderName(mfaProvider.getName());
    MockMvcUtils.updateIdentityZone(identityZone, webApplicationContext);
    String deleteResponse = mockMvc.perform(delete("/mfa-providers/" + mfaProvider.getId()).header("Authorization", "Bearer " + adminToken).header("X-Identity-Zone-Id", identityZone.getId())).andExpect(status().isConflict()).andReturn().getResponse().getContentAsString();
    assertThat(deleteResponse, containsString("MFA provider is currently active on zone: " + identityZone.getId()));
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) MockMvcUtils.constructGoogleMfaProvider(org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.constructGoogleMfaProvider) IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) GoogleMfaProviderConfig(org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.jupiter.api.Test)

Example 27 with MfaProvider

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

the class MfaProviderEndpointsMockMvcTests method testCreateGoogleMfaProviderConfigDefaults.

@Test
void testCreateGoogleMfaProviderConfigDefaults() throws Exception {
    MfaProvider mfaProvider = constructGoogleMfaProvider();
    mfaProvider.setConfig(null);
    MvcResult mfaResponse = mockMvc.perform(post("/mfa-providers").header("Authorization", "Bearer " + adminToken).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(mfaProvider))).andReturn();
    assertEquals(HttpStatus.CREATED.value(), mfaResponse.getResponse().getStatus());
    MfaProvider<GoogleMfaProviderConfig> mfaProviderCreated = JsonUtils.readValue(mfaResponse.getResponse().getContentAsString(), MfaProvider.class);
    assertEquals(IdentityZoneHolder.get().getName(), mfaProviderCreated.getConfig().getIssuer());
    assertEquals(IdentityZoneHolder.get().getId(), mfaProviderCreated.getIdentityZoneId());
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) MockMvcUtils.constructGoogleMfaProvider(org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.constructGoogleMfaProvider) GoogleMfaProviderConfig(org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test)

Example 28 with MfaProvider

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

the class IntegrationTestUtils method createGoogleMfaProvider.

public static MfaProvider createGoogleMfaProvider(String url, String token, MfaProvider<GoogleMfaProviderConfig> provider, String zoneSwitchId) {
    RestTemplate template = new RestTemplate();
    MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
    headers.add("Accept", APPLICATION_JSON_VALUE);
    headers.add("Authorization", "bearer " + token);
    headers.add("Content-Type", APPLICATION_JSON_VALUE);
    if (hasText(zoneSwitchId)) {
        headers.add(IdentityZoneSwitchingFilter.HEADER, zoneSwitchId);
    }
    HttpEntity getHeaders = new HttpEntity<>(provider, headers);
    ResponseEntity<MfaProvider> providerResponse = template.exchange(url + "/mfa-providers", HttpMethod.POST, getHeaders, MfaProvider.class);
    if (providerResponse.getStatusCode() == HttpStatus.CREATED) {
        return providerResponse.getBody();
    }
    throw new RuntimeException("Invalid return code:" + providerResponse.getStatusCode());
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) LinkedMultiValueMap(org.springframework.util.LinkedMultiValueMap) RestTemplate(org.springframework.web.client.RestTemplate) OAuth2RestTemplate(org.springframework.security.oauth2.client.OAuth2RestTemplate)

Example 29 with MfaProvider

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

the class LoginMockMvcTests method setUpContext.

@BeforeEach
void setUpContext(@Autowired WebApplicationContext webApplicationContext, @Autowired MockMvc mockMvc, @Autowired IdentityZoneProvisioning identityZoneProvisioning, @Autowired LimitedModeUaaFilter limitedModeUaaFilter) throws Exception {
    generator = new RandomValueStringGenerator();
    this.webApplicationContext = webApplicationContext;
    this.mockMvc = mockMvc;
    this.limitedModeUaaFilter = limitedModeUaaFilter;
    SecurityContextHolder.clearContext();
    String adminToken = MockMvcUtils.getClientCredentialsOAuthAccessToken(mockMvc, "admin", "adminsecret", null, null);
    identityZoneConfiguration = identityZoneProvisioning.retrieve(IdentityZone.getUaaZoneId()).getConfig();
    IdentityZoneHolder.setProvisioning(identityZoneProvisioning);
    String subdomain = new RandomValueStringGenerator(24).generate().toLowerCase();
    identityZone = MockMvcUtils.createOtherIdentityZone(subdomain, mockMvc, webApplicationContext, false, IdentityZoneHolder.getCurrentZoneId());
    MfaProvider mfaProvider = constructGoogleMfaProvider();
    mfaProvider = JsonUtils.readValue(mockMvc.perform(post("/mfa-providers").header("X-Identity-Zone-Id", identityZone.getId()).header("Authorization", "Bearer " + adminToken).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(mfaProvider))).andExpect(status().isCreated()).andReturn().getResponse().getContentAsByteArray(), MfaProvider.class);
    identityZone.getConfig().getMfaConfig().setEnabled(true).setProviderName(mfaProvider.getName());
    MockMvcUtils.updateIdentityZone(identityZone, webApplicationContext);
    originalLimitedModeStatusFile = MockMvcUtils.getLimitedModeStatusFile(webApplicationContext);
    MockMvcUtils.resetLimitedModeStatusFile(webApplicationContext, null);
    assertFalse(isLimitedMode(limitedModeUaaFilter));
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) MockMvcUtils.constructGoogleMfaProvider(org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.constructGoogleMfaProvider) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) Matchers.containsString(org.hamcrest.Matchers.containsString) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

MfaProvider (org.cloudfoundry.identity.uaa.mfa.MfaProvider)29 Test (org.junit.jupiter.api.Test)16 GoogleMfaProviderConfig (org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig)12 MockMvcUtils.constructGoogleMfaProvider (org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.constructGoogleMfaProvider)10 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)7 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)6 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)6 MfaProviderProvisioning (org.cloudfoundry.identity.uaa.mfa.MfaProviderProvisioning)5 MfaConfig (org.cloudfoundry.identity.uaa.zone.MfaConfig)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 MvcResult (org.springframework.test.web.servlet.MvcResult)5 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)4 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)4 JdbcMfaProviderProvisioning (org.cloudfoundry.identity.uaa.mfa.JdbcMfaProviderProvisioning)3 UserGoogleMfaCredentials (org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials)3 ResultActions (org.springframework.test.web.servlet.ResultActions)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 UaaPrincipal (org.cloudfoundry.identity.uaa.authentication.UaaPrincipal)2 Before (org.junit.Before)2 BeforeEach (org.junit.jupiter.api.BeforeEach)2