use of org.cloudfoundry.identity.uaa.mfa.MfaProvider in project uaa by cloudfoundry.
the class MfaProviderEndpointsMockMvcTests method testCreateMfaProvider.
@Test
void testCreateMfaProvider() throws Exception {
MfaProvider<GoogleMfaProviderConfig> mfaProvider = constructGoogleMfaProvider();
String name = new RandomValueStringGenerator(5).generate();
mfaProvider.setName(name);
MvcResult mfaResponse = mockMvc.perform(post("/mfa-providers").header("Authorization", "Bearer " + adminToken).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(mfaProvider))).andReturn();
mfaProvider = JsonUtils.readValue(mfaResponse.getResponse().getContentAsString(), MfaProvider.class);
assertEquals(HttpStatus.CREATED.value(), mfaResponse.getResponse().getStatus());
assertEquals(name, mfaProvider.getName());
assertNotNull(mfaProvider.getId());
}
use of org.cloudfoundry.identity.uaa.mfa.MfaProvider in project uaa by cloudfoundry.
the class IdentityZoneEndpointsMockMvcTests method createGoogleMfaProvider.
private MfaProvider<GoogleMfaProviderConfig> createGoogleMfaProvider(String zoneId) throws Exception {
MfaProvider<GoogleMfaProviderConfig> mfaProvider = new MfaProvider().setName(new RandomValueStringGenerator(5).generate());
MockHttpServletRequestBuilder createMfaRequest = post("/mfa-providers").header("Authorization", "Bearer " + adminToken).contentType(APPLICATION_JSON).content(JsonUtils.writeValueAsString(mfaProvider));
if (hasText(zoneId)) {
createMfaRequest.header("X-Identity-Zone-Id", zoneId);
}
MockHttpServletResponse mfaProviderResponse = mockMvc.perform(createMfaRequest).andReturn().getResponse();
mfaProvider = JsonUtils.readValue(mfaProviderResponse.getContentAsString(), MfaProvider.class);
return mfaProvider;
}
use of org.cloudfoundry.identity.uaa.mfa.MfaProvider in project uaa by cloudfoundry.
the class TotpMfaEndpoint method generateQrUrl.
@RequestMapping(value = { "/register" }, method = RequestMethod.GET)
public String generateQrUrl(Model model, @ModelAttribute("uaaMfaCredentials") UserGoogleMfaCredentials credentials) throws WriterException, IOException, UaaPrincipalIsNotInSession {
UaaPrincipal uaaPrincipal = getSessionAuthPrincipal();
MfaProvider provider = getMfaProvider();
if (mfaCredentialsProvisioning.activeUserCredentialExists(uaaPrincipal.getId(), provider.getId())) {
return "redirect:/login/mfa/verify";
} else {
String url = mfaCredentialsProvisioning.getOtpAuthURL(provider.getConfig().getIssuer(), credentials, uaaPrincipal.getName());
model.addAttribute("qrurl", url);
model.addAttribute("identity_zone", IdentityZoneHolder.get().getName());
return "mfa/qr_code";
}
}
use of org.cloudfoundry.identity.uaa.mfa.MfaProvider in project uaa by cloudfoundry.
the class TotpMfaEndpoint method manualRegistration.
@RequestMapping(value = { "/manual" }, method = RequestMethod.GET)
public String manualRegistration(Model model, @ModelAttribute("uaaMfaCredentials") UserGoogleMfaCredentials credentials) throws UaaPrincipalIsNotInSession {
UaaPrincipal uaaPrincipal = getSessionAuthPrincipal();
MfaProvider provider = getMfaProvider();
if (mfaCredentialsProvisioning.activeUserCredentialExists(uaaPrincipal.getId(), provider.getId())) {
return "redirect:/login/mfa/verify";
} else {
model.addAttribute("issuer", provider.getConfig().getIssuer());
model.addAttribute("username", uaaPrincipal.getName());
model.addAttribute("mfa_secret", credentials.getSecretKey());
model.addAttribute("identity_zone", IdentityZoneHolder.get().getName());
return "mfa/manual_registration";
}
}
use of org.cloudfoundry.identity.uaa.mfa.MfaProvider in project uaa by cloudfoundry.
the class MfaProviderEndpointsIntegrationTests method createMfaProviderInZone.
@Test
public void createMfaProviderInZone() throws Exception {
ClientCredentialsResourceDetails adminResource = IntegrationTestUtils.getClientCredentialsResource(baseUrl, new String[0], "admin", "adminsecret");
RestTemplate adminClient = IntegrationTestUtils.getClientCredentialsTemplate(adminResource);
IdentityZone mfaZone = IntegrationTestUtils.createZoneOrUpdateSubdomain(adminClient, baseUrl, "testzone1", "testzone1", null);
String zoneUrl = baseUrl.replace("localhost", mfaZone.getSubdomain() + ".localhost");
String zoneAdminToken = IntegrationTestUtils.getZoneAdminToken(baseUrl, serverRunning, mfaZone.getId());
BaseClientDetails zoneClient = new BaseClientDetails("mfaAdmin", null, "", "client_credentials", "uaa.admin");
zoneClient.setClientSecret("secret");
IntegrationTestUtils.createClientAsZoneAdmin(zoneAdminToken, baseUrl, mfaZone.getId(), zoneClient);
String inZoneAdminToken = IntegrationTestUtils.getClientCredentialsToken(zoneUrl, "mfaAdmin", "secret");
MfaProvider result = IntegrationTestUtils.createGoogleMfaProvider(zoneUrl, inZoneAdminToken, mfaProvider, "");
assertTrue("id is not empty", StringUtils.hasText(result.getId()));
}
Aggregations