use of jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials in project teamcity-rest by JetBrains.
the class TwoFactorSecretKeysUpdater method generateAndSetDraftCredentials.
/**
* Generates draft credentials to be confirmed for given user and writes them in temporary storage.
* Returns secret key, recovery keys and UUID for confirmation
*
* @param user owner of new credentials
* @return unconfirmed {@link TwoFactorCredentials}
*/
@NotNull
public TwoFactorCredentials generateAndSetDraftCredentials(@NotNull final SUser user) {
final String generatedKey = myGenerator.generateSecretKey();
final Set<String> generatedRecoveryKeys = myGenerator.generateRecoveryKeys();
final UUID uuid = myManager.addDraftCredentials(user, generatedKey, generatedRecoveryKeys);
return new TwoFactorCredentials(generatedKey, new TwoFactorRecoveryKeys(generatedRecoveryKeys), uuid);
}
use of jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials in project teamcity-rest by JetBrains.
the class TwoFactorRequestTest method testSetupAdminKey.
@Test
public void testSetupAdminKey() throws Throwable {
final SUser admin = createAdmin("admin");
myFixture.getSecurityContext().runAs(admin, new SecurityContextEx.RunAsAction() {
@Override
public void run() {
TwoFactorCredentials credentials = myRequest.setupTwoFactor();
myRequest.confirmTwoFactor(credentials.uuid.toString(), 0, new FakeHttpServletRequest());
assertNotNull(admin.getPropertyValue(SECRET_KEY_PROPERTY));
assertNotNull(admin.getPropertyValue(RECOVERY_KEY_PROPERTY));
}
});
}
use of jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials in project teamcity-rest by JetBrains.
the class TwoFactorRequestTest method testSetupUserKey.
@Test
public void testSetupUserKey() throws Throwable {
final SUser user = createUser("user");
myFixture.getSecurityContext().runAs(user, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
TwoFactorCredentials credentials = myRequest.setupTwoFactor();
myRequest.confirmTwoFactor(credentials.uuid.toString(), 0, new FakeHttpServletRequest());
assertNotNull(myFixture.getSecurityContext().runAsSystem(() -> user.getPropertyValue(SECRET_KEY_PROPERTY)));
assertNotNull(myFixture.getSecurityContext().runAsSystem(() -> user.getPropertyValue(RECOVERY_KEY_PROPERTY)));
}
});
}
use of jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials in project teamcity-rest by JetBrains.
the class TwoFactorRequestTest method testKeyRegeneration.
@Test
public void testKeyRegeneration() throws Throwable {
final SUser user = createUser("user");
myFixture.getSecurityContext().runAs(user, new SecurityContextEx.RunAsAction() {
@Override
public void run() throws Throwable {
TwoFactorCredentials credentials = myRequest.setupTwoFactor();
myRequest.confirmTwoFactor(credentials.uuid.toString(), 0, new FakeHttpServletRequest());
final String hashedRecovery = myFixture.getSecurityContext().runAsSystem(() -> user.getPropertyValue(RECOVERY_KEY_PROPERTY));
myRequest.serveRecoveryKeys();
final String newHashedRecovery = myFixture.getSecurityContext().runAsSystem(() -> user.getPropertyValue(RECOVERY_KEY_PROPERTY));
Assert.assertNotEquals(hashedRecovery, newHashedRecovery);
}
});
}
Aggregations