doc/book/en/devrepo/repo/sessions.rst
author Aurelien Campeas <aurelien.campeas@logilab.fr>
Wed, 22 Sep 2010 20:12:38 +0200
branchstable
changeset 6313 b3fd91524132
parent 6311 afd6a9e45489
child 6319 20a7399ed58d
permissions -rw-r--r--
[doc/book] begin an howto write auth plugins chapter
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     1
.. -*- coding: utf-8 -*-
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     2
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     3
Sessions
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     4
========
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
     5
6311
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
     6
Sessions are object carrying the `.execute` method to query the data
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
     7
sources.
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
     8
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
     9
Kinds of sessions
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    10
-----------------
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    11
6298
f4347f796908 [doc/book] fix session types
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 5394
diff changeset
    12
There are two kinds of sessions.
2112
df86450ca65d [doc] a note on sessions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    13
6311
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    14
* `normal sessions` are the most common: they are related to users and
2112
df86450ca65d [doc] a note on sessions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    15
  carry security checks coming with user credentials
df86450ca65d [doc] a note on sessions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    16
2539
0f26a76b0348 [doc] some more rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2112
diff changeset
    17
* `internal sessions` have all the powers; they are also used in only a
2112
df86450ca65d [doc] a note on sessions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    18
  few situations where you don't already have an adequate session at
df86450ca65d [doc] a note on sessions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    19
  hand, like: user authentication, data synchronisation in
df86450ca65d [doc] a note on sessions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    20
  multi-source contexts
df86450ca65d [doc] a note on sessions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    21
2539
0f26a76b0348 [doc] some more rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2112
diff changeset
    22
.. note::
0f26a76b0348 [doc] some more rewriting
Nicolas Chauvat <nicolas.chauvat@logilab.fr>
parents: 2112
diff changeset
    23
  Do not confuse the session type with their connection mode, for
6311
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    24
  instance : `in memory` or `pyro`.
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    25
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    26
Normal sessions are typically named `_cw` in most appobjects or
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    27
sometimes just `session`.
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    28
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    29
Internal sessions are available from the `Repository` object and are
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    30
to be used like this:
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    31
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    32
.. sourcecode:: python
6313
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    33
6311
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    34
   session = self.repo.internal_session()
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    35
   try:
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    36
       # do stuff
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    37
   finally:
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    38
       session.close()
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    39
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    40
.. warning::
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    41
  Do not forget to close such a session after use for a session leak
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    42
  will quickly lead to an application crash.
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    43
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    44
Authentication and management of sessions
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    45
-----------------------------------------
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    46
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    47
The authentication process is a ballet involving a few dancers:
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    48
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    49
* through its `connect` method the top-level application object (the
6313
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    50
  `CubicWebPublisher`) will open a session whenever a web request
6311
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    51
  comes in; it asks the `session manager` to open a session (giving
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    52
  the web request object as context) using `open_session`
2112
df86450ca65d [doc] a note on sessions
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 1714
diff changeset
    53
6311
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    54
  * the session manager asks its authentication manager (which is a
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    55
    `component`) to authenticate the request (using `authenticate`)
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    56
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    57
    * the authentication manager asks, in order, to its authentication
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    58
      information retrievers, a login and an opaque object containing
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    59
      other credentials elements (calling `authentication_information`),
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    60
      giving the request object each time
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    61
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    62
      * the default retriever (bizarrely named
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    63
        `LoginPaswordRetreiver`) will in turn defer login and password
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    64
        fetching to the request object (which, depending on the
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    65
        authentication mode (`cookie` or `http`), will do the
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    66
        appropriate things and return a login and a password)
1714
a721966779be new book layout, do not compile yet
sylvain.thenault@logilab.fr
parents:
diff changeset
    67
6311
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    68
    * the authentication manager, on success, asks the `Repository`
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    69
      object to connect with the found credentials (using `connect`)
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    70
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    71
      * the repository object asks authentication to all of its
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    72
        sources which support the `CWUser` entity with the given
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    73
        credentials; when successful it can build the cwuser entity,
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    74
        from which a regular `Session` object is made; it returns the
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    75
        session id
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    76
6313
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    77
        * the source in turn will defer work to an authentifier class
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    78
          that define the ultimate `authenticate` method (for instance
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    79
          the native source will query the database against the
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    80
          provided credentials)
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    81
6311
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    82
    * the authentication manager, on success, will call back _all_
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    83
      retrievers with `authenticated` and return its authentication
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    84
      data (on failure, it will try the anonymous login or, if the
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    85
      configuration forbids it, raise an `AuthenticationError`)
afd6a9e45489 [doc/book] tell a more complete story on sessions and the authentication process
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6298
diff changeset
    86
6313
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    87
Writing authentication plugins
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    88
------------------------------
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    89
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    90
Sometimes CubicWeb's out-of-the-box authentication schemes (cookie and
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    91
http) are not sufficient. Nowadays there is a plethore of such schemes
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    92
and the framework cannot provide them all, but as the sequence above
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    93
may show, it is extensible.
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    94
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    95
Two levels have to be considered when writing an authentication
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    96
plugin: the web client the repository.
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    97
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    98
On the repository side, it is possible to register a source
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
    99
authentifier using the following kind of code:
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   100
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   101
.. sourcecode:: python
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   102
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   103
 from cubicweb.server.sources import native
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   104
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   105
 class FooAuthentifier(native.BaseAuthentifier):
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   106
     """ a source authentifier plugin
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   107
     if the password is 'foo', it's ok
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   108
     """
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   109
     auth_rql = ('Any X,P WHERE X is CWUser, X login %(login)s, X upassword P')
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   110
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   111
     def authenticate(self, session, login, **kwargs):
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   112
         """return CWUser eid for the given login
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   113
         if this account is defined in this source,
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   114
         else raise `AuthenticationError`
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   115
         """
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   116
         session.debug('authentication by %s', self.__class__.__name__)
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   117
         try:
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   118
             rset = session.execute(self.auth_rql, {'login': login})
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   119
             if rset[0][1].lower() == u'foo':
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   120
                 return rset[0][0]
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   121
         except Exception, exc:
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   122
             session.debug('authentication failure (%s)', exc)
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   123
             pass
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   124
         raise AuthenticationError('user password is not foo')
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   125
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   126
 class ServerStartupHook(hook.Hook):
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   127
     """ register the foo authenticator """
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   128
     __regid__ = 'fooauthenticatorregisterer'
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   129
     events = ('server_startup',)
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   130
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   131
     def __call__(self):
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   132
         self.debug('registering foo authentifier')
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   133
         self.repo.system_source.add_authentifier(FooAuthentifier())
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   134
b3fd91524132 [doc/book] begin an howto write auth plugins chapter
Aurelien Campeas <aurelien.campeas@logilab.fr>
parents: 6311
diff changeset
   135