devise-audit-log 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ecf8a2898f1e6b3c4fd7cba2235e6149600296ff
4
+ data.tar.gz: b78169721b308219903b9a66f9e607bdab021b14
5
+ SHA512:
6
+ metadata.gz: ef4553e83c56a26d782d74565fd64465cdea018e5dacee796676bd92b15b9bbd137aa953d73073787cded0d4aa5dcb1b6a9589603645b3ce584bbda3e6b263f1
7
+ data.tar.gz: b19c4d9af85147804553806298c64a06ecebe6eff95abd0ba525ae5365a0c771833d1c1bd5e700a8ed3d1e6628ce565ddff176d233bfd36e3ddb363dfc594b49
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
@@ -0,0 +1,6 @@
1
+ <component name="InspectionProjectProfileManager">
2
+ <profile version="1.0">
3
+ <option name="myName" value="Project Default" />
4
+ <inspection_tool class="Rubocop" enabled="false" level="WARNING" enabled_by_default="false" />
5
+ </profile>
6
+ </component>
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.4.4
7
+ before_install: gem install bundler -v 1.16.4
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at jonathan@helloglobo.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in devise-audit-log.gemspec
6
+ gemspec
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Jonathan De Jong
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -0,0 +1,43 @@
1
+ # Devise::Audit::Log
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/devise/audit/log`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'devise-audit-log'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install devise-audit-log
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/devise-audit-log. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+ ## License
38
+
39
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
40
+
41
+ ## Code of Conduct
42
+
43
+ Everyone interacting in the Devise::Audit::Log project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/devise-audit-log/blob/master/CODE_OF_CONDUCT.md).
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "devise/audit/log"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,32 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "devise/audit-log/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "devise-audit-log"
8
+ spec.version = Devise::AuditLog::VERSION
9
+ spec.authors = ["Jonathan De Jong"]
10
+ spec.email = ["jonathan@helloglobo.com"]
11
+
12
+ spec.summary = %q{This GEM provides a log of all authentication requests in Warden and Devise.}
13
+ spec.description = %q{This GEM provides a log of all authentication requests in Warden and Devise. Requires devise-eventable for simple events to be monitored by this GEM.}
14
+ spec.homepage = "https://github.com/jdejong/devise-audit-log"
15
+ spec.license = "MIT"
16
+
17
+ # Specify which files should be added to the gem when it is released.
18
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
19
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
20
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
21
+ end
22
+ spec.bindir = "exe"
23
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
24
+ spec.require_paths = ["lib"]
25
+
26
+ spec.add_dependency "devise", "~> 4"
27
+ spec.add_dependency "devise-eventable", ">= 0.1.1", "<= 1"
28
+
29
+ spec.add_development_dependency "bundler", "~> 1.16"
30
+ spec.add_development_dependency "rake", "~> 10.0"
31
+ spec.add_development_dependency "rspec", "~> 3.0"
32
+ end
@@ -0,0 +1 @@
1
+ require "devise/audit_log"
@@ -0,0 +1,5 @@
1
+ module Devise
2
+ module AuditLog
3
+ VERSION = "0.1.1"
4
+ end
5
+ end
@@ -0,0 +1,109 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "devise"
4
+ require "devise/audit-log/version"
5
+
6
+ module Devise
7
+ module AuditLog
8
+ mattr_accessor :test
9
+ @@test = true
10
+
11
+ def self.log(event, user, warden, env, options, success)
12
+ env ||= warden.try(:env)
13
+ warden ||= env["warden"] if env
14
+
15
+ request = ActionDispatch::Request.new(env)
16
+
17
+ ael = AuthenticationEventLog.new
18
+
19
+ ael.event_type = event
20
+ ael.user = user
21
+ ael.ip = request.remote_ip if env
22
+ ael.user_agent = request.user_agent if env
23
+ ael.referrer = request.referrer if env
24
+ ael.scope = options[:scope].to_s
25
+ ael.strategy = AuditLog.warden_strategy(warden) if warden
26
+
27
+ ael.success = success
28
+ ael.failure_reason = options[:message].to_s if !ael.success
29
+
30
+ ael.identity = user.try(:email) || request.params[ ael.scope ] && request.params[ ael.scope ][:email] || nil
31
+
32
+ ael.action = "#{request.params[:controller]}##{request.params[:action]}" if request && env && request.params.has_key?(:controller)
33
+
34
+ ael.save
35
+ end
36
+
37
+
38
+ def self.warden_strategy(warden_env)
39
+ strategy = v.env["omniauth.auth"]["provider"] if warden_env.env["omniauth.auth"]
40
+ strategy ||= warden_env.winning_strategy.class.name.split("::").last.underscore if warden_env.winning_strategy
41
+ strategy ||= "database_authenticatable"
42
+ strategy
43
+ end
44
+
45
+ def self.login_event
46
+ "LOGIN".freeze
47
+ end
48
+
49
+ def self.logout_event
50
+ "LOGOUT".freeze
51
+ end
52
+
53
+ def self.login_failure_event
54
+ "LOGIN FAILURE".freeze
55
+ end
56
+
57
+ def self.account_unlocked_event
58
+ "ACCOUNT UNLOCKED".freeze
59
+ end
60
+
61
+ def self.account_locked_event
62
+ "ACCOUNT LOCKED".freeze
63
+ end
64
+
65
+ def self.password_reset_event
66
+ "PASSWORD RESET".freeze
67
+ end
68
+
69
+ def self.password_reset_sent_event
70
+ "PASSWORD RESET SENT".freeze
71
+ end
72
+
73
+ def self.password_change_event
74
+ "PASSWORD CHANGED".freeze
75
+ end
76
+ end
77
+
78
+ self.on(:logout) do |val|
79
+ AuditLog.log(AuditLog.logout_event, val.try(:[], :record), val.try(:[], :warden), nil, val.try(:[], :options), true)
80
+ end
81
+
82
+ self.on(:login) do |val|
83
+ AuditLog.log(AuditLog.login_event, val.try(:[], :record), val.try(:[], :warden), nil, val.try(:[], :options), true)
84
+ end
85
+
86
+ self.on(:login_failure) do |val|
87
+ AuditLog.log(AuditLog.login_failure_event, nil, nil, val.try(:[], :env), val.try(:[], :options), false)
88
+ end
89
+
90
+ self.on(:password_change) do |val|
91
+ AuditLog.log(AuditLog.password_change_event, val.try(:[], :record), nil, nil, {}, true)
92
+ end
93
+
94
+ self.on(:password_reset_sent) do |val|
95
+ AuditLog.log(AuditLog.password_reset_sent_event, val.try(:[], :record), nil, nil, {}, true)
96
+ end
97
+
98
+ self.on(:password_reset) do |val|
99
+ AuditLog.log(AuditLog.password_reset_event, val.try(:[], :record), nil, nil, {}, true)
100
+ end
101
+
102
+ self.on(:account_locked) do |val|
103
+ AuditLog.log(AuditLog.account_locked_event, val.try(:[], :record), nil, nil, {}, true)
104
+ end
105
+
106
+ self.on(:account_unlocked) do |val|
107
+ AuditLog.log(AuditLog.account_unlocked_event, val.try(:[], :record), nil, nil, {}, true)
108
+ end
109
+ end
@@ -0,0 +1,51 @@
1
+ require "rails/generators"
2
+ require "rails/generators/migration"
3
+ require "active_record"
4
+ require "rails/generators/active_record"
5
+
6
+ module DeviseAuditLog
7
+ module Generators
8
+ class InstallGenerator < Rails::Generators::Base
9
+ include Rails::Generators::Migration
10
+ source_root File.expand_path("../templates", __FILE__)
11
+
12
+ # Implement the required interface for Rails::Generators::Migration.
13
+ def self.next_migration_number(dirname) #:nodoc:
14
+ next_migration_number = current_migration_number(dirname) + 1
15
+ if ::ActiveRecord::Base.timestamped_migrations
16
+ [Time.now.utc.strftime("%Y%m%d%H%M%S"), "%.14d" % next_migration_number].max
17
+ else
18
+ "%.3d" % next_migration_number
19
+ end
20
+ end
21
+
22
+ def copy_migration
23
+ migration_template "authentication_event_log_migration.rb", "db/migrate/create_authentication_event_logs.rb", migration_version: migration_version
24
+ end
25
+
26
+ def generate_model
27
+ template "authentication_event_log_model.rb", "app/models/authentication_event_log.rb", model_base_class: model_base_class, ar_optional_flag: ar_optional_flag
28
+ end
29
+
30
+ def migration_version
31
+ if rails5?
32
+ "[#{ActiveRecord::VERSION::MAJOR}.#{ActiveRecord::VERSION::MINOR}]"
33
+ end
34
+ end
35
+
36
+ def rails5?
37
+ Rails::VERSION::MAJOR >= 5
38
+ end
39
+
40
+ def model_base_class
41
+ rails5? ? "ApplicationRecord" : "ActiveRecord::Base"
42
+ end
43
+
44
+ def ar_optional_flag
45
+ if rails5?
46
+ ", optional: true"
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,24 @@
1
+ class <%= migration_class_name %> < ActiveRecord::Migration<%= migration_version %>
2
+ def change
3
+ create_table :authentication_event_logs do |t|
4
+ t.string :scope
5
+ t.string :strategy
6
+ t.string :identity
7
+ t.references :user, polymorphic: true
8
+ t.string :event_type
9
+
10
+ t.boolean :success
11
+ t.string :failure_reason
12
+
13
+ t.string :action
14
+ t.string :ip
15
+ t.text :user_agent
16
+ t.text :referrer
17
+
18
+ t.timestamps
19
+ end
20
+
21
+ add_index :authentication_event_logs, :identity
22
+ add_index :authentication_event_logs, :ip
23
+ end
24
+ end
@@ -0,0 +1,4 @@
1
+ class AuthenticationEventLog < <%= model_base_class %>
2
+ belongs_to :user, polymorphic: true<%= ar_optional_flag %>
3
+
4
+ end
metadata ADDED
@@ -0,0 +1,139 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: devise-audit-log
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Jonathan De Jong
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-09-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: devise
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '4'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '4'
27
+ - !ruby/object:Gem::Dependency
28
+ name: devise-eventable
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.1
34
+ - - "<="
35
+ - !ruby/object:Gem::Version
36
+ version: '1'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: 0.1.1
44
+ - - "<="
45
+ - !ruby/object:Gem::Version
46
+ version: '1'
47
+ - !ruby/object:Gem::Dependency
48
+ name: bundler
49
+ requirement: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - "~>"
52
+ - !ruby/object:Gem::Version
53
+ version: '1.16'
54
+ type: :development
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.16'
61
+ - !ruby/object:Gem::Dependency
62
+ name: rake
63
+ requirement: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - "~>"
66
+ - !ruby/object:Gem::Version
67
+ version: '10.0'
68
+ type: :development
69
+ prerelease: false
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: '10.0'
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec
77
+ requirement: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - "~>"
80
+ - !ruby/object:Gem::Version
81
+ version: '3.0'
82
+ type: :development
83
+ prerelease: false
84
+ version_requirements: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - "~>"
87
+ - !ruby/object:Gem::Version
88
+ version: '3.0'
89
+ description: This GEM provides a log of all authentication requests in Warden and
90
+ Devise. Requires devise-eventable for simple events to be monitored by this GEM.
91
+ email:
92
+ - jonathan@helloglobo.com
93
+ executables: []
94
+ extensions: []
95
+ extra_rdoc_files: []
96
+ files:
97
+ - ".gitignore"
98
+ - ".idea/inspectionProfiles/Project_Default.xml"
99
+ - ".rspec"
100
+ - ".travis.yml"
101
+ - CODE_OF_CONDUCT.md
102
+ - Gemfile
103
+ - LICENSE.txt
104
+ - README.md
105
+ - Rakefile
106
+ - bin/console
107
+ - bin/setup
108
+ - devise-audit-log.gemspec
109
+ - lib/devise-audit-log.rb
110
+ - lib/devise/audit-log/version.rb
111
+ - lib/devise/audit_log.rb
112
+ - lib/generators/devise_audit_log/install_generator.rb
113
+ - lib/generators/devise_audit_log/templates/authentication_event_log_migration.rb
114
+ - lib/generators/devise_audit_log/templates/authentication_event_log_model.rb
115
+ homepage: https://github.com/jdejong/devise-audit-log
116
+ licenses:
117
+ - MIT
118
+ metadata: {}
119
+ post_install_message:
120
+ rdoc_options: []
121
+ require_paths:
122
+ - lib
123
+ required_ruby_version: !ruby/object:Gem::Requirement
124
+ requirements:
125
+ - - ">="
126
+ - !ruby/object:Gem::Version
127
+ version: '0'
128
+ required_rubygems_version: !ruby/object:Gem::Requirement
129
+ requirements:
130
+ - - ">="
131
+ - !ruby/object:Gem::Version
132
+ version: '0'
133
+ requirements: []
134
+ rubyforge_project:
135
+ rubygems_version: 2.6.14.1
136
+ signing_key:
137
+ specification_version: 4
138
+ summary: This GEM provides a log of all authentication requests in Warden and Devise.
139
+ test_files: []