-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Handle case when actor key value can be null Co-authored-by: Lucia Janíková <[email protected]> * Handle case when actor key value can be null Co-authored-by: Lucia Janíková <[email protected]> * Add login button, expect callback URL from UPVS to be always /login for safety reasons * Fix logout redirect * Improve login button, fetch assertion * Persist subject data from assertion * Disallow subject login for non-full representation * Update app/views/sessions/insufficient_representation.html.erb Co-authored-by: Jano Suchal <[email protected]> * Remove index which is not necessary --------- Co-authored-by: Ahmed Al Hafoudh <[email protected]> Co-authored-by: Lucia Janíková <[email protected]> Co-authored-by: Jano Suchal <[email protected]>
- Loading branch information
1 parent
2d78d95
commit ac499f9
Showing
15 changed files
with
172 additions
and
64 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,73 @@ | ||
module Upvs | ||
class Assertion | ||
include ActiveModel::Model | ||
attr_accessor(:raw, :subject_name, :subject_id, :subject_cin, :subject_edesk_number, :delegation_type) | ||
|
||
DELEGATION_TYPES = { | ||
legal_representation: '0', | ||
full_representation: '1', | ||
partial_representation: '2', | ||
} | ||
|
||
def fully_represents_subject? | ||
delegation_type&.to_s&.in?(full_representations) | ||
end | ||
|
||
def self.new_from_xml(raw:) | ||
return unless raw | ||
|
||
doc = Nokogiri::XML(raw) | ||
return unless doc | ||
|
||
doc.remove_namespaces! | ||
doc_attrs = doc.xpath('//Assertion/AttributeStatement/Attribute') | ||
return unless doc_attrs | ||
|
||
new( | ||
raw:, | ||
subject_name: doc_attrs.detect{|n| n['Name'] == 'Subject.FormattedName' }&.xpath('AttributeValue')&.text, | ||
subject_id: doc_attrs.detect{|n| n['Name'] == 'SubjectID' }&.xpath('AttributeValue')&.text, | ||
subject_cin: doc_attrs.detect{|n| n['Name'] == 'Subject.ICO' }&.xpath('AttributeValue')&.text, | ||
subject_edesk_number: doc_attrs.detect{|n| n['Name'] == 'Subject.eDeskNumber' }&.xpath('AttributeValue')&.text, | ||
delegation_type: doc_attrs.detect{|n| n['Name'] == 'DelegationType' }&.xpath('AttributeValue')&.text, | ||
) | ||
end | ||
|
||
def self.assertion(eid_token, client: Faraday, url: "#{ENV.fetch('AUTH_EID_BASE_URL')}/api/upvs/assertion?token=#{eid_token&.api_token}") | ||
new_from_xml(raw: get_from_sk_api(client, url, eid_token)) | ||
end | ||
|
||
def self.get_from_sk_api(client, url, eid_token) | ||
headers = { | ||
"Accept": "application/samlassertion+xml", | ||
"AUTHORIZATION": "Bearer #{eid_token&.api_token}", | ||
} | ||
|
||
response = client.get(url, {}, headers) | ||
error = begin | ||
JSON.parse(response.body) | ||
rescue StandardError | ||
nil | ||
end | ||
if error && error['message'] | ||
return nil | ||
end | ||
response.body | ||
rescue StandardError => _e | ||
raise | ||
nil | ||
end | ||
|
||
private | ||
|
||
def full_representations | ||
[ | ||
DELEGATION_TYPES[:legal_representation], | ||
DELEGATION_TYPES[:full_representation], | ||
] | ||
end | ||
|
||
class SkApiError < StandardError | ||
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
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,9 @@ | ||
<%= content_for :title, build_page_title('Chyba pri prihlasovaní') %> | ||
|
||
<div class="govuk-grid-row"> | ||
<div class="govuk-grid-column-two-thirds"> | ||
<h2 class="govuk-heading-xl">Nastala chyba pri prihlasovaní</h2> | ||
|
||
<p class="govuk-body-lead">Nemáte dostatočné oprávnenia, aby ste mohli zastupovať zvolený subjekt.</p> | ||
</div> | ||
</div> |
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 |
---|---|---|
|
@@ -16,6 +16,7 @@ | |
} | ||
provider :eid, { | ||
config: Rails.application.config_for(:auth).fetch(:eid), | ||
callback_path: '/login', | ||
} | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class AddSubjectDataToUsers < ActiveRecord::Migration[6.1] | ||
def change | ||
add_column :users, :subject_name, :string | ||
add_column :users, :subject_cin, :string | ||
add_column :users, :subject_edesk_number, :string | ||
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