Class: CasClient::Filter
- Inherits:
-
Object
- Object
- CasClient::Filter
- Defined in:
- lib/casclient.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
- .check_and_parse_xml(raw_xml) ⇒ Object
- .filter(controller) ⇒ Object
- .logout(controller, service) ⇒ Object
- .redirect_to_cas(controller) ⇒ Object
- .request_cas_response(uri) ⇒ Object
- .return_address(controller, action, st = nil) ⇒ Object
- .service_url(controller) ⇒ Object
- .setup(config) ⇒ Object
- .username(text) ⇒ Object
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
21 22 23 |
# File 'lib/casclient.rb', line 21 def client @client end |
Class Method Details
.check_and_parse_xml(raw_xml) ⇒ Object
95 96 97 98 99 100 101 102 |
# File 'lib/casclient.rb', line 95 def check_and_parse_xml(raw_xml) begin doc = REXML::Document.new(raw_xml) end return doc.elements["cas:serviceResponse"].elements[1] end |
.filter(controller) ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/casclient.rb', line 30 def filter(controller) st=controller.params[:ticket] if st request=request_cas_response(return_address(controller,"validate",st)) if check_and_parse_xml(request).name=="authenticationSuccess" controller.session[:user]=username(request) controller.session[:previously_redirect_to_cas]=Time.now controller.session[:last_valid_ticket]=st else redirect_to_cas(controller) puts "!!!Invalid ticket!!!" end else redirect_to_cas(controller) puts "!!!Not ticket!!!" end end |
.logout(controller, service) ⇒ Object
75 76 77 78 79 |
# File 'lib/casclient.rb', line 75 def logout(controller,service) controller.send(:reset_session) controller.params.delete(:ticket) return @@client.logout_url + "?service=" + service end |
.redirect_to_cas(controller) ⇒ Object
53 54 55 |
# File 'lib/casclient.rb', line 53 def redirect_to_cas(controller) controller.send(:redirect_to,return_address(controller,"login")) end |
.request_cas_response(uri) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/casclient.rb', line 82 def request_cas_response(uri) uri = URI.parse(uri) http = Net::HTTP.new(uri.host, uri.port) http.use_ssl = (uri.scheme == 'https') http.verify_mode = (@force_ssl_verification ? OpenSSL::SSL::VERIFY_PEER : OpenSSL::SSL::VERIFY_NONE) begin raw_res = http.start do |conn| conn.get("#{uri.path}?#{uri.query}") end end return raw_res.body end |
.return_address(controller, action, st = nil) ⇒ Object
61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/casclient.rb', line 61 def return_address(controller,action,st=nil) case action when "login" return @@client.login_url + "?service=" + service_url(controller) when "logout" return @@client.logout_url + "?service=" + service_url(controller) when "validate" return @@client.validate_url + "?service=" + service_url(controller) + "&ticket=" + st else @@client.address end end |
.service_url(controller) ⇒ Object
57 58 59 |
# File 'lib/casclient.rb', line 57 def service_url(controller) controller.url_for(controller.params.dup) end |
.setup(config) ⇒ Object
25 26 27 28 |
# File 'lib/casclient.rb', line 25 def setup(config) @@config = config @@client=CasClient::CasClass.new(@@config) end |
.username(text) ⇒ Object
48 49 50 |
# File 'lib/casclient.rb', line 48 def username(text) check_and_parse_xml(text).elements["cas:user"].text.strip if check_and_parse_xml(text).elements["cas:user"] end |