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