Search in sources :

Example 11 with MfaProvider

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());
}
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) Matchers.containsString(org.hamcrest.Matchers.containsString) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) MvcResult(org.springframework.test.web.servlet.MvcResult) Test(org.junit.jupiter.api.Test)

Example 12 with MfaProvider

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;
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) MockHttpServletRequestBuilder(org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder) GoogleMfaProviderConfig(org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) MockHttpServletResponse(org.springframework.mock.web.MockHttpServletResponse)

Example 13 with 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";
    }
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) UaaPrincipal(org.cloudfoundry.identity.uaa.authentication.UaaPrincipal)

Example 14 with MfaProvider

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";
    }
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) UaaPrincipal(org.cloudfoundry.identity.uaa.authentication.UaaPrincipal)

Example 15 with MfaProvider

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()));
}
Also used : BaseClientDetails(org.springframework.security.oauth2.provider.client.BaseClientDetails) MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) IdentityZone(org.cloudfoundry.identity.uaa.zone.IdentityZone) RestTemplate(org.springframework.web.client.RestTemplate) ClientCredentialsResourceDetails(org.springframework.security.oauth2.client.token.grant.client.ClientCredentialsResourceDetails) Test(org.junit.Test)

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