Module: RedhatAccess::Authentication::ClientAuthentication

Included in:
RedhatAccess::Api::TelemetryApiController
Defined in:
app/services/redhat_access/authentication/client_authentication.rb

Instance Method Summary collapse

Instance Method Details

#authenticate_clientObject



12
13
14
15
16
# File 'app/services/redhat_access/authentication/client_authentication.rb', line 12

def authenticate_client
  set_client_user
   unless User.current
  User.current.present?
end

#cert_from_requestObject



38
39
40
41
42
43
44
45
# File 'app/services/redhat_access/authentication/client_authentication.rb', line 38

def cert_from_request
    request.env['HTTP_X_RHSM_SSL_CLIENT_CERT'] ||
    request.env['SSL_CLIENT_CERT'] ||
    request.env['HTTP_SSL_CLIENT_CERT'] ||
    ENV['HTTP_X_RHSM_SSL_CLIENT_CERT'] ||
    ENV['SSL_CLIENT_CERT'] ||
    ENV['HTTP_SSL_CLIENT_CERT']
end

#cert_present?Boolean

Returns:

  • (Boolean)


33
34
35
36
# File 'app/services/redhat_access/authentication/client_authentication.rb', line 33

def cert_present?
  ssl_client_cert = cert_from_request
  !ssl_client_cert.nil? && !ssl_client_cert.empty? && ssl_client_cert != "(null)"
end

#deny_accessObject



18
19
20
# File 'app/services/redhat_access/authentication/client_authentication.rb', line 18

def deny_access
  render json: { :message => "Permission Denied." }, :status => 403
end

#set_client_userObject



22
23
24
25
26
27
28
29
30
31
# File 'app/services/redhat_access/authentication/client_authentication.rb', line 22

def set_client_user
  if cert_present?
    client_cert = RedhatAccess::Authentication::Cert.new(cert_from_request)
    uuid = client_cert.uuid
    Rails.logger.debug("Client cert UUID is : #{uuid}")
    User.current =  CertUser.new(:login => uuid)
  else
    Rails.logger.debug("Client cert not present in request")
  end
end