UserGoogleMfaCredentialsProvisioning implements ICredentialRepository { public boolean isFirstTimeMFAUser(UaaPrincipal uaaPrincipal) { if (uaaPrincipal == null) throw new RuntimeException("User information is not present in session."); return getUserGoogleMfaCredentials(uaaPrincipal.getId()) == null; }  void setAuthenticator(GoogleAuthenticator authenticator); UserGoogleMfaCredentials getUserGoogleMfaCredentials(String userId); UserGoogleMfaCredentials getUserGoogleMfaCredentials(String userId, String providerId); @Override String getSecretKey(String userId); String getOtpAuthURL(String qrIssuer, UserGoogleMfaCredentials credentials, String userName); UserGoogleMfaCredentials createUserCredentials(String userId); boolean isValidCode(UserGoogleMfaCredentials credentials, Integer code); @Override void saveUserCredentials(String userId, String secretKey, int validationCode, List<Integer> scratchCodes); void saveUserCredentials(UserGoogleMfaCredentials credentials); boolean activeUserCredentialExists(String userId, String providerId); boolean isFirstTimeMFAUser(UaaPrincipal uaaPrincipal); void setJdbcProvisioner(UserMfaCredentialsProvisioning<UserGoogleMfaCredentials> jdbcProvisioner); void setMfaProviderProvisioning(MfaProviderProvisioning mfaProviderProvisioning);  }
@Test void isFirstTimeMFAUser() { UaaPrincipal uaaPrincipal = mock(UaaPrincipal.class); assertTrue(provisioner.isFirstTimeMFAUser(uaaPrincipal)); }
@Test void isFirstTimeMFAUser_CredsAreNotInSession() { UaaPrincipal uaaPrincipal = mock(UaaPrincipal.class); UserGoogleMfaCredentials creds = creds(); when(jdbcProvisioner.retrieve(any(),any())).thenReturn(creds); assertFalse(provisioner.isFirstTimeMFAUser(uaaPrincipal)); }
@Test void isFirstTimeMFAUser_failsIfNotParitallyLoggedIn() { assertThrows(RuntimeException.class, () -> provisioner.isFirstTimeMFAUser(null)); }