2018-10-11 20:12:21 +00:00
# frozen_string_literal: true
2018-02-23 12:10:39 +00:00
module Gitlab
module Auth
module Saml
class AuthHash < Gitlab :: Auth :: OAuth :: AuthHash
def groups
Array . wrap ( get_raw ( Gitlab :: Auth :: Saml :: Config . groups ) )
end
2018-06-25 15:32:03 +00:00
def authn_context
response_object = auth_hash . extra [ :response_object ]
2019-02-08 12:19:53 +00:00
return if response_object . blank?
2018-06-25 15:32:03 +00:00
document = response_object . decrypted_document
document || = response_object . document
2019-02-08 12:19:53 +00:00
return if document . blank?
2018-06-25 15:32:03 +00:00
extract_authn_context ( document )
end
2018-02-23 12:10:39 +00:00
private
def get_raw ( key )
# Needs to call `all` because of https://git.io/vVo4u
# otherwise just the first value is returned
auth_hash . extra [ :raw_info ] . all [ key ]
end
2018-06-25 15:32:03 +00:00
def extract_authn_context ( document )
2018-10-24 11:21:47 +00:00
REXML :: XPath . first ( document , " //*[name()='saml:AuthnStatement' or name()='saml2:AuthnStatement']/*[name()='saml:AuthnContext' or name()='saml2:AuthnContext']/*[name()='saml:AuthnContextClassRef' or name()='saml2:AuthnContextClassRef']/text() " ) . to_s
2018-06-25 15:32:03 +00:00
end
2018-02-23 12:10:39 +00:00
end
end
end
end