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