Class: SqAuth::SqAuthAccess
- Inherits:
-
Object
- Object
- SqAuth::SqAuthAccess
- Defined in:
- lib/sq_auth/sq_auth_access.rb
Constant Summary collapse
- DEFAULT_ACCESS_PATH =
"/access_partial"
- DEFAULT_DRAW_PROC =
Proc.new {|uri, project_params, user_params| SqAuthUtils::default_draw_template(uri, project_params, user_params)}
- DEFAULT_DATA_PROC =
Proc.new { "Forbidden" }
- DEFAULT_OPTIONS =
{project: "Project", https: true}
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#forced_host ⇒ Object
Returns the value of attribute forced_host.
-
#forced_port ⇒ Object
Returns the value of attribute forced_port.
-
#gateway_ip ⇒ Object
Returns the value of attribute gateway_ip.
-
#login_path ⇒ Object
Returns the value of attribute login_path.
-
#project_name ⇒ Object
Returns the value of attribute project_name.
Instance Method Summary collapse
- #api_filter(roles, project = @project_name, when_ok, when_no_role, options) ⇒ Object
- #check_session_provider ⇒ Object
- #connect(options = {}) {|_self| ... } ⇒ Object
- #current_user_ip=(ip) ⇒ Object
- #current_user_name=(name) ⇒ Object
- #data_when_not_logged_in(&block) ⇒ Object
- #draw_when_not_authenticated(roles, project = @project_name) ⇒ Object
- #draw_when_not_logged_in(&block) ⇒ Object
- #form_project_params(callback, roles, project) ⇒ Object
- #get_not_logged_in_proc(type = nil) ⇒ Object
-
#initialize(options = {}) ⇒ SqAuthAccess
constructor
A new instance of SqAuthAccess.
- #login_to ⇒ Object
- #message_when_not_authenticated(roles = [], project = @project_name) ⇒ Object
- #revoke_session(sqauthsession) ⇒ Object
- #roles_for_current_user(project = @project_name) ⇒ Object
- #save_session_for_current_user(sqauthsession) ⇒ Object
- #save_username_for_current_user(username) ⇒ Object
- #session_for_current_user ⇒ Object
- #set_callback(actual_callback) ⇒ Object
- #sq_auth_filter(roles, project = @project_name, options = {}) ⇒ Object
- #when_not_authenticated(roles, project, options = {}) ⇒ Object
- #with_sq_auth(roles, project = @project_name, options = {}, &block) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ SqAuthAccess
Returns a new instance of SqAuthAccess.
8 9 10 11 12 13 14 15 16 |
# File 'lib/sq_auth/sq_auth_access.rb', line 8 def initialize ={} @options = @data_proc = DEFAULT_DATA_PROC @draw_proc = DEFAULT_DRAW_PROC @login_path = DEFAULT_ACCESS_PATH @gateway_ip = nil @forced_host = nil @forced_port = nil end |
Instance Attribute Details
#callback ⇒ Object
Returns the value of attribute callback.
7 8 9 |
# File 'lib/sq_auth/sq_auth_access.rb', line 7 def callback @callback end |
#forced_host ⇒ Object
Returns the value of attribute forced_host.
7 8 9 |
# File 'lib/sq_auth/sq_auth_access.rb', line 7 def forced_host @forced_host end |
#forced_port ⇒ Object
Returns the value of attribute forced_port.
7 8 9 |
# File 'lib/sq_auth/sq_auth_access.rb', line 7 def forced_port @forced_port end |
#gateway_ip ⇒ Object
Returns the value of attribute gateway_ip.
7 8 9 |
# File 'lib/sq_auth/sq_auth_access.rb', line 7 def gateway_ip @gateway_ip end |
#login_path ⇒ Object
Returns the value of attribute login_path.
7 8 9 |
# File 'lib/sq_auth/sq_auth_access.rb', line 7 def login_path @login_path end |
#project_name ⇒ Object
Returns the value of attribute project_name.
7 8 9 |
# File 'lib/sq_auth/sq_auth_access.rb', line 7 def project_name @project_name end |
Instance Method Details
#api_filter(roles, project = @project_name, when_ok, when_no_role, options) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/sq_auth/sq_auth_access.rb', line 50 def api_filter(roles, project = @project_name, when_ok, when_no_role, ) check_session_provider not_logged_in_proc = get_not_logged_in_proc([:draw]) if sq_auth_filter(roles, project, ) when_ok.call else when_no_role.(not_logged_in_proc.(login_to, form_project_params(callback, roles, project), @session_provider.current_user_params)) end end |
#check_session_provider ⇒ Object
45 46 47 48 |
# File 'lib/sq_auth/sq_auth_access.rb', line 45 def check_session_provider raise "Authentication service not specified" unless @session_provider # raise "Authentication service unavailable" unless @session_provider.available? end |
#connect(options = {}) {|_self| ... } ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/sq_auth/sq_auth_access.rb', line 18 def connect = {} = DEFAULT_OPTIONS.merge() @project_name = [:project] @gateway_ip = [:gateway_ip] @forced_port = [:forced_host] @forced_host = [:forced_port] yield self if block_given? SqAuthIntegration.alter_environment @session_provider = SqAuthClient.new end |
#current_user_ip=(ip) ⇒ Object
107 108 109 110 111 112 113 |
# File 'lib/sq_auth/sq_auth_access.rb', line 107 def current_user_ip= ip if @gateway_ip @session_provider.user.user_ip = @gateway_ip else @session_provider.user.user_ip = ip end end |
#current_user_name=(name) ⇒ Object
115 116 117 |
# File 'lib/sq_auth/sq_auth_access.rb', line 115 def current_user_name= name @session_provider.user.user_name = name end |
#data_when_not_logged_in(&block) ⇒ Object
33 34 35 |
# File 'lib/sq_auth/sq_auth_access.rb', line 33 def data_when_not_logged_in &block @data_proc = Proc.new {|*args| block.call(*args)} end |
#draw_when_not_authenticated(roles, project = @project_name) ⇒ Object
73 74 75 |
# File 'lib/sq_auth/sq_auth_access.rb', line 73 def draw_when_not_authenticated(roles, project = @project_name) when_not_authenticated(roles, project, {:draw => true}) end |
#draw_when_not_logged_in(&block) ⇒ Object
29 30 31 |
# File 'lib/sq_auth/sq_auth_access.rb', line 29 def draw_when_not_logged_in &block @draw_proc = block end |
#form_project_params(callback, roles, project) ⇒ Object
64 65 66 |
# File 'lib/sq_auth/sq_auth_access.rb', line 64 def form_project_params callback, roles, project {callback: callback, roles: [*roles], auth_name: project} end |
#get_not_logged_in_proc(type = nil) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/sq_auth/sq_auth_access.rb', line 37 def get_not_logged_in_proc type = nil if type == true || type.nil? @draw_proc else @data_proc end end |
#login_to ⇒ Object
123 124 125 126 127 |
# File 'lib/sq_auth/sq_auth_access.rb', line 123 def login_to uri = @session_provider.auth_server_uri uri.path = "#@login_path" uri.to_s end |
#message_when_not_authenticated(roles = [], project = @project_name) ⇒ Object
77 78 79 |
# File 'lib/sq_auth/sq_auth_access.rb', line 77 def (roles = [], project = @project_name) when_not_authenticated(roles, project, {:draw => false}) end |
#revoke_session(sqauthsession) ⇒ Object
99 100 101 |
# File 'lib/sq_auth/sq_auth_access.rb', line 99 def revoke_session sqauthsession @session_provider.delete_session(sqauthsession) end |
#roles_for_current_user(project = @project_name) ⇒ Object
91 92 93 |
# File 'lib/sq_auth/sq_auth_access.rb', line 91 def roles_for_current_user project = @project_name @session_provider.roles_for_current_user project end |
#save_session_for_current_user(sqauthsession) ⇒ Object
95 96 97 |
# File 'lib/sq_auth/sq_auth_access.rb', line 95 def save_session_for_current_user sqauthsession @session_provider.create_session_for_current_user sqauthsession end |
#save_username_for_current_user(username) ⇒ Object
103 104 105 |
# File 'lib/sq_auth/sq_auth_access.rb', line 103 def save_username_for_current_user username @session_provider.username = username end |
#session_for_current_user ⇒ Object
119 120 121 |
# File 'lib/sq_auth/sq_auth_access.rb', line 119 def session_for_current_user @session_provider.session_for_current_user end |
#set_callback(actual_callback) ⇒ Object
129 130 131 132 133 134 |
# File 'lib/sq_auth/sq_auth_access.rb', line 129 def set_callback(actual_callback) callback_uri = URI.parse(actual_callback) callback_uri.port = @forced_port.to_i if @forced_port callback_uri.host = @forced_host if @forced_host @callback = callback_uri.to_s end |
#sq_auth_filter(roles, project = @project_name, options = {}) ⇒ Object
60 61 62 |
# File 'lib/sq_auth/sq_auth_access.rb', line 60 def sq_auth_filter(roles, project = @project_name, = {}) @session_provider.session_for_current_user && @session_provider.role_exist_for_current_user?(roles, project) end |
#when_not_authenticated(roles, project, options = {}) ⇒ Object
68 69 70 71 |
# File 'lib/sq_auth/sq_auth_access.rb', line 68 def when_not_authenticated(roles, project, = {}) not_logged_in_proc = get_not_logged_in_proc([:draw]) not_logged_in_proc.call(login_to, form_project_params(callback, roles, project), @session_provider.current_user_params) end |
#with_sq_auth(roles, project = @project_name, options = {}, &block) ⇒ Object
81 82 83 84 85 86 87 88 89 |
# File 'lib/sq_auth/sq_auth_access.rb', line 81 def with_sq_auth(roles, project = @project_name, = {}, &block) check_session_provider binded_self = [:binding].is_a?(Binding) ? eval("self", [:binding]) : self if sq_auth_filter(roles, project, ) binded_self.instance_eval(&block) if block_given? else when_not_authenticated(roles, project, ) end end |