-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add the code for cert authentication, pulled from another repo
- Loading branch information
Showing
51 changed files
with
868 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
24 changes: 24 additions & 0 deletions
24
app/assets/javascripts/app/application/certificate_authentication.js.coffee
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
class mconf.CertificateAuthentication | ||
|
||
redirect_on_success = -> | ||
if $('.certificate-login-error').length == 0 | ||
window.location = '/home' | ||
|
||
setTimeout redirect_on_success, 2000 | ||
|
||
# Binds all certificate authentication login modal events | ||
@bind: -> | ||
|
||
# Redirect after some time has passed | ||
$('a#certificate-login').on 'modal-shown', -> | ||
setTimeout redirect_on_success, 2000 | ||
|
||
$('a#certificate-login').on 'modal-hide', -> | ||
redirect_on_success() | ||
|
||
# Show an error message if server returns 40x or 50x | ||
$('a#certificate-login').on 'modal-error', -> | ||
$(this).addClass('certificate-login-error') | ||
$('.modal.xhr-error').load('/certificate_error') | ||
.hide() | ||
.fadeIn('slow'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,8 @@ | ||
#= require "../registrations/_signup_form" | ||
#= require "../application/certificate_authentication" | ||
|
||
$ -> | ||
if isOnPage 'frontpage', 'show' | ||
mconf.SignupForm.setup() | ||
|
||
mconf.CertificateAuthentication.bind() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#= require "../application/certificate_authentication" | ||
|
||
$ -> | ||
if isOnPage 'sessions', 'new|create' | ||
mconf.CertificateAuthentication.bind() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
//= require_tree ./app/sessions/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
class CertificateAuthenticationController < ApplicationController | ||
|
||
layout :determine_layout | ||
def determine_layout | ||
if request.xhr? | ||
'modal' | ||
else | ||
'application' | ||
end | ||
end | ||
|
||
def login | ||
certificate = request.headers['SSL_CLIENT_CERT'] | ||
|
||
@cert = Mconf::SSLClientCert.new(certificate) | ||
@user = @cert.user | ||
|
||
if @user.present? | ||
|
||
# If the user has permission, log him in | ||
if Mconf::AttributeCertificate::any_certificate?(@user) | ||
sign_in :user, @user | ||
redirect_to my_home_path if !request.xhr? | ||
|
||
# user present but has no permissions via his certificate | ||
else | ||
redirect_to certificate_pending_path(name: @user.name) | ||
end | ||
|
||
else | ||
error = @cert.error || 'unknown' | ||
flash[:error] = I18n.t("certificate_authentication.error.#{error}") | ||
end | ||
end | ||
|
||
# Serves the error modal | ||
def error | ||
end | ||
|
||
def pending | ||
# don't show it unless user logged via certificate | ||
# referers = [login_url, root_url, certificate_login_path] | ||
|
||
if user_signed_in? | ||
redirect_to root_path | ||
end | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
class AttributeCertificateConfiguration < ActiveRecord::Base | ||
validates :repository_url, presence: true, if: :enabled? | ||
|
||
before_save :adjust_repository_url, if: :repository_url | ||
|
||
def full_url | ||
return '' if repository_url.blank? | ||
|
||
port = repository_port || '443' | ||
port_str = ":#{port}/" unless ['80','443'].include?(port) | ||
|
||
"http#{port == '443' ? 's' : ''}://#{repository_url}#{port_str}?wsdl" | ||
end | ||
|
||
|
||
private | ||
|
||
def adjust_repository_url | ||
repository_url.gsub!(/\?wsdl$/, '') # remove ?wsdl from the url | ||
repository_url.gsub!(/^https?:\/\//, '') # remove protocol from the start | ||
end | ||
|
||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
class AttributeRole < ActiveRecord::Base | ||
belongs_to :role | ||
|
||
def self.find_by_role_name name | ||
r = Role.where(name: name).first | ||
|
||
where(role: r).first | ||
end | ||
|
||
def role_name | ||
role.try(:name) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.certificate-login-error | ||
= flash[:error] || t('.generic') | ||
= icon_error() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
.modal-body | ||
- content_for :modal_title, t('.title') | ||
= render 'error' |
Oops, something went wrong.