module OpenTox::Authorization
Public Class Methods
authenticate(user, pw)
click to toggle source
Authentication against OpenSSO. Returns token. Requires Username and Password.
@param user [String] Username @param pw [String] Password @return [Boolean] true if successful
# File lib/aa.rb, line 43 def self.authenticate(user, pw) begin res = RestClientWrapper.post("#{AA}/auth/authenticate",{:username=>user, :password => pw},{:subjectid => ""}).sub("token.id=","").sub("\n","") if is_token_valid(res) RestClientWrapper.subjectid = res return true else bad_request_error "Authentication failed #{res.inspect}" end rescue bad_request_error "Authentication failed #{res.inspect}" end end
is_token_valid(subjectid=RestClientWrapper.subjectid)
click to toggle source
Checks if a token is a valid token
@param [String]subjectid subjectid from openSSO session @return [Boolean] subjectid is valid or not.
# File lib/aa.rb, line 73 def self.is_token_valid(subjectid=RestClientWrapper.subjectid) begin return true if RestClientWrapper.post("#{AA}/auth/isTokenValid",:tokenid => subjectid) == "boolean=true\n" rescue #do rescue because openSSO throws 401 return false end return false end
logout(subjectid=RestClientWrapper.subjectid)
click to toggle source
Logout on opensso. Make token invalid. Requires token
@param [String] subjectid the subjectid @return [Boolean] true if logout is OK
# File lib/aa.rb, line 60 def self.logout(subjectid=RestClientWrapper.subjectid) begin out = RestClientWrapper.post("#{AA}/auth/logout", :subjectid => subjectid) return true unless is_token_valid(subjectid) rescue return false end return false end