You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ha...@apache.org on 2022/11/03 09:10:15 UTC
[cloudstack] branch 2FA updated (5f1112b483e -> c820e685566)
This is an automated email from the ASF dual-hosted git repository.
harikrishna pushed a change to branch 2FA
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
from 5f1112b483e Added 2fa info to login response
new 62c0c3861ad UI improvements
new b1be581f967 Static Pin changes
new c820e685566 partial changes on login page
The 3 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../java/com/cloud/utils/db/GenericDaoBase.java | 3 -
.../auth/StaticPinUserTwoFactorAuthenticator.java | 2 +-
.../auth/SetupUserTwoFactorAuthenticationCmd.java | 8 +-
...ValidateUserTwoFactorAuthenticationCodeCmd.java | 9 +-
.../java/com/cloud/user/AccountManagerImpl.java | 5 +
ui/public/locales/en.json | 9 +-
ui/src/components/page/GlobalLayout.vue | 10 +-
ui/src/config/router.js | 19 +--
ui/src/store/modules/user.js | 1 +
ui/src/views/auth/Login.vue | 19 ++-
ui/src/views/dashboard/Dashboard.vue | 5 +-
ui/src/views/dashboard/TwoFa.vue | 25 +++-
ui/src/views/iam/RegisterTwoFactorAuth.vue | 137 ++++++++++++++++-----
13 files changed, 172 insertions(+), 80 deletions(-)
[cloudstack] 03/03: partial changes on login page
Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
harikrishna pushed a commit to branch 2FA
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit c820e685566026c13a783edb1ecc40d9d633c39e
Author: Harikrishna Patnala <ha...@gmail.com>
AuthorDate: Thu Nov 3 14:39:45 2022 +0530
partial changes on login page
---
ui/src/components/page/GlobalLayout.vue | 10 +++-------
ui/src/config/router.js | 19 ++++++++++---------
ui/src/store/modules/user.js | 1 +
ui/src/views/auth/Login.vue | 19 +++++++++----------
ui/src/views/dashboard/Dashboard.vue | 5 +----
ui/src/views/dashboard/TwoFa.vue | 6 +++++-
6 files changed, 29 insertions(+), 31 deletions(-)
diff --git a/ui/src/components/page/GlobalLayout.vue b/ui/src/components/page/GlobalLayout.vue
index d55f19e49eb..3f8779d6062 100644
--- a/ui/src/components/page/GlobalLayout.vue
+++ b/ui/src/components/page/GlobalLayout.vue
@@ -17,8 +17,7 @@
<template>
<a-layout class="layout" :class="[device]">
-
- <a-affix style="z-index: 200" v-if="$store.getters.loginFlag">
+ <a-affix style="z-index: 200">
<template v-if="isSideMenu()">
<a-drawer
v-if="isMobile()"
@@ -80,7 +79,7 @@
<a-layout :class="[layoutMode, `content-width-${contentWidth}`]" :style="{ paddingLeft: contentPaddingLeft, minHeight: '100vh' }">
<!-- layout header -->
- <a-affix style="z-index: 100" v-if="$store.getters.loginFlag">
+ <a-affix style="z-index: 100">
<global-header
:mode="layoutMode"
:menus="menus"
@@ -158,10 +157,7 @@ export default {
return '0'
}
if (this.sidebarOpened) {
- if (this.$store.getters.loginFlag) {
- return '256px'
- }
- return '0'
+ return '256px'
}
return '80px'
}
diff --git a/ui/src/config/router.js b/ui/src/config/router.js
index 38fb05a34ec..e45977c4f64 100644
--- a/ui/src/config/router.js
+++ b/ui/src/config/router.js
@@ -223,15 +223,6 @@ export function asyncRouterMap () {
},
component: () => import('@/views/dashboard/Dashboard')
},
- // {
- // path: '/2FA',
- // name: 'TwoFA',
- // meta: {
- // title: 'label.2fa',
- // hidden: true
- // },
- // component: () => import('@/views/dashboard/2FA')
- // },
generateRouterMap(compute),
generateRouterMap(storage),
@@ -250,6 +241,16 @@ export function asyncRouterMap () {
generateRouterMap(quota),
generateRouterMap(cloudian),
+ {
+ path: '/2FA',
+ name: 'TwoFa',
+ meta: {
+ title: 'label.2fa',
+ hidden: true
+ },
+ component: () => import('@/views/dashboard/TwoFa')
+ },
+
{
path: '/exception',
name: 'exception',
diff --git a/ui/src/store/modules/user.js b/ui/src/store/modules/user.js
index 262ac7676aa..5a83e9bb1da 100644
--- a/ui/src/store/modules/user.js
+++ b/ui/src/store/modules/user.js
@@ -181,6 +181,7 @@ const user = {
commit('SET_DOMAIN_STORE', {})
commit('SET_LOGOUT_FLAG', false)
// TODO: get value from session and set - currently hard-coding it
+ // commit('SET_2FA_ENABLED', (result.is2faenabled === 'true'))
commit('SET_2FA_ENABLED', true)
commit('SET_LOGIN_FLAG', false)
notification.destroy()
diff --git a/ui/src/views/auth/Login.vue b/ui/src/views/auth/Login.vue
index e9f34499d07..983ad03cd10 100644
--- a/ui/src/views/auth/Login.vue
+++ b/ui/src/views/auth/Login.vue
@@ -278,15 +278,7 @@ export default {
loginParams.domain = '/'
}
this.Login(loginParams)
- .then((res) => {
- if (store.getters.twoFaEnabled) {
- this.$notification.destroy()
- this.$store.commit('SET_COUNT_NOTIFY', 0)
- this.$router.push({ path: '/dashboard' }).catch(() => {})
- } else {
- this.loginSuccess(res)
- }
- })
+ .then((res) => this.loginSuccess(res))
.catch(err => {
this.requestFailed(err)
this.state.loginBtn = false
@@ -307,7 +299,14 @@ export default {
this.$notification.destroy()
this.$store.commit('SET_COUNT_NOTIFY', 0)
this.$store.commit('SET_LOGIN_FLAG', true)
- this.$router.push({ path: '/dashboard' }).catch(() => {})
+ console.log(store.getters.twoFaEnabled)
+ if (store.getters.twoFaEnabled === true) {
+ console.log('hari1')
+ this.$router.push({ path: '/2FA' }).catch(() => {})
+ } else {
+ console.log('hari2')
+ this.$router.push({ path: '/dashboard' }).catch(() => {})
+ }
},
requestFailed (err) {
if (err && err.response && err.response.data && err.response.data.loginresponse) {
diff --git a/ui/src/views/dashboard/Dashboard.vue b/ui/src/views/dashboard/Dashboard.vue
index 325b3c1748e..e07b7735bdd 100644
--- a/ui/src/views/dashboard/Dashboard.vue
+++ b/ui/src/views/dashboard/Dashboard.vue
@@ -17,10 +17,7 @@
<template>
<div class="page-header-index-wide">
- <div v-if="!$store.getters.loginFlag">
- <two-fa />
- </div>
- <div v-else-if="showOnboarding">
+ <div v-if="showOnboarding">
<onboarding-dashboard />
</div>
<div v-else-if="$store.getters.userInfo.roletype === 'Admin' && !project">
diff --git a/ui/src/views/dashboard/TwoFa.vue b/ui/src/views/dashboard/TwoFa.vue
index eb95d638426..0f9e6017642 100644
--- a/ui/src/views/dashboard/TwoFa.vue
+++ b/ui/src/views/dashboard/TwoFa.vue
@@ -64,8 +64,8 @@ import { ref, reactive, toRaw } from 'vue'
export default {
name: 'TwoFa',
data () {
- console.log('here')
return {
+ twoFAresponse: false
}
},
created () {
@@ -84,6 +84,10 @@ export default {
const values = toRaw(this.form)
console.log(values.secretkey)
api('validateUserTwoFactorAuthenticationCode', { '2facode': values.secretkey }).then(response => {
+ this.twoFAresponse = true
+ if (this.twoFAresponse) {
+ this.$router.push({ path: '/dashboard' }).catch(() => {})
+ }
console.log(response)
}).catch(error => {
this.$notification.error({
[cloudstack] 01/03: UI improvements
Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
harikrishna pushed a commit to branch 2FA
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit 62c0c3861ad89868483d372db924cb1041e32849
Author: Harikrishna Patnala <ha...@gmail.com>
AuthorDate: Tue Nov 1 12:09:15 2022 +0530
UI improvements
---
.../auth/SetupUserTwoFactorAuthenticationCmd.java | 6 +-
...ValidateUserTwoFactorAuthenticationCodeCmd.java | 9 +-
ui/public/locales/en.json | 7 +-
ui/src/views/dashboard/TwoFa.vue | 19 +++-
ui/src/views/iam/RegisterTwoFactorAuth.vue | 116 ++++++++++++++++-----
5 files changed, 118 insertions(+), 39 deletions(-)
diff --git a/server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java b/server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java
index b5ab837863a..acce2cf3dfd 100644
--- a/server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java
+++ b/server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java
@@ -57,13 +57,15 @@ public class SetupUserTwoFactorAuthenticationCmd extends BaseCmd {
}
public Boolean getEnable() {
- return enable != null? true:enable;
+ return enable == null ? true : enable;
}
@Override
public void execute() throws ServerApiException {
UserTwoFactorAuthenticationSetupResponse response = accountManager.setupUserTwoFactorAuthentication(this);
- this.setResponseObject(response);
+ response.setObjectName("setup2fa");
+ response.setResponseName(getCommandName());
+ setResponseObject(response);
}
@Override
diff --git a/server/src/main/java/com/cloud/api/auth/ValidateUserTwoFactorAuthenticationCodeCmd.java b/server/src/main/java/com/cloud/api/auth/ValidateUserTwoFactorAuthenticationCodeCmd.java
index 413dec02e2a..a3405761eac 100644
--- a/server/src/main/java/com/cloud/api/auth/ValidateUserTwoFactorAuthenticationCodeCmd.java
+++ b/server/src/main/java/com/cloud/api/auth/ValidateUserTwoFactorAuthenticationCodeCmd.java
@@ -19,8 +19,8 @@ package com.cloud.api.auth;
import com.cloud.api.ApiServlet;
import com.cloud.api.response.ApiResponseSerializer;
import com.cloud.exception.CloudAuthenticationException;
-import com.cloud.user.Account;
import com.cloud.user.AccountManager;
+import com.cloud.user.UserAccount;
import org.apache.cloudstack.api.APICommand;
import org.apache.cloudstack.api.ApiConstants;
import org.apache.cloudstack.api.ApiErrorCode;
@@ -96,13 +96,12 @@ public class ValidateUserTwoFactorAuthenticationCodeCmd extends BaseCmd implemen
throw new ServerApiException(ApiErrorCode.ACCOUNT_ERROR, "Code for two factor authentication is required");
}
- Account owner = _accountService.getActiveAccountById(getEntityOwnerId());
- Long domainId = owner.getDomainId();
- Long accountId = owner.getAccountId();
+ final long currentUserId = (Long) session.getAttribute("userid");
+ final UserAccount currentUserAccount = _accountService.getUserAccountById(currentUserId);
String serializedResponse = null;
try {
- accountManager.verifyUsingTwoFactorAuthenticationCode(twoFactorAuthenticationCode, domainId, accountId);
+ accountManager.verifyUsingTwoFactorAuthenticationCode(twoFactorAuthenticationCode, currentUserAccount.getDomainId(), currentUserId);
SuccessResponse response = new SuccessResponse(getCommandName());
setResponseObject(response);
return ApiResponseSerializer.toSerializedString(response, responseType);
diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json
index c118c1f57da..013391290c0 100644
--- a/ui/public/locales/en.json
+++ b/ui/public/locales/en.json
@@ -136,7 +136,7 @@
"label.action.reboot.systemvm": "Reboot system VM",
"label.action.recover.volume": "Recover volume",
"label.action.recurring.snapshot": "Recurring snapshots",
-"label.action.register.2FA.user.auth": "Register user for 2FA authentication",
+"label.action.register.2FA.user.auth": "Register user for Two Factor Authentication",
"label.action.register.iso": "Register ISO",
"label.action.register.template": "Register template from URL",
"label.action.release.ip": "Release IP",
@@ -409,7 +409,6 @@
"label.compute.offerings": "Compute offerings",
"label.configuration": "Configuration",
"label.configure": "Configure",
-"label.configure.app": "Configure the App",
"label.configure.ldap": "Configure LDAP",
"label.configure.ovs": "Configure Ovs",
"label.configure.sticky.policy": "Configure sticky policy",
@@ -677,7 +676,7 @@
"label.endipv6": "IPv6 end IP",
"label.endpoint": "Endpoint",
"label.endport": "End port",
-"label.enter.code": "Enter 6-digit code",
+"label.enter.code": "Enter Authentication code to verify",
"label.enter.token": "Enter token",
"label.error": "Error",
"label.error.caught": "Error caught",
@@ -1525,6 +1524,7 @@
"label.select.ps": "Select primary storage",
"label.select.tier": "Select tier",
"label.select.zones": "Select zones",
+"label.select.2fa.provider": "Select the provider",
"label.self": "Mine",
"label.selfexecutable": "Self",
"label.semanticversion": "Semantic version",
@@ -1736,6 +1736,7 @@
"label.try.again": "Try again",
"label.tuesday": "Tuesday",
"label.two.factor.secret": "Your Two-factor secret",
+"label.two.factor.authentication": "Two Factor Authentication",
"label.type": "Type",
"label.type.id": "Type ID",
"label.ucs": "UCS",
diff --git a/ui/src/views/dashboard/TwoFa.vue b/ui/src/views/dashboard/TwoFa.vue
index 31fd375fe4e..eb95d638426 100644
--- a/ui/src/views/dashboard/TwoFa.vue
+++ b/ui/src/views/dashboard/TwoFa.vue
@@ -27,7 +27,7 @@
:src="$config.banner"
class="user-layout-logo"
alt="logo">
- <h1 style="text-align: center; font-size: 24px; color: gray"> two-factor authentication </h1>
+ <h1 style="text-align: center; font-size: 24px; color: gray"> {{ $t('label.two.factor.authentication') }} </h1>
<br />
<br />
<a-form
@@ -57,7 +57,9 @@
</a-form>
</template>
<script>
-import { ref, reactive } from 'vue'
+
+import { api } from '@/api'
+import { ref, reactive, toRaw } from 'vue'
export default {
name: 'TwoFa',
@@ -78,6 +80,19 @@ export default {
})
},
handleSubmit () {
+ this.formRef.value.validate().then(() => {
+ const values = toRaw(this.form)
+ console.log(values.secretkey)
+ api('validateUserTwoFactorAuthenticationCode', { '2facode': values.secretkey }).then(response => {
+ console.log(response)
+ }).catch(error => {
+ this.$notification.error({
+ message: this.$t('message.request.failed'),
+ description: (error.response && error.response.headers && error.response.headers['x-description']) || error.message
+ })
+ })
+ })
+
// Add logic to set loginFlag to true
this.$store.dispatch('SetLoginFlag', true)
}
diff --git a/ui/src/views/iam/RegisterTwoFactorAuth.vue b/ui/src/views/iam/RegisterTwoFactorAuth.vue
index c9378772fb4..3ffb9f5b391 100644
--- a/ui/src/views/iam/RegisterTwoFactorAuth.vue
+++ b/ui/src/views/iam/RegisterTwoFactorAuth.vue
@@ -16,36 +16,71 @@
// under the License.
<template>
- <h3> {{ $t('label.configure.app') }} </h3>
- <div> {{ $t('message.two.fa.auth.register.account') }} </div>
- <vue-qrious
- class="center-align"
- :value="resource.id"
- @change="onDataUrlChange"
- />
- <br />
- <div> {{ $t('message.two.fa.static.pin.part1') }} <a @click="generateStaticPin"> {{ $t('message.two.fa.static.pin.part2') }}</a></div>
- <br />
- <h3> {{ $t('label.enter.code') }} </h3>
- <a-form @finish="submitPin" v-ctrl-enter="submitPin" class="container">
- <a-input v-model:value="pin" />
- <div :span="24">
- <a-button ref="submit" type="primary" @click="submitPin">{{ $t('label.ok') }}</a-button>
+ <div style="width:500px;height=500px">
+ <h3> {{ $t('label.select.2fa.provider') }} </h3>
+ <a-form
+ :rules="rules"
+ layout="vertical">
+ <div class="form-layout" v-ctrl-enter="submitPin">
+ <a-select
+ v-model:value="selectedProvider"
+ optionFilterProp="label"
+ :filterOption="(input, option) => {
+ return option.children[0].children.toLowerCase().indexOf(input.toLowerCase()) >= 0
+ }"
+ style="width: 100%"
+ @change="val => { handleSelectChange(val) }">
+ <a-select-option
+ v-for="(opt) in providers"
+ :key="opt.name"
+ :disabled="opt.enabled === false">
+ {{ opt.name }}
+ </a-select-option>
+ </a-select>
</div>
+ <div v-if="selectedProvider === 'google'">
+ <br />
+ <div> {{ $t('message.two.fa.auth.register.account') }} </div>
+ <vue-qrious
+ class="center-align"
+ :value="pin"
+ @change="onDataUrlChange"
+ />
+ </div>
+ <div v-else-if="selectedProvider === 'staticpin'">
+ <div> <a @click="setup2FAProvider"> {{ $t('message.two.fa.static.pin.part2') }}</a></div>
+ </div>
+ <div v-else-if="selectedProvider !== null && selectedProvider !== 'staticpin'">
+ <div> {{ $t('message.two.fa.static.pin.part1') }} <a @click="setup2FAProvider"> {{ $t('message.two.fa.static.pin.part2') }}</a></div>
+ </div>
+ <div v-if="selectedProvider">
+ <br />
+ <h3> {{ $t('label.enter.code') }} </h3>
+ <a-form @finish="submitPin" v-ctrl-enter="submitPin" class="container">
+ <a-input v-model:value="pin" />
+ <div :span="24">
+ <a-button ref="submit" type="primary" @click="submitPin">{{ $t('label.ok') }}</a-button>
+ </div>
+ </a-form>
+ </div>
+
+ <a-modal
+ v-if="showPin"
+ :visible="showPin"
+ :title="$t('label.two.factor.secret')"
+ :closable="true"
+ :footer="null"
+ @cancel="onCloseModal"
+ centered
+ width="450px">
+ <div> {{ pin }} </div>
+ </a-modal>
</a-form>
- <a-modal
- v-if="showPin"
- :visible="showPin"
- :title="$t('label.two.factor.secret')"
- :closable="true"
- :footer="null"
- @cancel="onCloseModal"
- centered
- width="450px">
- <div> {{ pin }} </div>
- </a-modal>
+ </div>
</template>
<script>
+
+import { api } from '@/api'
import VueQrious from 'vue-qrious'
export default {
name: 'RegisterTwoFactorAuth',
@@ -62,13 +97,39 @@ export default {
return {
dataUrl: '',
pin: '',
- showPin: false
+ showPin: false,
+ providers: [],
+ selectedProvider: null
}
},
+ mounted () {
+ this.list2FAProviders()
+ },
methods: {
onDataUrlChange (dataUrl) {
this.dataUrl = dataUrl
},
+ handleSelectChange (val) {
+ this.selectedProvider = val
+ this.setup2FAProvider()
+ },
+ setup2FAProvider () {
+ api('setupUserTwoFactorAuthentication', { provider: this.selectedProvider }).then(response => {
+ console.log(response)
+ this.pin = response.setupusertwofactorauthenticationresponse.setup2fa.secretcode
+ this.showPin = true
+ }).catch(error => {
+ this.$notification.error({
+ message: this.$t('message.request.failed'),
+ description: (error.response && error.response.headers && error.response.headers['x-description']) || error.message
+ })
+ })
+ },
+ list2FAProviders () {
+ api('listUserTwoFactorAuthenticatorProviders', {}).then(response => {
+ this.providers = response.listusertwofactorauthenticatorprovidersresponse.providers || []
+ })
+ },
submitPin () {
// call api
},
@@ -82,6 +143,7 @@ export default {
}
}
</script>
+
<style scoped>
.center-align {
display: block;
[cloudstack] 02/03: Static Pin changes
Posted by ha...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
harikrishna pushed a commit to branch 2FA
in repository https://gitbox.apache.org/repos/asf/cloudstack.git
commit b1be581f967a1a240715614fe9ac301df800f85c
Author: Harikrishna Patnala <ha...@gmail.com>
AuthorDate: Tue Nov 1 14:46:11 2022 +0530
Static Pin changes
---
.../java/com/cloud/utils/db/GenericDaoBase.java | 3 ---
.../auth/StaticPinUserTwoFactorAuthenticator.java | 2 +-
.../auth/SetupUserTwoFactorAuthenticationCmd.java | 2 +-
.../java/com/cloud/user/AccountManagerImpl.java | 5 +++++
ui/public/locales/en.json | 4 ++--
ui/src/views/iam/RegisterTwoFactorAuth.vue | 25 ++++++++++++++++------
6 files changed, 28 insertions(+), 13 deletions(-)
diff --git a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
index 456c9a83c36..208e8463e72 100644
--- a/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
+++ b/framework/db/src/main/java/com/cloud/utils/db/GenericDaoBase.java
@@ -838,9 +838,6 @@ public abstract class GenericDaoBase<T, ID extends Serializable> extends Compone
}
int result = pstmt.executeUpdate();
- if (sql.toString().contains("user")) {
- s_logger.debug("HARI " + pstmt.toString());
- }
txn.commit();
ub.clear();
return result;
diff --git a/plugins/user-two-factor-authenticators/static-pin/src/main/java/org/apache/cloudstack/auth/StaticPinUserTwoFactorAuthenticator.java b/plugins/user-two-factor-authenticators/static-pin/src/main/java/org/apache/cloudstack/auth/StaticPinUserTwoFactorAuthenticator.java
index 3e32e2f5b1f..99bd404ebc8 100644
--- a/plugins/user-two-factor-authenticators/static-pin/src/main/java/org/apache/cloudstack/auth/StaticPinUserTwoFactorAuthenticator.java
+++ b/plugins/user-two-factor-authenticators/static-pin/src/main/java/org/apache/cloudstack/auth/StaticPinUserTwoFactorAuthenticator.java
@@ -65,7 +65,7 @@ public class StaticPinUserTwoFactorAuthenticator extends AdapterBase implements
}
long seed = System.currentTimeMillis();
Random rng = new Random(seed);
- long number = (rng.nextLong() % 900000) + 100000;
+ long number = (rng.nextLong() % 90000) + 100000;
String key = Long.toString(number);
userAccount.setKeyFor2fa(key);
diff --git a/server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java b/server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java
index acce2cf3dfd..5ef0341662c 100644
--- a/server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java
+++ b/server/src/main/java/com/cloud/api/auth/SetupUserTwoFactorAuthenticationCmd.java
@@ -42,7 +42,7 @@ public class SetupUserTwoFactorAuthenticationCmd extends BaseCmd {
//////////////// API parameters /////////////////////
/////////////////////////////////////////////////////
- @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "two factor authentication code", required = true)
+ @Parameter(name = ApiConstants.PROVIDER, type = CommandType.STRING, description = "two factor authentication code")
private String provider;
@Parameter(name = ApiConstants.ENABLE, type = CommandType.BOOLEAN, description = "Enabled by default, provide false to disable 2FA")
diff --git a/server/src/main/java/com/cloud/user/AccountManagerImpl.java b/server/src/main/java/com/cloud/user/AccountManagerImpl.java
index 1813be8d0c7..3c2fbe50a2a 100644
--- a/server/src/main/java/com/cloud/user/AccountManagerImpl.java
+++ b/server/src/main/java/com/cloud/user/AccountManagerImpl.java
@@ -3201,6 +3201,9 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
UserTwoFactorAuthenticationSetupResponse response = new UserTwoFactorAuthenticationSetupResponse();
if (cmd.getEnable()) {
+ if (StringUtils.isEmpty(providerName)) {
+ throw new InvalidParameterValueException("Provider name is mandatory to setup 2FA");
+ }
UserTwoFactorAuthenticator provider = getUserTwoFactorAuthenticationProvider(providerName);
UserAccountVO userAccount = _userAccountDao.findById(owner.getId());
String code = provider.setup2FAKey(userAccount);
@@ -3212,6 +3215,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
_userDao.update(owner.getId(), user);
response.setId(owner.getUuid());
+ response.setUsername(owner.getName());
response.setSecretCode(code);
return response;
@@ -3224,6 +3228,7 @@ public class AccountManagerImpl extends ManagerBase implements AccountManager, M
_userDao.update(owner.getId(), user);
response.setId(owner.getUuid());
+ response.setUsername(owner.getName());
return response;
}
diff --git a/ui/public/locales/en.json b/ui/public/locales/en.json
index 013391290c0..508c6f93098 100644
--- a/ui/public/locales/en.json
+++ b/ui/public/locales/en.json
@@ -676,7 +676,7 @@
"label.endipv6": "IPv6 end IP",
"label.endpoint": "Endpoint",
"label.endport": "End port",
-"label.enter.code": "Enter Authentication code to verify",
+"label.enter.code": "Enter authentication code to verify",
"label.enter.token": "Enter token",
"label.error": "Error",
"label.error.caught": "Error caught",
@@ -2585,7 +2585,7 @@
"message.two.fa.auth": "Open the two-factor authentication app on your mobile device to view your authentication code",
"message.two.fa.auth.register.account": "Open the two-factor authentication application and scan the QR code add the user account",
"message.two.fa.static.pin.part1": "If you can't scan the QR code, ",
-"message.two.fa.static.pin.part2": "enter this text code",
+"message.two.fa.static.pin.part2": "Click here to view the secret code",
"message.update.ipaddress.processing": "Updating IP Address...",
"message.update.resource.count": "Please confirm that you want to update resource counts for this account.",
"message.update.resource.count.domain": "Please confirm that you want to update resource counts for this domain.",
diff --git a/ui/src/views/iam/RegisterTwoFactorAuth.vue b/ui/src/views/iam/RegisterTwoFactorAuth.vue
index 3ffb9f5b391..1c1db3e28cf 100644
--- a/ui/src/views/iam/RegisterTwoFactorAuth.vue
+++ b/ui/src/views/iam/RegisterTwoFactorAuth.vue
@@ -43,7 +43,7 @@
<div> {{ $t('message.two.fa.auth.register.account') }} </div>
<vue-qrious
class="center-align"
- :value="pin"
+ :value="googleUrl"
@change="onDataUrlChange"
/>
</div>
@@ -57,7 +57,7 @@
<br />
<h3> {{ $t('label.enter.code') }} </h3>
<a-form @finish="submitPin" v-ctrl-enter="submitPin" class="container">
- <a-input v-model:value="pin" />
+ <a-input v-model:value="code" />
<div :span="24">
<a-button ref="submit" type="primary" @click="submitPin">{{ $t('label.ok') }}</a-button>
</div>
@@ -95,8 +95,10 @@ export default {
},
data () {
return {
+ googleUrl: '',
dataUrl: '',
pin: '',
+ code: '',
showPin: false,
providers: [],
selectedProvider: null
@@ -117,6 +119,10 @@ export default {
api('setupUserTwoFactorAuthentication', { provider: this.selectedProvider }).then(response => {
console.log(response)
this.pin = response.setupusertwofactorauthenticationresponse.setup2fa.secretcode
+ if (this.selectedProvider === 'google') {
+ this.username = response.setupusertwofactorauthenticationresponse.setup2fa.username
+ this.googleUrl = 'otpauth://totp/CloudStack:' + this.username + '?secret=' + this.pin + '&issuer=CloudStack'
+ }
this.showPin = true
}).catch(error => {
this.$notification.error({
@@ -131,11 +137,18 @@ export default {
})
},
submitPin () {
- // call api
+ api('validateUserTwoFactorAuthenticationCode', { '2facode': this.code }).then(response => {
+ console.log(response)
+ }).catch(error => {
+ this.$notification.error({
+ message: this.$t('message.request.failed'),
+ description: (error.response && error.response.headers && error.response.headers['x-description']) || error.message
+ })
+ })
+ this.closeAction()
},
- generateStaticPin () {
- this.pin = Math.floor(100000 + Math.random() * 900000)
- this.showPin = true
+ closeAction () {
+ this.$emit('close-action')
},
onCloseModal () {
this.showPin = false