Search in sources :

Example 1 with TwoFactorCredentials

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);
}
Also used : TwoFactorRecoveryKeys(jetbrains.buildServer.server.rest.model.user.TwoFactorRecoveryKeys) UUID(java.util.UUID) TwoFactorCredentials(jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with TwoFactorCredentials

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));
        }
    });
}
Also used : FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) SecurityContextEx(jetbrains.buildServer.serverSide.SecurityContextEx) SUser(jetbrains.buildServer.users.SUser) TwoFactorCredentials(jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 3 with TwoFactorCredentials

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)));
        }
    });
}
Also used : FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) SecurityContextEx(jetbrains.buildServer.serverSide.SecurityContextEx) SUser(jetbrains.buildServer.users.SUser) TwoFactorCredentials(jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Example 4 with TwoFactorCredentials

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);
        }
    });
}
Also used : FakeHttpServletRequest(jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest) SecurityContextEx(jetbrains.buildServer.serverSide.SecurityContextEx) SUser(jetbrains.buildServer.users.SUser) TwoFactorCredentials(jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials) BaseFinderTest(jetbrains.buildServer.server.rest.data.BaseFinderTest) Test(org.testng.annotations.Test)

Aggregations

TwoFactorCredentials (jetbrains.buildServer.server.rest.model.user.TwoFactorCredentials)4 FakeHttpServletRequest (jetbrains.buildServer.controllers.fakes.FakeHttpServletRequest)3 BaseFinderTest (jetbrains.buildServer.server.rest.data.BaseFinderTest)3 SecurityContextEx (jetbrains.buildServer.serverSide.SecurityContextEx)3 SUser (jetbrains.buildServer.users.SUser)3 Test (org.testng.annotations.Test)3 UUID (java.util.UUID)1 TwoFactorRecoveryKeys (jetbrains.buildServer.server.rest.model.user.TwoFactorRecoveryKeys)1 NotNull (org.jetbrains.annotations.NotNull)1