-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Don't allow enforcing 2FA when no provider is enabled #16463
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -15,6 +15,12 @@ | |||||||||||||||
<label for="two-factor-enforced">{{ t('settings', 'Enforce two-factor authentication') }}</label> | ||||||||||||||||
</p> | ||||||||||||||||
<template v-if="enforced"> | ||||||||||||||||
<p id="two-factor-warning-global" class="warning" v-if="noProviderGlobally"> | ||||||||||||||||
{{ t('settings', 'No Two-Factor authentication provider enabled on this server. Are you sure that you want to enforce Two-Factor authentication?') }} | ||||||||||||||||
</p> | ||||||||||||||||
<p id="two-factor-warning-admin" class="warning" v-if="noProviderAdmin"> | ||||||||||||||||
{{ t('settings', 'No Two-Factor authentication provider enabled for your account. Are you sure that you want to enforce Two-Factor authentication?') }} | ||||||||||||||||
</p> | ||||||||||||||||
<h3>{{ t('settings', 'Limit to groups') }}</h3> | ||||||||||||||||
{{ t('settings', 'Enforcement of two-factor authentication can be set for certain groups only.') }} | ||||||||||||||||
<p> | ||||||||||||||||
|
@@ -78,6 +84,10 @@ | |||||||||||||||
components: { | ||||||||||||||||
Multiselect | ||||||||||||||||
}, | ||||||||||||||||
beforeMount(){ | ||||||||||||||||
this.$store.dispatch('getAllApps'); | ||||||||||||||||
this.$store.dispatch('getEnabledProvidersCurrentUser'); | ||||||||||||||||
}, | ||||||||||||||||
data () { | ||||||||||||||||
return { | ||||||||||||||||
loading: false, | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If so maybe set it to true by default? |
||||||||||||||||
|
@@ -89,7 +99,7 @@ | |||||||||||||||
computed: { | ||||||||||||||||
enforced: { | ||||||||||||||||
get: function () { | ||||||||||||||||
return this.$store.state.enforced | ||||||||||||||||
return this.$store.state.security.enforced | ||||||||||||||||
}, | ||||||||||||||||
set: function (val) { | ||||||||||||||||
this.dirty = true | ||||||||||||||||
|
@@ -98,7 +108,7 @@ | |||||||||||||||
}, | ||||||||||||||||
enforcedGroups: { | ||||||||||||||||
get: function () { | ||||||||||||||||
return this.$store.state.enforcedGroups | ||||||||||||||||
return this.$store.state.security.enforcedGroups | ||||||||||||||||
}, | ||||||||||||||||
set: function (val) { | ||||||||||||||||
this.dirty = true | ||||||||||||||||
|
@@ -107,13 +117,27 @@ | |||||||||||||||
}, | ||||||||||||||||
excludedGroups: { | ||||||||||||||||
get: function () { | ||||||||||||||||
return this.$store.state.excludedGroups | ||||||||||||||||
return this.$store.state.security.excludedGroups | ||||||||||||||||
}, | ||||||||||||||||
set: function (val) { | ||||||||||||||||
this.dirty = true | ||||||||||||||||
this.$store.commit('setExcludedGroups', val) | ||||||||||||||||
} | ||||||||||||||||
}, | ||||||||||||||||
noProviderGlobally: { | ||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can directly use the function if you don't have a setter here.
Suggested change
|
||||||||||||||||
get: function () { | ||||||||||||||||
var providers = this.$store.getters.getAllApps.filter( function(app) { | ||||||||||||||||
return ('two-factor-providers' in app && 'provider' in app['two-factor-providers'] && app['active'] === true); | ||||||||||||||||
}); | ||||||||||||||||
return (providers.length === 0); | ||||||||||||||||
} | ||||||||||||||||
}, | ||||||||||||||||
noProviderAdmin: { | ||||||||||||||||
get: function () { | ||||||||||||||||
var providers = this.$store.getters.getEnabledProvidersCurrentUser; | ||||||||||||||||
return (providers.length === 0); | ||||||||||||||||
} | ||||||||||||||||
}, | ||||||||||||||||
}, | ||||||||||||||||
mounted () { | ||||||||||||||||
// Groups are loaded dynamically, but the assigned ones *should* | ||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import Vue from 'vue' | ||
|
||
import AdminTwoFactor from './components/AdminTwoFactor.vue' | ||
import store from './store/admin-security' | ||
import store from './store/' | ||
|
||
__webpack_nonce__ = btoa(OC.requestToken) | ||
|
||
|
@@ -11,9 +11,10 @@ Vue.prototype.t = t; | |
window.OC = window.OC || {}; | ||
window.OC.Settings = window.OC.Settings || {}; | ||
|
||
store.replaceState( | ||
OCP.InitialState.loadState('settings', 'mandatory2FAState') | ||
) | ||
let initialState = OCP.InitialState.loadState('settings', 'mandatory2FAState'); | ||
store.commit('setEnforced', initialState.enforced); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is considered bad practice to commit from a component. |
||
store.commit('setEnforcedGroups', initialState.enforcedGroups); | ||
store.commit('setExcludedGroups', initialState.excludedGroups); | ||
|
||
const View = Vue.extend(AdminTwoFactor) | ||
new View({ | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,10 +21,18 @@ | |
|
||
import Vue from 'vue' | ||
import Vuex from 'vuex' | ||
import api from './api'; | ||
|
||
Vue.use(Vuex) | ||
|
||
export const mutations = { | ||
const state = { | ||
enforced: false, | ||
enforcedGroups: [], | ||
excludedGroups: [], | ||
enabledProvidersCurrentUser: [], | ||
}; | ||
|
||
const mutations = { | ||
setEnforced(state, enabled) { | ||
Vue.set(state, 'enforced', enabled) | ||
}, | ||
|
@@ -33,31 +41,48 @@ export const mutations = { | |
}, | ||
setExcludedGroups(state, used) { | ||
Vue.set(state, 'excludedGroups', used) | ||
}, | ||
setEnabledProvidersCurrentUser(state, providers) { | ||
Vue.set(state, 'enabledProvidersCurrentUser', providers) | ||
} | ||
} | ||
|
||
const getters = { | ||
getEnabledProvidersCurrentUser(state) { | ||
return state.enabledProvidersCurrentUser; | ||
} | ||
} | ||
|
||
export const actions = { | ||
const actions = { | ||
save ({commit}, ) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This looks weird? |
||
commit('setEnabled', false); | ||
|
||
return generateCodes() | ||
.then(({codes, state}) => { | ||
commit('setEnabled', state.enabled); | ||
commit('setTotal', state.total); | ||
commit('setUsed', state.used); | ||
commit('setCodes', codes); | ||
return true; | ||
}); | ||
} | ||
commit('setTotal', state.total); | ||
commit('setUsed', state.used); | ||
commit('setCodes', codes); | ||
return true; | ||
}); | ||
}, | ||
getEnabledProvidersCurrentUser(context) { | ||
context.commit('startLoading', 'providers'); | ||
var user = OC.getCurrentUser().uid; | ||
return api.get(OC.generateUrl(`/settings/api/users/${user}/twoFactorProviders`)) | ||
.then((response) => { | ||
context.commit('setEnabledProvidersCurrentUser', response.data); | ||
context.commit('stopLoading', 'providers'); | ||
return true; | ||
}) | ||
.catch((error) => context.commit('API_FAILURE', error)); | ||
}, | ||
} | ||
|
||
export default new Vuex.Store({ | ||
export default { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Much cleaner!! 👍 |
||
strict: process.env.NODE_ENV !== 'production', | ||
state: { | ||
enforced: false, | ||
enforcedGroups: [], | ||
excludedGroups: [], | ||
}, | ||
state, | ||
mutations, | ||
getters, | ||
actions | ||
}) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Loading state here?