Search in sources :

Example 1 with GoogleMfaProviderConfig

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

the class TotpMfaEndpointTest method setup.

@Before
public void setup() {
    userId = new RandomValueStringGenerator(5).generate();
    userGoogleMfaCredentialsProvisioning = mock(UserGoogleMfaCredentialsProvisioning.class);
    mfaProviderProvisioning = mock(MfaProviderProvisioning.class);
    uaaAuthentication = mock(UaaAuthentication.class);
    mfaProvider = new MfaProvider();
    mfaProvider.setName("provider-name");
    mfaProvider.setId("provider_id1");
    mfaProvider.setConfig(new GoogleMfaProviderConfig());
    mfaProvider.setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR);
    otherMfaProvider = new MfaProvider();
    otherMfaProvider.setName("other-provider-name");
    otherMfaProvider.setId("provider_id2");
    otherMfaProvider.setConfig(new GoogleMfaProviderConfig());
    otherMfaProvider.setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR);
    mockSuccessHandler = mock(SavedRequestAwareAuthenticationSuccessHandler.class);
    SecurityContextHolder.getContext().setAuthentication(uaaAuthentication);
    publisher = mock(ApplicationEventPublisher.class);
    eventCaptor = ArgumentCaptor.forClass(ApplicationEvent.class);
    doNothing().when(publisher).publishEvent(eventCaptor.capture());
    userDb = mock(UaaUserDatabase.class);
    mockMfaPolicy = mock(CommonLoginPolicy.class);
    when(mockMfaPolicy.isAllowed(anyString())).thenReturn(new LoginPolicy.Result(true, 0));
    endpoint = new TotpMfaEndpoint(userGoogleMfaCredentialsProvisioning, mfaProviderProvisioning, "/login/mfa/completed", userDb, mockMfaPolicy);
    endpoint.setApplicationEventPublisher(publisher);
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) CommonLoginPolicy(org.cloudfoundry.identity.uaa.authentication.manager.CommonLoginPolicy) MfaProviderProvisioning(org.cloudfoundry.identity.uaa.mfa.MfaProviderProvisioning) ApplicationEvent(org.springframework.context.ApplicationEvent) GoogleMfaProviderConfig(org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig) UaaUserDatabase(org.cloudfoundry.identity.uaa.user.UaaUserDatabase) UserGoogleMfaCredentialsProvisioning(org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentialsProvisioning) UaaAuthentication(org.cloudfoundry.identity.uaa.authentication.UaaAuthentication) SavedRequestAwareAuthenticationSuccessHandler(org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler) ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) CommonLoginPolicy(org.cloudfoundry.identity.uaa.authentication.manager.CommonLoginPolicy) LoginPolicy(org.cloudfoundry.identity.uaa.authentication.manager.LoginPolicy) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) Before(org.junit.Before)

Example 2 with GoogleMfaProviderConfig

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

the class ScimUserEndpointsMockMvcTests method createMfaProvider.

private MfaProvider createMfaProvider(String identityZoneId) {
    String index = generator.generate();
    String mfaProviderId = "mfaProviderId" + index;
    String mfaProviderName = "mfaProvider" + index;
    MfaProvider provider = new MfaProvider().setName(mfaProviderName).setId(mfaProviderId).setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR).setConfig(new GoogleMfaProviderConfig()).setIdentityZoneId(identityZoneId);
    mfaProviderProvisioning.create(provider, identityZoneId);
    return provider;
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) GoogleMfaProviderConfig(org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig)

Example 3 with GoogleMfaProviderConfig

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

the class MfaProviderEndpointsIntegrationTests method setup.

@Before
public void setup() throws Exception {
    adminToken = IntegrationTestUtils.getZoneAdminToken(baseUrl, serverRunning);
    mfaProvider = new MfaProvider();
    mfaProvider.setConfig(new GoogleMfaProviderConfig());
    mfaProvider.setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR);
    mfaProvider.setName("testMfaProvider");
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) GoogleMfaProviderConfig(org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig) Before(org.junit.Before)

Example 4 with GoogleMfaProviderConfig

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

the class MockMvcUtils method createMfaProvider.

public static MfaProvider createMfaProvider(ApplicationContext context, IdentityZone zone) {
    String zoneId = zone.getId();
    MfaProvider provider = new MfaProvider();
    provider.setName(new RandomValueStringGenerator(5).generate().toLowerCase());
    provider.setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR);
    provider.setIdentityZoneId(zoneId);
    provider.setConfig(new GoogleMfaProviderConfig());
    provider.getConfig().setIssuer(zone.getName());
    MfaProviderProvisioning provisioning = context.getBean(MfaProviderProvisioning.class);
    try {
        return provisioning.create(provider, zoneId);
    } catch (MfaAlreadyExistsException x) {
        return provisioning.update(provider, zoneId);
    }
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) MfaAlreadyExistsException(org.cloudfoundry.identity.uaa.mfa.exception.MfaAlreadyExistsException) MfaProviderProvisioning(org.cloudfoundry.identity.uaa.mfa.MfaProviderProvisioning) GoogleMfaProviderConfig(org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator)

Example 5 with GoogleMfaProviderConfig

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

the class AbstractLdapMockMvcTest method testLdapAuthenticationWithMfa.

@Test
void testLdapAuthenticationWithMfa() throws Exception {
    String zoneId = zone.getZone().getIdentityZone().getId();
    // create mfa provider
    MfaProvider<GoogleMfaProviderConfig> mfaProvider = new MfaProvider();
    mfaProvider.setName(new RandomValueStringGenerator(5).generate());
    mfaProvider.setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR);
    mfaProvider.setIdentityZoneId(zone.getZone().getIdentityZone().getId());
    mfaProvider.setConfig((GoogleMfaProviderConfig) new GoogleMfaProviderConfig().setIssuer("issuer"));
    mfaProvider = getWebApplicationContext().getBean(JdbcMfaProviderProvisioning.class).create(mfaProvider, zoneId);
    zone.getZone().getIdentityZone().getConfig().setMfaConfig(new MfaConfig().setEnabled(true).setProviderName(mfaProvider.getName()));
    IdentityZone newZone = getWebApplicationContext().getBean(JdbcIdentityZoneProvisioning.class).update(zone.getZone().getIdentityZone());
    assertEquals(mfaProvider.getName(), newZone.getConfig().getMfaConfig().getProviderName());
    ResultActions actions = performMfaRegistrationInZone("marissa7", "ldap7", getMockMvc(), host, new String[] { "ext", "pwd" }, new String[] { "ext", "pwd", "mfa", "otp" });
    actions.andExpect(status().isOk()).andExpect(view().name("home"));
}
Also used : MfaProvider(org.cloudfoundry.identity.uaa.mfa.MfaProvider) GoogleMfaProviderConfig(org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) ResultActions(org.springframework.test.web.servlet.ResultActions) Test(org.junit.jupiter.api.Test)

Aggregations

GoogleMfaProviderConfig (org.cloudfoundry.identity.uaa.mfa.GoogleMfaProviderConfig)19 Test (org.junit.jupiter.api.Test)13 MfaProvider (org.cloudfoundry.identity.uaa.mfa.MfaProvider)11 RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)8 Matchers.containsString (org.hamcrest.Matchers.containsString)6 MfaProviderProvisioning (org.cloudfoundry.identity.uaa.mfa.MfaProviderProvisioning)4 MockMvcUtils.constructGoogleMfaProvider (org.cloudfoundry.identity.uaa.mock.util.MockMvcUtils.constructGoogleMfaProvider)4 Snippet (org.springframework.restdocs.snippet.Snippet)4 MvcResult (org.springframework.test.web.servlet.MvcResult)4 ResultActions (org.springframework.test.web.servlet.ResultActions)4 JdbcMfaProviderProvisioning (org.cloudfoundry.identity.uaa.mfa.JdbcMfaProviderProvisioning)2 KeyWithCertTest (org.cloudfoundry.identity.uaa.util.KeyWithCertTest)2 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)2 Before (org.junit.Before)2 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)2 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)2 FieldDescriptor (org.springframework.restdocs.payload.FieldDescriptor)2 BouncyCastleProvider (org.bouncycastle.jce.provider.BouncyCastleProvider)1 UaaAuthentication (org.cloudfoundry.identity.uaa.authentication.UaaAuthentication)1 CommonLoginPolicy (org.cloudfoundry.identity.uaa.authentication.manager.CommonLoginPolicy)1