Class: OpenShift::MongoAuthService
- Inherits:
-
AuthService
- Object
- AuthService
- OpenShift::MongoAuthService
- Defined in:
- lib/openshift/mongo_auth_service.rb
Instance Method Summary collapse
- #authenticate(request, login, password) ⇒ Object
- #db ⇒ Object
-
#initialize(auth_info = nil) ⇒ MongoAuthService
constructor
A new instance of MongoAuthService.
- #login(request, params, cookies) ⇒ Object
- #register_user(login, password) ⇒ Object
- #user_exists?(login) ⇒ Boolean
Constructor Details
#initialize(auth_info = nil) ⇒ MongoAuthService
Returns a new instance of MongoAuthService.
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/openshift/mongo_auth_service.rb', line 8 def initialize(auth_info = nil) super if @auth_info != nil # no-op elsif defined? Rails @auth_info = Rails.application.config.auth else raise Exception.new("Mongo DataStore service is not initialized") end @replica_set = @auth_info[:mongo_replica_sets] @host_port = @auth_info[:mongo_host_port] @user = @auth_info[:mongo_user] @password = @auth_info[:mongo_password] @db = @auth_info[:mongo_db] @collection = @auth_info[:mongo_collection] end |
Instance Method Details
#authenticate(request, login, password) ⇒ Object
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/openshift/mongo_auth_service.rb', line 48 def authenticate(request, login, password) if request.headers['User-Agent'] == "OpenShift" # password == iv, login == key return validate_broker_key(password, login) else raise OpenShift::AccessDeniedException if login.nil? || login.empty? || password.nil? || password.empty? encoded_password = Digest::MD5.hexdigest(Digest::MD5.hexdigest(password) + @salt) hash = db.collection(@collection).find_one({"_id" => login}) if hash && !hash.empty? && (hash["password"] == encoded_password) return {:username => login, :auth_method => :login} else raise OpenShift::AccessDeniedException end end end |
#db ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/openshift/mongo_auth_service.rb', line 27 def db if @replica_set con = Mongo::ReplSetConnection.new(*@host_port << {:read => :secondary}) else con = Mongo::Connection.new(@host_port[0], @host_port[1]) end user_db = con.db(@db) user_db.authenticate(@user, @password) unless @user.nil? user_db end |
#login(request, params, cookies) ⇒ Object
64 65 66 67 68 69 70 71 |
# File 'lib/openshift/mongo_auth_service.rb', line 64 def login(request, params, ) if params['broker_auth_key'] && params['broker_auth_iv'] validate_broker_key(params['broker_auth_iv'], params['broker_auth_key']) else data = JSON.parse(params['json_data']) return authenticate(request, data['rhlogin'], params['password']) end end |
#register_user(login, password) ⇒ Object
38 39 40 41 |
# File 'lib/openshift/mongo_auth_service.rb', line 38 def register_user(login,password) encoded_password = Digest::MD5.hexdigest(Digest::MD5.hexdigest(password) + @salt) db.collection(@collection).insert({"_id" => login, "user" => login, "password" => encoded_password}) end |
#user_exists?(login) ⇒ Boolean
43 44 45 46 |
# File 'lib/openshift/mongo_auth_service.rb', line 43 def user_exists?(login) hash = db.collection(@collection).find_one({"_id" => login}) !hash.nil? end |