diff --git a/Gemfile b/Gemfile index f2ef4487..64303600 100644 --- a/Gemfile +++ b/Gemfile @@ -19,7 +19,7 @@ gem 'json-ld' # Rack middleware -gem 'ffi' +gem 'ffi', '~> 1.15.5' gem 'rack-accept', '~> 0.4' gem 'rack-attack', '~> 6.6.1', require: 'rack/attack' gem 'rack-cache', '~> 1.13.0' @@ -52,6 +52,7 @@ gem 'goo', github: 'ontoportal-lirmm/goo', branch: 'development' gem 'sparql-client', github: 'ontoportal-lirmm/sparql-client', branch: 'development' gem 'ontologies_linked_data', git: 'https://github.com/lifewatch-eric/ontologies_linked_data.git', branch: 'master' gem 'ncbo_cron', git: 'https://github.com/lifewatch-eric/ncbo_cron.git', branch: 'master' +gem 'request_store' group :development do # bcrypt_pbkdf and ed35519 is required for capistrano deployments when using ed25519 keys; see https://github.com/miloserdow/capistrano-deploy/issues/42 diff --git a/Gemfile.lock b/Gemfile.lock index 5d8556e8..113b2492 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -426,7 +426,7 @@ DEPENDENCIES cube-ruby ed25519 (>= 1.2, < 2.0) faraday (~> 1.9) - ffi + ffi (~> 1.15.5) goo! haml (~> 5.2.2) json-ld diff --git a/config/deploy/appliance.rb b/config/deploy/appliance.rb deleted file mode 100644 index fdfe0d70..00000000 --- a/config/deploy/appliance.rb +++ /dev/null @@ -1,49 +0,0 @@ -# Simple Role Syntax -# ================== -# Supports bulk-adding hosts to roles, the primary -# server in each group is considered to be the first -# unless any hosts have the primary property set. -# Don't declare `role :all`, it's a meta role - -# Extended Server Syntax -# ====================== -# This can be used to drop a more detailed server -# definition into the server list. The second argument -# something that quacks like a hash can be used to set -# extended properties on the server. -server 'localhost', roles: %w{app} - -# you can set custom ssh options -# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options -# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) -# set it globally -# set :ssh_options, { -# keys: %w(/home/rlisowski/.ssh/id_rsa), -# forward_agent: false, -# auth_methods: %w(password) -# } -# and/or per server -# server 'example.com', -# user: 'user_name', -# roles: %w{web app}, -# ssh_options: { -# user: 'user_name', # overrides user setting above -# keys: %w(/home/user_name/.ssh/id_rsa), -# forward_agent: false, -# auth_methods: %w(publickey password) -# # password: 'please use keys' -# } -# setting per server overrides global ssh_options - -BRANCH = ENV.include?('BRANCH') ? ENV['BRANCH'] : 'master' -set :branch, "#{BRANCH}" -set :deploy_to, "/srv/ontoportal/#{fetch(:application)}" -# install gems into a common direcotry shared across ui, api and ncbo_cron to reduce disk usage -set :bundle_path, '/srv/ontoportal/.bundle' -remove :linked_dirs, 'vendor/bundle' - -# private git repo for configuraiton -# PRIVATE_CONFIG_REPO = ENV.include?('PRIVATE_CONFIG_REPO') ? ENV['PRIVATE_CONFIG_REPO'] : 'git@github.com:your_org/private-config-repo.git' - -# location of local configuration files -LOCAL_CONFIG_PATH = ENV.include?('LOCAL_CONFIG_PATH') ? ENV['LOCAL_CONFIG_PATH'] : '/srv/ontoportal/virtual_appliance/appliance_config' diff --git a/config/deploy/production.rb b/config/deploy/production.rb index c84d24ea..1339b1ef 100644 --- a/config/deploy/production.rb +++ b/config/deploy/production.rb @@ -1,39 +1,13 @@ -# Simple Role Syntax -# ================== -# Supports bulk-adding hosts to roles, the primary -# server in each group is considered to be the first -# unless any hosts have the primary property set. -# Don't declare `role :all`, it's a meta role -role :app, %w{deploy@example.com} -role :web, %w{deploy@example.com} -role :db, %w{deploy@example.com} +set :branch, 'master' +set :server, 'ecoportal.lifewatch.eu' -# Extended Server Syntax -# ====================== -# This can be used to drop a more detailed server -# definition into the server list. The second argument -# something that quacks like a hash can be used to set -# extended properties on the server. -server 'example.com', user: 'deploy', roles: %w{web app}, my_property: :my_value +server fetch(:server), user: fetch(:user), roles: %w{web app} -# you can set custom ssh options -# it's possible to pass any option but you need to keep in mind that net/ssh understand limited list of options -# you can see them in [net/ssh documentation](http://net-ssh.github.io/net-ssh/classes/Net/SSH.html#method-c-start) -# set it globally -# set :ssh_options, { -# keys: %w(/home/rlisowski/.ssh/id_rsa), -# forward_agent: false, -# auth_methods: %w(password) -# } -# and/or per server -# server 'example.com', -# user: 'user_name', -# roles: %w{web app}, -# ssh_options: { -# user: 'user_name', # overrides user setting above -# keys: %w(/home/user_name/.ssh/id_rsa), -# forward_agent: false, -# auth_methods: %w(publickey password) -# # password: 'please use keys' -# } -# setting per server overrides global ssh_options +set :ssh_options, { + user: 'ontoportal', + forward_agent: 'true', + #keys: %w(config/deploy_id_rsa), + #auth_methods: %w(publickey), + # use ssh proxy if UI servers are on a private network + #proxy: Net::SSH::Proxy::Command.new('ssh deployer@sshproxy.ontoportal.org -W %h:%p') +} diff --git a/controllers/users_controller.rb b/controllers/users_controller.rb index 8e20813a..f4c30694 100644 --- a/controllers/users_controller.rb +++ b/controllers/users_controller.rb @@ -1,17 +1,17 @@ -require 'jwt' - class UsersController < ApplicationController namespace "/users" do post "/authenticate" do + # Modify params to show all user attributes params["display"] = User.attributes.join(",") - if $SSO_ENABLED - user = sso_auth + + if params["access_token"] + user = oauth_authenticate(params) + user.bring(*User.goo_attrs_to_load(includes_param)) else - user = password_auth + user = login_password_authenticate(params) end - - user.show_apikey = true + user.show_apikey = true unless user.nil? reply user end @@ -98,54 +98,6 @@ class UsersController < ApplicationController private - def password_auth - user_id = params["user"] - user_password = params["password"] - user = User.find(user_id).include(User.goo_attrs_to_load(includes_param) + [:passwordHash]).first - authenticated = user.authenticate(user_password) unless user.nil? - error 401, "Username/password combination invalid" unless authenticated - user - end - - def sso_auth - bearer_token = params["token"] - error 401, "No bearer token provided" unless bearer_token - - begin - decoded_token = LinkedData::Security::Authorization.decodeJWT(bearer_token) - rescue JWT::DecodeError => e - error 401, "Failed to decode JWT token: " + e.message - end - token_payload = decoded_token[0] - - user_id = token_payload[LinkedData.settings.oauth2_username_claim] - given_name = token_payload[LinkedData.settings.oauth2_given_name_claim] - family_name = token_payload[LinkedData.settings.oauth2_family_name_claim] - email = token_payload[LinkedData.settings.oauth2_email_claim] - - user = User.find(user_id).include(User.goo_attrs_to_load(includes_param)).first - - if user.nil? # first-time access, register new user - user_creation_params = { - username: user_id, - firstName: given_name, - lastName: family_name, - email: email, - password: SecureRandom.hex(16) - } - - user = instance_from_params(User, user_creation_params) - save_user(user) - end - user - end - - def token(len) - chars = ("a".."z").to_a + ("A".."Z").to_a + ("1".."9").to_a - token = "" - 1.upto(len) { |i| token << chars[rand(chars.size-1)] } - token - end def create_user(send_notifications: true) params ||= @params @@ -153,16 +105,12 @@ def create_user(send_notifications: true) error 409, "User with username `#{params["username"]}` already exists" unless user.nil? params.delete("role") unless current_user.admin? user = instance_from_params(User, params) - save_user(user) - reply 201, user - end - - def save_user(user) if user.valid? user.save(send_notifications: send_notifications) else error 422, user.errors end + reply 201, user end end -end +end \ No newline at end of file diff --git a/test/controllers/test_identifier_request_controller.rb b/test/controllers/test_identifier_request_controller.rb index fb6d7c58..c63e4034 100644 --- a/test/controllers/test_identifier_request_controller.rb +++ b/test/controllers/test_identifier_request_controller.rb @@ -21,7 +21,7 @@ def setup hasOntologyLanguage: LinkedData::Models::OntologyFormat.find('OWL').first, contact: [LinkedData::Models::Contact.new(email: 'test@test.com', name: 'test').save], released: DateTime.now, uploadFilePath: '', - URI: 'https://test.com/test', + URI: RDF::URI.new('https://test.com/test'), status: 'production', description: 'ontology description' ).save end