UserGoogleMfaCredentialsProvisioning implements ICredentialRepository { public boolean activeUserCredentialExists(String userId, String providerId) { return getUserGoogleMfaCredentials(userId, providerId)!=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 testActiveUserCredentialExists() { UserGoogleMfaCredentials creds = creds(); when(jdbcProvisioner.retrieve(anyString(), eq(mfaProvider.getId()))).thenReturn(creds); when(jdbcProvisioner.retrieve(anyString(), eq(otherMfaProvider.getId()))).thenThrow(UserMfaConfigDoesNotExistException.class); provisioner.saveUserCredentials(creds.getUserId(), creds.getSecretKey(), creds.getValidationCode(), creds.getScratchCodes()); assertTrue("user not persisted for mfa provider", provisioner.activeUserCredentialExists("jabbahut", mfaProvider.getId())); assertFalse("user persisted even though we switched mfaProvider", provisioner.activeUserCredentialExists("jabbahut", otherMfaProvider.getId())); }