Search in sources :

Example 1 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator 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 RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class MfaCheckerTests method setUp.

@BeforeEach
void setUp() {
    randomValueStringGenerator = new RandomValueStringGenerator();
    identityZone = MultitenancyFixture.identityZone(randomValueStringGenerator.generate(), randomValueStringGenerator.generate());
    mockIdentityZoneProvisioning = mock(IdentityZoneProvisioning.class);
    when(mockIdentityZoneProvisioning.retrieve(any())).thenReturn(identityZone);
    mfaChecker = new MfaChecker(mockIdentityZoneProvisioning);
}
Also used : IdentityZoneProvisioning(org.cloudfoundry.identity.uaa.zone.IdentityZoneProvisioning) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 3 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class MfaProviderEndpointsTest method testDeleteMFaProvider.

@Test
public void testDeleteMFaProvider() {
    ApplicationEventPublisher publisher = mock(ApplicationEventPublisher.class);
    endpoint.setApplicationEventPublisher(publisher);
    MfaProvider<GoogleMfaProviderConfig> providerToDelete = constructGoogleProvider();
    String id = new RandomValueStringGenerator(5).generate();
    when(provisioning.retrieve(eq(id), anyString())).thenReturn(providerToDelete);
    ResponseEntity<MfaProvider> mfaDeleteResponse = endpoint.deleteMfaProviderById(id);
    assertEquals(providerToDelete, mfaDeleteResponse.getBody());
    ArgumentCaptor<EntityDeletedEvent> entityDeletedCaptor = ArgumentCaptor.forClass(EntityDeletedEvent.class);
    verify(provisioning, times(1)).retrieve(id, IdentityZoneHolder.get().getId());
    verify(publisher, times(1)).publishEvent(entityDeletedCaptor.capture());
    assertEquals(providerToDelete.getId(), ((MfaProvider) (entityDeletedCaptor.getAllValues().get(0)).getDeleted()).getId());
}
Also used : ApplicationEventPublisher(org.springframework.context.ApplicationEventPublisher) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) EntityDeletedEvent(org.cloudfoundry.identity.uaa.audit.event.EntityDeletedEvent) Test(org.junit.Test)

Example 4 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class MfaProviderEndpointsTest method testDeleteActiveProviderThrowsException.

@Test
public void testDeleteActiveProviderThrowsException() {
    MfaProvider<GoogleMfaProviderConfig> providerToDelete = constructGoogleProvider();
    String id = new RandomValueStringGenerator(5).generate();
    when(provisioning.retrieve(eq(id), anyString())).thenReturn(providerToDelete);
    IdentityZoneHolder.get().getConfig().getMfaConfig().setEnabled(true).setProviderName(providerToDelete.getName());
    expection.expect(MfaAlreadyExistsException.class);
    expection.expectMessage("MFA provider is currently active on zone: " + IdentityZoneHolder.get().getId() + ". Please deactivate it from the zone or set another MFA provider");
    endpoint.deleteMfaProviderById(id);
    IdentityZoneHolder.get().getConfig().getMfaConfig().setProviderName(null);
}
Also used : ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator) Test(org.junit.Test)

Example 5 with RandomValueStringGenerator

use of org.springframework.security.oauth2.common.util.RandomValueStringGenerator in project uaa by cloudfoundry.

the class GeneralMfaProviderValidatorTest method createValidGoogleMfaProvider.

private MfaProvider createValidGoogleMfaProvider() {
    MfaProvider<GoogleMfaProviderConfig> res = new MfaProvider();
    res.setName(new RandomValueStringGenerator(5).generate()).setConfig(createValidGoogleMfaConfig()).setIdentityZoneId(IdentityZone.getUaaZoneId()).setType(MfaProvider.MfaProviderType.GOOGLE_AUTHENTICATOR);
    return res;
}
Also used : RandomValueStringGenerator(org.springframework.security.oauth2.common.util.RandomValueStringGenerator)

Aggregations

RandomValueStringGenerator (org.springframework.security.oauth2.common.util.RandomValueStringGenerator)271 Test (org.junit.jupiter.api.Test)111 Matchers.containsString (org.hamcrest.Matchers.containsString)92 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)81 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)76 Test (org.junit.Test)52 BeforeEach (org.junit.jupiter.api.BeforeEach)45 IdentityZone (org.cloudfoundry.identity.uaa.zone.IdentityZone)40 MockHttpServletRequestBuilder (org.springframework.test.web.servlet.request.MockHttpServletRequestBuilder)36 RestTemplate (org.springframework.web.client.RestTemplate)34 IdentityProvider (org.cloudfoundry.identity.uaa.provider.IdentityProvider)30 SamlIdentityProviderDefinition (org.cloudfoundry.identity.uaa.provider.SamlIdentityProviderDefinition)29 MvcResult (org.springframework.test.web.servlet.MvcResult)26 SetServerNameRequestPostProcessor (org.cloudfoundry.identity.uaa.util.SetServerNameRequestPostProcessor)16 IdentityZoneConfiguration (org.cloudfoundry.identity.uaa.zone.IdentityZoneConfiguration)16 ClientDetails (org.springframework.security.oauth2.provider.ClientDetails)16 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)15 ScimGroup (org.cloudfoundry.identity.uaa.scim.ScimGroup)14 KeyWithCertTest (org.cloudfoundry.identity.uaa.util.KeyWithCertTest)14 Matchers.isEmptyOrNullString (org.hamcrest.Matchers.isEmptyOrNullString)14