Class: Strelka::AuthProvider
- Inherits:
-
Object
- Object
- Strelka::AuthProvider
- Extended by:
- Loggability, Pluggability, AbstractClass, Delegation
- Includes:
- Constants, ResponseHelpers
- Defined in:
- lib/strelka/authprovider.rb
Overview
This is the abstract base class for authentication and/or authorization providers for the :auth plugin.
To define your own authentication provider, you'll need to inherit this class (either directly or via a subclass), name it Strelka::AuthProvider::{Something}, save it in a file named strelka/authprovider/{something}.rb, and override the required methods.
Which methods you'll need to provide implementations for depends on whether your provider provides authentication, authorization, or both.
Authentication Providers
Authentication providers should override either one or both of the following methods, depending on whether they will provide authentication, authorization, or both:
- #authenticate
- #authorize
Direct Known Subclasses
Defined Under Namespace
Classes: Basic, HostAccess
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
The Strelka::App that the AuthProvider belongs to.
Instance Method Summary collapse
-
#auth_succeeded(request, credentials) ⇒ Object
Callback for auth success; the auth provider should use this to add cookies, headers, or whatever to the request or response when the client becomes authenticated.
-
#authenticate(request) ⇒ Object
You should override this method if you want to authenticate the
request. -
#authorize(credentials, request, perms) ⇒ Object
You should override this method if you want to provide authorization in your provider.
-
#initialize(app) ⇒ AuthProvider
constructor
Create a new AuthProvider for the given
app.
Methods included from Delegation
def_class_delegators, def_ivar_delegators, def_method_delegators
Methods included from AbstractClass
extended, included, inherited, pure_virtual
Methods included from ResponseHelpers
Constructor Details
#initialize(app) ⇒ AuthProvider
Create a new AuthProvider for the given app.
53 54 55 |
# File 'lib/strelka/authprovider.rb', line 53 def initialize( app ) @app = app end |
Instance Attribute Details
#app ⇒ Object (readonly)
The Strelka::App that the AuthProvider belongs to.
64 65 66 |
# File 'lib/strelka/authprovider.rb', line 64 def app @app end |
Instance Method Details
#auth_succeeded(request, credentials) ⇒ Object
Callback for auth success; the auth provider should use this to add cookies, headers, or whatever to the request or response when the client becomes authenticated. This is a no-op by default.
78 79 80 81 |
# File 'lib/strelka/authprovider.rb', line 78 def auth_succeeded( request, credentials ) self.log.info "Authentication for %p succeeded." % [ credentials ] # No-op by default end |
#authenticate(request) ⇒ Object
You should override this method if you want to authenticate the request. It should
return a credentials object if authentication is successful, or a false value if it fails.
69 70 71 72 |
# File 'lib/strelka/authprovider.rb', line 69 def authenticate( request ) self.log.debug "No authentication provided, returning anonymous credentials." return 'anonymous' end |
#authorize(credentials, request, perms) ⇒ Object
You should override this method if you want to provide authorization in your
provider. The credentials will be the same object as the one returned by #authenticate,
the request is the current Strelka::HTTPRequest, and perms is the Array of Symbols
the represents the permissions that apply to the request as specified by the
application's require_perms_for and no_perms_for declarations, as an Array of
Symbols.
The default behavior is to throw an 403 FORBIDDEN response if any perms were
required.
93 94 95 96 |
# File 'lib/strelka/authprovider.rb', line 93 def ( credentials, request, perms ) return true if perms.empty? self. end |