lib/puavo/authentication.rb in puavo_authentication-0.0.11 vs lib/puavo/authentication.rb in puavo_authentication-0.0.13

- old
+ new

@@ -8,16 +8,21 @@ def authenticate(login, password) logger.debug "Find user by uid from ldap" logger.debug "uid: #{login}" begin - user = User.find(:first, :attribute => "uid", :value => login) + user = self.find(:first, :attribute => "uid", :value => login) if user.bind(password) host = LdapBase.configuration[:host] base = LdapBase.base.to_s user.remove_connection LdapBase.ldap_setup_connection(host, base, user.dn, password) + + # Allow authentication always if logged in user is ExteralService object + if user.class == ExternalService + return user + end # Allow authetication only if user is School Admin in the some School or organisation owner. if School.find( :first, :attribute => "puavoSchoolAdmin", :value => user.dn ) || LdapOrganisation.first.owner.include?(user.dn) return user