diff --git a/config/initializers/00_settings.rb b/config/initializers/00_settings.rb
index cffe487..86537d3 100644
--- a/config/initializers/00_settings.rb
+++ b/config/initializers/00_settings.rb
@@ -1,6 +1,6 @@
Baas.settings director_name: YAML.load_file(Rails.root.join('config', 'bacula.yml'))[Rails.env].
symbolize_keys[:director]
Archiving.settings vima_oauth_enabled: true
-Archiving.settings institutional_authentication_enabled: false
+Archiving.settings institutional_authentication_enabled: true
Archiving.settings okeanos_authentication_enabled: false
diff --git a/config/routes.rb b/config/routes.rb
index eedbac6..7da6c85 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -1,81 +1,82 @@
Rails.application.routes.draw do
root 'application#index'
post 'grnet' => 'application#grnet'
+ get 'institutional' => 'application#institutional'
match 'vima', to: 'application#vima', :via => [:get, :post]
get 'logout' => 'application#logout'
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
get :users
get :restore
post :run_restore
end
collection do
post :index
end
end
resources :hosts, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
post :submit_config
post :disable
delete :revoke
end
resources :jobs, only: [:new, :create, :show, :edit, :update, :destroy] do
member do
patch :toggle_enable
post :backup_now
end
end
resources :filesets, only: [:show, :new, :create, :destroy]
resources :schedules, only: [:show, :new, :edit, :create, :update, :destroy]
end
namespace :admin do
match '/', to: 'base#index', via: [:get, :post]
get '/login' => 'base#login', as: :login
resources :settings, only: [:index, :new, :create, :edit, :update] do
member do
delete :reset
end
end
resources :clients, only: [:index, :show] do
member do
get :jobs
get :logs
get :stats
post :stats
get :configuration
post :disable
delete :revoke
end
end
resources :hosts, only: [:show] do
collection do
get :unverified
end
member do
post :verify
end
end
resources :users, only: [:index, :new, :create] do
member do
patch :ban
patch :unban
end
end
end
end
diff --git a/lib/peter/peter.rb b/lib/peter/peter.rb
index 7a5eb58..c75aafb 100644
--- a/lib/peter/peter.rb
+++ b/lib/peter/peter.rb
@@ -1,27 +1,27 @@
require 'peter/strategies/admin'
require 'peter/strategies/vima'
+require 'peter/strategies/institutional'
module Peter
extend self
def set_session(user, auth, opts)
session = auth.session(:default)
end
Rails.configuration.middleware.insert_after ActionDispatch::Flash, Warden::Manager do |manager|
- manager.default_strategies :admin, :vima
manager.failure_app = ApplicationController
end
Warden::Manager.serialize_into_session do |user|
user.id
end
Warden::Manager.serialize_from_session do |id|
User.find_by_id(id)
end
end
Warden::Manager.after_authentication do |user,auth,opts|
Peter.set_session(user, auth, opts)
end
diff --git a/lib/peter/strategies/institutional.rb b/lib/peter/strategies/institutional.rb
new file mode 100644
index 0000000..57851fd
--- /dev/null
+++ b/lib/peter/strategies/institutional.rb
@@ -0,0 +1,38 @@
+Warden::Strategies.add(:institutional) do
+ def valid?
+ fetch_header('HTTP_PERSISTENT_ID').present? &&
+ fetch_header('HTTP_MAIL').present? &&
+ fetch_header('HTTP_ENTITLEMENT').present? &&
+ fetch_header('HTTP_ENTITLEMENT').include?('urn:mace:grnet.gr:archiving:admin')
+ end
+
+ def fetch_header(header)
+ request.env[header]
+ end
+
+ def authenticate!
+ if !Archiving.settings[:institutional_authentication_enabled]
+ return fail!("Shibboleth is temporarily disabled")
+ end
+
+ identifier = "institutional:#{fetch_header("HTTP_PERSISTENT_ID")}"
+ user = User.find_or_initialize_by(identifier: identifier)
+
+ return fail!("Wrong credentials") unless user
+
+ user.login_at = Time.now
+
+ if user.new_record?
+ user.email = fetch_header("HTTP_MAIL")
+ user.username = fetch_header("HTTP_MAIL")
+ user.enabled = true
+ user.institutional!
+ else
+ user.save
+ end
+
+ return fail!("Service not available") unless user.enabled?
+
+ success!(user)
+ end
+end