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, callback, role, project, session| SqAuthUtils::default_draw_template(uri, callback, role, project, session)}
- DEFAULT_DATA_PROC =
Proc.new { "Forbidden" }
- DEFAULT_OPTIONS =
{project: "Project", https: true}
Instance Attribute Summary collapse
-
#callback ⇒ Object
Returns the value of attribute callback.
-
#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
- #data_when_not_logged_in(&block) ⇒ Object
- #draw_when_not_authenticated(roles, project = @project_name) ⇒ Object
- #draw_when_not_logged_in(&block) ⇒ 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
- #save_session_for_current_user(sqauthsession) ⇒ 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 |
# 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 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 |
#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
46 47 48 49 50 51 52 53 54 |
# File 'lib/sq_auth/sq_auth_access.rb', line 46 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, callback, roles, project, @session_provider.session_for_current_user)) end end |
#check_session_provider ⇒ Object
41 42 43 44 |
# File 'lib/sq_auth/sq_auth_access.rb', line 41 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
16 17 18 19 20 21 22 23 |
# File 'lib/sq_auth/sq_auth_access.rb', line 16 def connect = {} = DEFAULT_OPTIONS.merge() @project_name = [:project] @gateway_ip = [:gateway_ip] yield self if block_given? SqAuthIntegration.alter_environment @session_provider = SqAuthClient.new end |
#current_user_ip=(ip) ⇒ Object
88 89 90 91 92 93 94 95 |
# File 'lib/sq_auth/sq_auth_access.rb', line 88 def current_user_ip= ip if @gateway_ip @session_provider.user.user_ip = @gateway_ip else @session_provider.user.user_ip = ip end p @session_provider.user.user_ip end |
#data_when_not_logged_in(&block) ⇒ Object
29 30 31 |
# File 'lib/sq_auth/sq_auth_access.rb', line 29 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
66 67 68 |
# File 'lib/sq_auth/sq_auth_access.rb', line 66 def draw_when_not_authenticated(roles, project = @project_name) when_not_authenticated(roles, project, {:draw => true}) end |
#draw_when_not_logged_in(&block) ⇒ Object
25 26 27 |
# File 'lib/sq_auth/sq_auth_access.rb', line 25 def draw_when_not_logged_in &block @draw_proc = block end |
#get_not_logged_in_proc(type = nil) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/sq_auth/sq_auth_access.rb', line 33 def get_not_logged_in_proc type = nil if type == true || type.nil? @draw_proc else @data_proc end end |
#login_to ⇒ Object
97 98 99 100 101 |
# File 'lib/sq_auth/sq_auth_access.rb', line 97 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
70 71 72 |
# File 'lib/sq_auth/sq_auth_access.rb', line 70 def (roles = [], project = @project_name) when_not_authenticated(roles, project, {:draw => false}) end |
#save_session_for_current_user(sqauthsession) ⇒ Object
84 85 86 |
# File 'lib/sq_auth/sq_auth_access.rb', line 84 def save_session_for_current_user sqauthsession @session_provider.create_session_for_current_user sqauthsession end |
#sq_auth_filter(roles, project = @project_name, options = {}) ⇒ Object
56 57 58 |
# File 'lib/sq_auth/sq_auth_access.rb', line 56 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
61 62 63 64 |
# File 'lib/sq_auth/sq_auth_access.rb', line 61 def when_not_authenticated(roles, project, = {}) not_logged_in_proc = get_not_logged_in_proc([:draw]) not_logged_in_proc.call(login_to, callback, roles, project, @session_provider.session_for_current_user) end |
#with_sq_auth(roles, project = @project_name, options = {}, &block) ⇒ Object
74 75 76 77 78 79 80 81 82 |
# File 'lib/sq_auth/sq_auth_access.rb', line 74 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 |