Search in sources :

Example 1 with UaaUser

use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.

the class AuthenticationSuccessListener method onApplicationEvent.

protected void onApplicationEvent(UserAuthenticationSuccessEvent event, String zoneId) {
    UaaUser user = event.getUser();
    if (user.isLegacyVerificationBehavior() && !user.isVerified()) {
        scimUserProvisioning.verifyUser(user.getId(), -1, zoneId);
    }
    UaaAuthentication authentication = (UaaAuthentication) event.getAuthentication();
    authentication.setLastLoginSuccessTime(user.getLastLogonTime());
    scimUserProvisioning.updateLastLogonTime(user.getId(), zoneId);
}
Also used : UaaAuthentication(org.cloudfoundry.identity.uaa.authentication.UaaAuthentication) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser)

Example 2 with UaaUser

use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.

the class TotpMfaEndpointTest method testEmptyOTP.

@Test
public void testEmptyOTP() throws Exception {
    when(uaaAuthentication.getPrincipal()).thenReturn(new UaaPrincipal(userId, "Marissa", null, "uaa", null, null), null, null);
    when(mfaProviderProvisioning.retrieveByName(mfaProvider.getName(), IdentityZoneHolder.get().getId())).thenReturn(mfaProvider);
    when(userDb.retrieveUserByName("Marissa", "uaa")).thenReturn(new UaaUser(new UaaUserPrototype().withUsername("Marissa").withOrigin("uaa").withId("1234").withEmail("marissa@example.com")));
    IdentityZoneHolder.get().getConfig().getMfaConfig().setEnabled(true).setProviderName(mfaProvider.getName());
    SessionStatus sessionStatus = mock(SessionStatus.class);
    ModelAndView returnView = endpoint.validateCode(mock(Model.class), "", mock(UserGoogleMfaCredentials.class), new MockHttpServletRequest(), sessionStatus);
    assertEquals("mfa/enter_code", returnView.getViewName());
    verifyZeroInteractions(sessionStatus);
    verifyMfaEvent(MfaAuthenticationFailureEvent.class);
}
Also used : UaaPrincipal(org.cloudfoundry.identity.uaa.authentication.UaaPrincipal) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) SessionStatus(org.springframework.web.bind.support.SessionStatus) UserGoogleMfaCredentials(org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials) ModelAndView(org.springframework.web.servlet.ModelAndView) Model(org.springframework.ui.Model) UaaUserPrototype(org.cloudfoundry.identity.uaa.user.UaaUserPrototype) Test(org.junit.Test)

Example 3 with UaaUser

use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.

the class TotpMfaEndpointTest method testValidOTPActivatesUser.

@Test
public void testValidOTPActivatesUser() throws Exception {
    int code = 1234;
    when(userGoogleMfaCredentialsProvisioning.isValidCode(ArgumentMatchers.any(UserGoogleMfaCredentials.class), eq(code))).thenReturn(true);
    when(uaaAuthentication.getPrincipal()).thenReturn(new UaaPrincipal(userId, "Marissa", null, "uaa", null, null), null, null);
    when(mfaProviderProvisioning.retrieveByName(mfaProvider.getName(), IdentityZoneHolder.get().getId())).thenReturn(mfaProvider);
    when(userDb.retrieveUserByName("Marissa", "uaa")).thenReturn(new UaaUser(new UaaUserPrototype().withUsername("Marissa").withOrigin("uaa").withId("1234").withEmail("marissa@example.com")));
    IdentityZoneHolder.get().getConfig().getMfaConfig().setEnabled(true).setProviderName(mfaProvider.getName());
    SessionStatus sessionStatus = mock(SessionStatus.class);
    endpoint.validateCode(mock(Model.class), Integer.toString(code), mock(UserGoogleMfaCredentials.class), new MockHttpServletRequest(), sessionStatus);
    verify(userGoogleMfaCredentialsProvisioning).saveUserCredentials(ArgumentMatchers.any(UserGoogleMfaCredentials.class));
    verify(sessionStatus).setComplete();
    verifyMfaEvent(MfaAuthenticationSuccessEvent.class);
}
Also used : UaaPrincipal(org.cloudfoundry.identity.uaa.authentication.UaaPrincipal) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UserGoogleMfaCredentials(org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) SessionStatus(org.springframework.web.bind.support.SessionStatus) Model(org.springframework.ui.Model) UaaUserPrototype(org.cloudfoundry.identity.uaa.user.UaaUserPrototype) Test(org.junit.Test)

Example 4 with UaaUser

use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.

the class TotpMfaEndpointTest method testValidOTPReturnsErrorWhenLockedOut.

@Test
public void testValidOTPReturnsErrorWhenLockedOut() throws Exception {
    exception.expect(AuthenticationPolicyRejectionException.class);
    int code = 1234;
    when(mockMfaPolicy.isAllowed(anyString())).thenReturn(new LoginPolicy.Result(false, 0));
    when(userGoogleMfaCredentialsProvisioning.isValidCode(ArgumentMatchers.any(UserGoogleMfaCredentials.class), eq(code))).thenReturn(true);
    when(uaaAuthentication.getPrincipal()).thenReturn(new UaaPrincipal(userId, "Marissa", null, "uaa", null, null), null, null);
    when(mfaProviderProvisioning.retrieveByName(mfaProvider.getName(), IdentityZoneHolder.get().getId())).thenReturn(mfaProvider);
    when(userDb.retrieveUserByName("Marissa", "uaa")).thenReturn(new UaaUser(new UaaUserPrototype().withUsername("Marissa").withOrigin("uaa").withId("1234").withEmail("marissa@example.com")));
    IdentityZoneHolder.get().getConfig().getMfaConfig().setEnabled(true).setProviderName(mfaProvider.getName());
    SessionStatus sessionStatus = mock(SessionStatus.class);
    endpoint.validateCode(mock(Model.class), Integer.toString(code), mock(UserGoogleMfaCredentials.class), new MockHttpServletRequest(), sessionStatus);
    verifyZeroInteractions(sessionStatus);
    verifyMfaEvent(MfaAuthenticationFailureEvent.class);
}
Also used : UaaPrincipal(org.cloudfoundry.identity.uaa.authentication.UaaPrincipal) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UserGoogleMfaCredentials(org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) SessionStatus(org.springframework.web.bind.support.SessionStatus) Model(org.springframework.ui.Model) CommonLoginPolicy(org.cloudfoundry.identity.uaa.authentication.manager.CommonLoginPolicy) LoginPolicy(org.cloudfoundry.identity.uaa.authentication.manager.LoginPolicy) UaaUserPrototype(org.cloudfoundry.identity.uaa.user.UaaUserPrototype) Test(org.junit.Test)

Example 5 with UaaUser

use of org.cloudfoundry.identity.uaa.user.UaaUser in project uaa by cloudfoundry.

the class TotpMfaEndpointTest method testValidOTPTakesToHomePage.

@Test
public void testValidOTPTakesToHomePage() throws Exception {
    int code = 1234;
    when(userGoogleMfaCredentialsProvisioning.isValidCode(ArgumentMatchers.any(UserGoogleMfaCredentials.class), eq(code))).thenReturn(true);
    when(uaaAuthentication.getPrincipal()).thenReturn(new UaaPrincipal(userId, "Marissa", null, "uaa", null, null), null, null);
    when(mfaProviderProvisioning.retrieveByName(mfaProvider.getName(), IdentityZoneHolder.get().getId())).thenReturn(mfaProvider);
    when(userDb.retrieveUserByName("Marissa", "uaa")).thenReturn(new UaaUser(new UaaUserPrototype().withUsername("Marissa").withOrigin("uaa").withId("1234").withEmail("marissa@example.com")));
    IdentityZoneHolder.get().getConfig().getMfaConfig().setEnabled(true).setProviderName(mfaProvider.getName());
    SessionStatus sessionStatus = mock(SessionStatus.class);
    ModelAndView returnView = endpoint.validateCode(mock(Model.class), Integer.toString(code), mock(UserGoogleMfaCredentials.class), new MockHttpServletRequest(), sessionStatus);
    assertEquals("/login/mfa/completed", ((RedirectView) returnView.getView()).getUrl());
    verify(sessionStatus, times(1)).setComplete();
    verifyMfaEvent(MfaAuthenticationSuccessEvent.class);
}
Also used : UaaPrincipal(org.cloudfoundry.identity.uaa.authentication.UaaPrincipal) MockHttpServletRequest(org.springframework.mock.web.MockHttpServletRequest) UserGoogleMfaCredentials(org.cloudfoundry.identity.uaa.mfa.UserGoogleMfaCredentials) UaaUser(org.cloudfoundry.identity.uaa.user.UaaUser) SessionStatus(org.springframework.web.bind.support.SessionStatus) ModelAndView(org.springframework.web.servlet.ModelAndView) Model(org.springframework.ui.Model) UaaUserPrototype(org.cloudfoundry.identity.uaa.user.UaaUserPrototype) Test(org.junit.Test)

Aggregations

UaaUser (org.cloudfoundry.identity.uaa.user.UaaUser)148 Test (org.junit.jupiter.api.Test)73 UaaAuthentication (org.cloudfoundry.identity.uaa.authentication.UaaAuthentication)38 UaaPrincipal (org.cloudfoundry.identity.uaa.authentication.UaaPrincipal)29 UaaUserPrototype (org.cloudfoundry.identity.uaa.user.UaaUserPrototype)26 ScimUser (org.cloudfoundry.identity.uaa.scim.ScimUser)24 Test (org.junit.Test)23 HashMap (java.util.HashMap)22 Date (java.util.Date)20 UaaUserMatcher.aUaaUser (org.cloudfoundry.identity.uaa.user.UaaUserMatcher.aUaaUser)17 Authentication (org.springframework.security.core.Authentication)15 OAuth2Authentication (org.springframework.security.oauth2.provider.OAuth2Authentication)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 UaaUserDatabase (org.cloudfoundry.identity.uaa.user.UaaUserDatabase)11 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)11 BaseClientDetails (org.springframework.security.oauth2.provider.client.BaseClientDetails)11 ModelTestUtils.getResourceAsString (org.cloudfoundry.identity.uaa.test.ModelTestUtils.getResourceAsString)10 Mockito.anyString (org.mockito.Mockito.anyString)9 UsernameNotFoundException (org.springframework.security.core.userdetails.UsernameNotFoundException)8 ArrayList (java.util.ArrayList)7