Skip to content

Commit b563eb9

Browse files
committed
Fixes Authenticator list endpoint
1 parent 343e285 commit b563eb9

File tree

3 files changed

+104
-7
lines changed

3 files changed

+104
-7
lines changed

app/domain/authentication/authenticator_class.rb

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,85 @@
33
# Represents a class that implements an authenticator.
44
#
55
module Authentication
6+
module V2
7+
8+
# This is a re-implementation of the original (below) to handle the
9+
# interface changes of the V2 interface.
10+
class AuthenticatorClass
11+
class Validation
12+
13+
def initialize(cls)
14+
@cls = cls
15+
end
16+
17+
def valid?
18+
valid_name? && valid_parent_name?
19+
end
20+
21+
def validate!
22+
%w[
23+
Strategy
24+
ResolveIdentity
25+
DataObjects::Authenticator
26+
DataObjects::AuthenticatorContract
27+
].each do |klass|
28+
full_class_name = "#{@cls}::#{klass}".classify
29+
unless class_exists?(full_class_name)
30+
raise Errors::Authentication::AuthenticatorClass::V2::MissingAuthenticatorComponents, parent_name, klass
31+
end
32+
end
33+
end
34+
35+
private
36+
37+
def class_exists?(class_name)
38+
Module.const_get(class_name).is_a?(Class)
39+
rescue NameError
40+
false
41+
end
42+
43+
def valid_name?
44+
own_name == 'V2'
45+
end
46+
47+
def valid_parent_name?
48+
parent_name =~ /^Authn/
49+
end
50+
51+
def own_name
52+
name_aware.own_name
53+
end
54+
55+
def parent_name
56+
name_aware.parent_name
57+
end
58+
59+
def name_aware
60+
@name_aware ||= ::Util::NameAwareModule.new(@cls)
61+
end
62+
end
63+
64+
attr_reader :authenticator
65+
66+
def initialize(cls)
67+
Validation.new(cls).validate!
68+
@cls = cls
69+
end
70+
71+
def requires_env_arg?
72+
!@cls.respond_to?(:requires_env_arg?) || @cls.requires_env_arg?
73+
end
74+
75+
def url_name
76+
name_aware.parent_name.underscore.dasherize
77+
end
78+
79+
def name_aware
80+
@name_aware ||= ::Util::NameAwareModule.new(@cls)
81+
end
82+
83+
end
84+
end
685
class AuthenticatorClass
786

887
# Represents the rules any authenticator class must conform to

app/domain/authentication/installed_authenticators.rb

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ def configured_authenticators
3535

3636
def enabled_authenticators
3737
# Enabling via environment overrides enabling via CLI
38-
authenticators =
39-
Rails.application.config.conjur_config.authenticators
38+
authenticators = Rails.application.config.conjur_config.authenticators
4039
authenticators.empty? ? db_enabled_authenticators : authenticators
4140
end
4241

@@ -45,7 +44,7 @@ def enabled_authenticators_str
4544
end
4645

4746
private
48-
47+
4948
def db_enabled_authenticators
5049
# Always include 'authn' when enabling authenticators via CLI so that it
5150
# doesn't get disabled when another authenticator is enabled
@@ -60,19 +59,31 @@ def loaded_authenticators(authentication_module)
6059
end
6160

6261
def authenticator_instance(cls, env)
63-
pass_env = ::Authentication::AuthenticatorClass.new(cls).requires_env_arg?
64-
pass_env ? cls.new(env: env) : cls.new
62+
unless cls.to_s.split('::').last == 'V2'
63+
pass_env = ::Authentication::AuthenticatorClass.new(cls).requires_env_arg?
64+
pass_env ? cls.new(env: env) : cls.new
65+
end
6566
end
6667

6768
def url_for(authenticator)
68-
::Authentication::AuthenticatorClass.new(authenticator).url_name
69+
if authenticator.to_s.split('::').last == 'V2'
70+
::Authentication::V2::AuthenticatorClass.new(authenticator).url_name
71+
else
72+
::Authentication::AuthenticatorClass.new(authenticator).url_name
73+
end
6974
end
7075

7176
def valid?(cls)
72-
::Authentication::AuthenticatorClass::Validation.new(cls).valid?
77+
if cls.to_s.split('::').last == 'V2'
78+
::Authentication::V2::AuthenticatorClass::Validation.new(cls).valid?
79+
else
80+
::Authentication::AuthenticatorClass::Validation.new(cls).valid?
81+
end
7382
end
7483

7584
def provides_login?(cls)
85+
return false if cls.to_s.split('::').last == 'V2'
86+
7687
validation = ::Authentication::AuthenticatorClass::Validation.new(cls)
7788
validation.valid? && validation.provides_login?
7889
end

app/domain/errors.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,13 @@ module AuthenticatorClass
152152
code: "CONJ00040E"
153153
)
154154

155+
module V2
156+
MissingAuthenticatorComponents = ::Util::TrackableErrorClass.new(
157+
msg: "'{0-authenticator-parent-name}' is not a valid authenticator "\
158+
"because it does not include the class '{1-class-name}'",
159+
code: "CONJ00155E"
160+
)
161+
end
155162
end
156163

157164
module Security

0 commit comments

Comments
 (0)