Skip to content

Commit 03d95d7

Browse files
Add "MFA Verified" check to workflowengine
Signed-off-by: Michiel de Jong <michiel@unhosted.org>
1 parent 9db3305 commit 03d95d7

File tree

8 files changed

+126
-4
lines changed

8 files changed

+126
-4
lines changed

apps/workflowengine/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
'OCA\\WorkflowEngine\\Check\\RequestURL' => $baseDir . '/../lib/Check/RequestURL.php',
2020
'OCA\\WorkflowEngine\\Check\\RequestUserAgent' => $baseDir . '/../lib/Check/RequestUserAgent.php',
2121
'OCA\\WorkflowEngine\\Check\\TFileCheck' => $baseDir . '/../lib/Check/TFileCheck.php',
22+
'OCA\\WorkflowEngine\\Check\\MfaVerified' => $baseDir . '/../lib/Check/MfaVerified.php',
2223
'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => $baseDir . '/../lib/Check/UserGroupMembership.php',
2324
'OCA\\WorkflowEngine\\Command\\Index' => $baseDir . '/../lib/Command/Index.php',
2425
'OCA\\WorkflowEngine\\Controller\\AWorkflowController' => $baseDir . '/../lib/Controller/AWorkflowController.php',

apps/workflowengine/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ class ComposerStaticInitWorkflowEngine
3535
'OCA\\WorkflowEngine\\Check\\RequestUserAgent' => __DIR__ . '/..' . '/../lib/Check/RequestUserAgent.php',
3636
'OCA\\WorkflowEngine\\Check\\TFileCheck' => __DIR__ . '/..' . '/../lib/Check/TFileCheck.php',
3737
'OCA\\WorkflowEngine\\Check\\UserGroupMembership' => __DIR__ . '/..' . '/../lib/Check/UserGroupMembership.php',
38+
'OCA\\WorkflowEngine\\Check\\MfaVerified' => __DIR__ . '/..' . '/../lib/Check/MfaVerified.php',
3839
'OCA\\WorkflowEngine\\Command\\Index' => __DIR__ . '/..' . '/../lib/Command/Index.php',
3940
'OCA\\WorkflowEngine\\Controller\\AWorkflowController' => __DIR__ . '/..' . '/../lib/Controller/AWorkflowController.php',
4041
'OCA\\WorkflowEngine\\Controller\\GlobalWorkflowsController' => __DIR__ . '/..' . '/../lib/Controller/GlobalWorkflowsController.php',
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/**
3+
* @copyright Copyright (c) 2016 Joas Schilling <coding@schilljs.com>
4+
*
5+
* @author Arthur Schiwon <blizzz@arthur-schiwon.de>
6+
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
7+
* @author Joas Schilling <coding@schilljs.com>
8+
* @author Julius Härtl <jus@bitgrid.net>
9+
* @author Richard Steinmetz <richard@steinmetz.cloud>
10+
*
11+
* @license GNU AGPL version 3 or any later version
12+
*
13+
* This program is free software: you can redistribute it and/or modify
14+
* it under the terms of the GNU Affero General Public License as
15+
* published by the Free Software Foundation, either version 3 of the
16+
* License, or (at your option) any later version.
17+
*
18+
* This program is distributed in the hope that it will be useful,
19+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
20+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21+
* GNU Affero General Public License for more details.
22+
*
23+
* You should have received a copy of the GNU Affero General Public License
24+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
25+
*
26+
*/
27+
namespace OCA\WorkflowEngine\Check;
28+
29+
use OCP\IL10N;
30+
use OCP\WorkflowEngine\ICheck;
31+
use OCP\ISession;
32+
33+
/** @psalm-suppress PropertyNotSetInConstructor */
34+
class MfaVerified implements ICheck{
35+
36+
/** @var IL10N */
37+
protected $l;
38+
39+
/** @var ISession */
40+
protected $session;
41+
42+
/**
43+
* @param IL10N $l
44+
* @param ISession $session
45+
*/
46+
public function __construct(IL10N $l, ISession $session) {
47+
$this->l = $l;
48+
$this->session = $session;
49+
}
50+
51+
/**
52+
* @param string $operator
53+
* @param string $value
54+
* @return bool
55+
*/
56+
public function executeCheck($operator, $value): bool {
57+
$mfaVerified = false;
58+
if (!empty($this->session->get('globalScale.userData'))) {
59+
$attr = $this->session->get('globalScale.userData')["userData"];
60+
$mfaVerified = $attr["mfaVerified"];
61+
}
62+
if (!empty($this->session->get('user_saml.samlUserData'))) {
63+
$attr = $this->session->get('user_saml.samlUserData');
64+
$mfaVerified = $attr["mfa_verified"][0];
65+
}
66+
if (!empty($this->session->get("two_factor_auth_passed"))){
67+
$mfaVerified = true;
68+
}
69+
70+
if ($operator === 'is') {
71+
return $mfaVerified === '1'; // checking whether the current user is MFA-verified
72+
} else {
73+
return $mfaVerified !== '1'; // checking whether the current user is not MFA-verified
74+
}
75+
}
76+
77+
/**
78+
* @param string $operator
79+
* @param string $value
80+
* @throws \UnexpectedValueException
81+
*/
82+
public function validateCheck($operator, $value): void {
83+
if (!in_array($operator, ['is', '!is'])) {
84+
throw new \UnexpectedValueException($this->l->t('The given operator is invalid'), 1);
85+
}
86+
}
87+
88+
public function supportedEntities(): array {
89+
return [];
90+
}
91+
92+
public function isAvailableForScope(int $scope): bool {
93+
return true;
94+
}
95+
}

apps/workflowengine/lib/Manager.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCA\WorkflowEngine\Check\FileName;
3737
use OCA\WorkflowEngine\Check\FileSize;
3838
use OCA\WorkflowEngine\Check\FileSystemTags;
39+
use OCA\WorkflowEngine\Check\MfaVerified;
3940
use OCA\WorkflowEngine\Check\RequestRemoteAddress;
4041
use OCA\WorkflowEngine\Check\RequestTime;
4142
use OCA\WorkflowEngine\Check\RequestURL;
@@ -486,6 +487,13 @@ public function deleteOperation($id, ScopeContext $scopeContext) {
486487
return $result;
487488
}
488489

490+
/**
491+
* @param string $entity
492+
* @param array $events
493+
* @param IOperation $operation
494+
* @return void
495+
* @throws \UnexpectedValueException
496+
*/
489497
protected function validateEvents(string $entity, array $events, IOperation $operation) {
490498
try {
491499
/** @var IEntity $instance */
@@ -769,6 +777,7 @@ protected function getBuildInChecks(): array {
769777
$this->container->query(FileName::class),
770778
$this->container->query(FileSize::class),
771779
$this->container->query(FileSystemTags::class),
780+
$this->container->query(MfaVerified::class),
772781
$this->container->query(RequestRemoteAddress::class),
773782
$this->container->query(RequestTime::class),
774783
$this->container->query(RequestURL::class),
@@ -784,4 +793,4 @@ protected function getBuildInChecks(): array {
784793
public function isUserScopeEnabled(): bool {
785794
return $this->config->getAppValue(Application::APP_ID, 'user_scope_disabled', 'no') === 'no';
786795
}
787-
}
796+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<template>
2+
<div>
3+
<!-- Only for remove default input -->
4+
</div>
5+
</template>

apps/workflowengine/src/components/Checks/file.js

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import { stringValidator, validateIPv4, validateIPv6 } from '../../helpers/validators.js'
2525
import FileMimeType from './FileMimeType.vue'
2626
import FileSystemTag from './FileSystemTag.vue'
27+
import MfaVerifiedValue from './MfaVerifiedValue.vue'
2728

2829
const stringOrRegexOperators = () => {
2930
return [
@@ -100,6 +101,16 @@ const FileChecks = [
100101
],
101102
component: FileSystemTag,
102103
},
104+
105+
{
106+
class: 'OCA\\WorkflowEngine\\Check\\MfaVerified',
107+
name: t('workflowengine', 'multi-factor authentication'),
108+
operators: [
109+
{ operator: 'is', name: t('workflowengine', 'is verified') },
110+
{ operator: '!is', name: t('workflowengine', 'is not verified') },
111+
],
112+
component: MfaVerifiedValue,
113+
},
103114
]
104115

105116
export default FileChecks

dist/workflowengine-workflowengine.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/workflowengine-workflowengine.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)