summaryrefslogtreecommitdiffstats
path: root/lib/redmine/twofa.rb
diff options
context:
space:
mode:
authorGo MAEDA <maeda@farend.jp>2020-08-29 06:21:50 +0000
committerGo MAEDA <maeda@farend.jp>2020-08-29 06:21:50 +0000
commit560bca344ae467cda03e758159fbf131d5c49f43 (patch)
tree15b4b2ec74c1d98e28f47453093588b271e18865 /lib/redmine/twofa.rb
parent657ddfef452b145bbbce2970369ce42624dfca8e (diff)
downloadredmine-560bca344ae467cda03e758159fbf131d5c49f43.tar.gz
redmine-560bca344ae467cda03e758159fbf131d5c49f43.zip
Adds two factor authentication support (#1237).
Patch by Felix Schäfer. git-svn-id: http://svn.redmine.org/redmine/trunk@19988 e93f8b46-1217-0410-a6f0-8f06a7374b81
Diffstat (limited to 'lib/redmine/twofa.rb')
-rw-r--r--lib/redmine/twofa.rb58
1 files changed, 58 insertions, 0 deletions
diff --git a/lib/redmine/twofa.rb b/lib/redmine/twofa.rb
new file mode 100644
index 000000000..44f1b7ac6
--- /dev/null
+++ b/lib/redmine/twofa.rb
@@ -0,0 +1,58 @@
+# frozen_string_literal: true
+
+# Redmine - project management software
+# Copyright (C) 2006-2020 Jean-Philippe Lang
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+
+module Redmine
+ module Twofa
+ def self.register_scheme(name, klass)
+ initialize_schemes
+ @@schemes[name] = klass
+ end
+
+ def self.available_schemes
+ schemes.keys
+ end
+
+ def self.for_twofa_scheme(name)
+ schemes[name]
+ end
+
+ def self.for_user(user)
+ for_twofa_scheme(user.twofa_scheme).try(:new, user)
+ end
+
+ def self.schemes
+ initialize_schemes
+ @@schemes
+ end
+ private_class_method :schemes
+
+ def self.initialize_schemes
+ @@schemes ||= { }
+ scan_builtin_schemes if @@schemes.blank?
+ end
+ private_class_method :initialize_schemes
+
+ def self.scan_builtin_schemes
+ Dir[Rails.root.join('lib', 'redmine', 'twofa', '*.rb')].each do |file|
+ require_dependency file
+ end
+ end
+ private_class_method :scan_builtin_schemes
+ end
+end