Module: Devise::Models::JiraAuthenticable

Extended by:
ActiveSupport::Concern
Defined in:
lib/devise/models/jira_authenticable.rb

Overview

The JiraAuthenticable module is responsible for validating a user’s credentials against the configured JIRA server. When authentication is successful, the attributes returned by the JIRA server are made available via the jira_attributes accessor in the user model.

The JiraAuthenticable module works by checking if the requested username already exists. If it does, radius authentication proceeds through that user record. Otherwise, a new user record is built and authentication proceeds. If authentication is successful, the after_jira_authentication callback is invoked, the default implementation of which simply saves the user record with validations disabled.

The radius username is extracted from the parameters hash by using the first configured value in the Devise.authentication_keys array. If the authentication key is in the list of case insensitive keys, the username will be converted to lowercase prior to authentication.

Options

JiraAuthenticable adds the following options to devise_for:

  • jira_site: The URL for the JIRA server.

  • jira_context_path: the context path for JIRA.

  • jira_read_timeout: The time we wait for a response from JIRA.

Callbacks

The after_jira_authentication callback is invoked on the user record when JIRA authentication succeeds for that user but prior to Devise checking if the user is active for authentication. Its default implementation simply saves the user record with validations disabled. This method should be overriden if further actions should be taken to make the user valid or active for authentication. If you override it, be sure to either call super to save the record or to save the record yourself.

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#valid_jira_password?(password) ⇒ Boolean

Use the currently configured JIRA server to attempt to authenticate the supplied username and password. If authentication succeeds, make the JIRA attributes returned by the server available via the radius_attributes accessor. Returns true if authentication was successful and false otherwise.

Parameters
  • username: The username to send to the radius server

  • password: The password to send to the radius server

Returns:

  • (Boolean)


54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/devise/models/jira_authenticable.rb', line 54

def valid_jira_password?(password)
  self.jira_client = JIRA::Client.new(
    username: username,
    password: password,
    site: self.class.jira_site,
    context_path: self.class.jira_context_path,
    auth_type: :cookie,
    use_cookies: true,
    read_timeout: self.class.jira_read_timeout
  )
  self.jira_client.authenticated?
rescue Timeout::Error
  raise Timeout::Error unless self.class.handle_jira_timeout_as_failure
  nil
end