Class: SignIn::CredentialLevelCreator

Inherits:
Object
  • Object
show all
Defined in:
app/services/sign_in/credential_level_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(requested_acr:, type:, logingov_acr:, user_info:) ⇒ CredentialLevelCreator

Returns a new instance of CredentialLevelCreator.



15
16
17
18
19
20
21
22
23
24
25
# File 'app/services/sign_in/credential_level_creator.rb', line 15

def initialize(requested_acr:, type:, logingov_acr:, user_info:)
  @requested_acr = requested_acr
  @type = type
  @logingov_acr = logingov_acr
  @verified_at = .verified_at
  @mhv_assurance = .mhv_assurance
  @dslogon_assurance = .dslogon_assurance
  @level_of_assurance = .level_of_assurance
  @credential_ial = .credential_ial
  @credential_uuid = .sub
end

Instance Attribute Details

#credential_ialObject (readonly)

Returns the value of attribute credential_ial.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def credential_ial
  @credential_ial
end

#credential_uuidObject (readonly)

Returns the value of attribute credential_uuid.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def credential_uuid
  @credential_uuid
end

#dslogon_assuranceObject (readonly)

Returns the value of attribute dslogon_assurance.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def dslogon_assurance
  @dslogon_assurance
end

#level_of_assuranceObject (readonly)

Returns the value of attribute level_of_assurance.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def level_of_assurance
  @level_of_assurance
end

#logingov_acrObject (readonly)

Returns the value of attribute logingov_acr.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def logingov_acr
  @logingov_acr
end

#mhv_assuranceObject (readonly)

Returns the value of attribute mhv_assurance.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def mhv_assurance
  @mhv_assurance
end

#requested_acrObject (readonly)

Returns the value of attribute requested_acr.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def requested_acr
  @requested_acr
end

#typeObject (readonly)

Returns the value of attribute type.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def type
  @type
end

#verified_atObject (readonly)

Returns the value of attribute verified_at.



5
6
7
# File 'app/services/sign_in/credential_level_creator.rb', line 5

def verified_at
  @verified_at
end

Instance Method Details

#auto_uplevelObject (private)



109
110
111
112
113
114
115
116
117
118
# File 'app/services/sign_in/credential_level_creator.rb', line 109

def auto_uplevel
  case type
  when Constants::Auth::LOGINGOV
    logingov_acr != Constants::Auth::LOGIN_GOV_IAL2 && previously_verified?(:logingov_uuid)
  when Constants::Auth::IDME
    credential_ial != Constants::Auth::IDME_CLASSIC_LOA3 && previously_verified?(:idme_uuid)
  else
    false
  end
end

#check_required_verification_levelObject (private)



34
35
36
37
38
39
40
41
42
43
# File 'app/services/sign_in/credential_level_creator.rb', line 34

def check_required_verification_level
  if 
    case type
    when Constants::Auth::MHV
      raise_unverified_credential_blocked_error(code: Constants::ErrorCode::MHV_UNVERIFIED_BLOCKED)
    else
      raise_unverified_credential_blocked_error(code: Constants::ErrorCode::GENERIC_EXTERNAL_ISSUE)
    end
  end
end

#create_credential_levelObject (private)



51
52
53
54
55
56
57
58
59
# File 'app/services/sign_in/credential_level_creator.rb', line 51

def create_credential_level
  CredentialLevel.new(requested_acr:,
                      credential_type: type,
                      current_ial:,
                      max_ial:,
                      auto_uplevel:)
rescue ActiveModel::ValidationError
  raise Errors::InvalidCredentialLevelError.new message: 'Unsupported credential authorization levels'
end

#current_ialObject (private)



76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'app/services/sign_in/credential_level_creator.rb', line 76

def current_ial
  case type
  when Constants::Auth::LOGINGOV
    verified_ial_level(logingov_acr == Constants::Auth::LOGIN_GOV_IAL2 || previously_verified?(:logingov_uuid))
  when Constants::Auth::MHV
    verified_ial_level(requested_verified_account? && Constants::Auth::MHV_PREMIUM_VERIFIED.include?(mhv_assurance))
  when Constants::Auth::DSLOGON
    verified_ial_level(requested_verified_account? &&
                       Constants::Auth::DSLOGON_PREMIUM_VERIFIED.include?(dslogon_assurance))
  else
    verified_ial_level(credential_ial == Constants::Auth::IDME_CLASSIC_LOA3 || previously_verified?(:idme_uuid))
  end
end

#max_ialObject (private)



61
62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'app/services/sign_in/credential_level_creator.rb', line 61

def max_ial
  case type
  when Constants::Auth::LOGINGOV
    verified_ial_level(verified_at)
  when Constants::Auth::MHV
    verified_ial_level(Constants::Auth::MHV_PREMIUM_VERIFIED.include?(mhv_assurance))
  when Constants::Auth::DSLOGON
    Rails.logger.info("[CredentialLevelCreator] DSLogon level of assurance: #{dslogon_assurance}, " \
                      "credential_uuid: #{credential_uuid}")
    verified_ial_level(Constants::Auth::DSLOGON_PREMIUM_VERIFIED.include?(dslogon_assurance))
  else
    verified_ial_level(level_of_assurance == Constants::Auth::LOA_THREE)
  end
end

#performObject



27
28
29
30
# File 'app/services/sign_in/credential_level_creator.rb', line 27

def perform
  check_required_verification_level
  create_credential_level
end

#previously_verified?(identifier_type) ⇒ Boolean (private)

Returns:

  • (Boolean)


102
103
104
105
106
107
# File 'app/services/sign_in/credential_level_creator.rb', line 102

def previously_verified?(identifier_type)
  return false unless Settings..auto_uplevel && requested_verified_account?

  user_verification = UserVerification.find_by(identifier_type => credential_uuid)
  user_verification&.verified?
end

#raise_unverified_credential_blocked_error(code:) ⇒ Object (private)



45
46
47
48
49
# File 'app/services/sign_in/credential_level_creator.rb', line 45

def raise_unverified_credential_blocked_error(code:)
  raise Errors::UnverifiedCredentialBlockedError.new(
    message: 'Unverified credential for authorization requiring verified credential', code:
  )
end

#requested_verified_account?Boolean (private)

Returns:

  • (Boolean)


94
95
96
# File 'app/services/sign_in/credential_level_creator.rb', line 94

def requested_verified_account?
  [Constants::Auth::IAL2, Constants::Auth::LOA3, Constants::Auth::MIN].include?(requested_acr)
end

#unverified_account_with_forced_verification?Boolean (private)

Returns:

  • (Boolean)


98
99
100
# File 'app/services/sign_in/credential_level_creator.rb', line 98

def 
  [Constants::Auth::IAL2, Constants::Auth::LOA3].include?(requested_acr) && current_ial < Constants::Auth::IAL_TWO
end

#verified_ial_level(verified) ⇒ Object (private)



90
91
92
# File 'app/services/sign_in/credential_level_creator.rb', line 90

def verified_ial_level(verified)
  verified ? Constants::Auth::IAL_TWO : Constants::Auth::IAL_ONE
end