Class: Foo::Filter

Inherits:
Object
  • Object
show all
Defined in:
lib/foo.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#clientObject

Returns the value of attribute client.



25
26
27
# File 'lib/foo.rb', line 25

def client
  @client
end

Class Method Details

.check_and_parse_xml(raw_xml) ⇒ Object



105
106
107
108
109
110
111
112
# File 'lib/foo.rb', line 105

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



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/foo.rb', line 33

def filter(controller)
  controller.session[:client]=@@client
  if controller.params[:ticket]
    check=request_cas_response(return_address(controller,"validate"))
    if username(check)
    controller.session[:user]=username(check)
    end
    controller.session[:sussess]=valid?(check)
    if @@client.success!=true
      if valid?(check)
        @@client.success=valid?(check)
      else
        puts "!!!!!!!!!!!!!!REDIRECT_TO CAS BECAUSE ERROR VALID TICKET!!!!!!!!!!!!!"
        redirect_to_cas(controller)
      end
    end
  else
    puts "!!!!!!!!!!!!!!REDIRECT_TO CAS BECAUSE NOT TICKET!!!!!!!!!!!!!"
    redirect_to_cas(controller)
  end
end

.logout(controller, service) ⇒ Object



55
56
57
58
59
60
# File 'lib/foo.rb', line 55

def logout(controller,service)
  @@client.success=false
  controller.send(:reset_session)
  controller.params.delete(:ticket)
  return @@client.logout_url + "?service=" + service
end

.redirect_to_cas(controller) ⇒ Object



62
63
64
# File 'lib/foo.rb', line 62

def redirect_to_cas(controller)
controller.send(:redirect_to,return_address(controller,"login"))
end

.request_cas_response(uri) ⇒ Object

то что возвращает cas сервер



86
87
88
89
90
91
92
93
94
95
# File 'lib/foo.rb', line 86

def request_cas_response(uri)
  uri = URI.parse(uri)
  http = Net::HTTP.new(uri.host, uri.port)
  begin
    raw_res = http.start do |conn|
      conn.get("#{uri.path}?#{uri.query}")
    end
  end
  return raw_res.body
end

.return_address(controller, action) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/foo.rb', line 70

def return_address(controller,action)
  case action
    when "login"
      return @@client. + "?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=" + controller.params[:ticket]
    else
      @@client.address

  end
end

.service_url(controller) ⇒ Object



66
67
68
# File 'lib/foo.rb', line 66

def service_url(controller)
  service_url=controller.url_for(controller.params.dup)
end

.setup(config) ⇒ Object



28
29
30
31
# File 'lib/foo.rb', line 28

def setup(config)
  @@config = config
  @@client=Foo::FooClass.new(@@config)
end

.username(text) ⇒ Object



101
102
103
# File 'lib/foo.rb', line 101

def username(text)
  check_and_parse_xml(text).elements["cas:user"].text.strip if check_and_parse_xml(text).elements["cas:user"]
end

.valid?(check) ⇒ Boolean

Returns:

  • (Boolean)


97
98
99
# File 'lib/foo.rb', line 97

def valid?(check)
  check_and_parse_xml(check).name=="authenticationSuccess"
end