PageRenderTime 39ms CodeModel.GetById 29ms app.highlight 7ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/galaxy/web/framework/openid_manager.py

https://bitbucket.org/cistrome/cistrome-harvard/
Python | 53 lines | 43 code | 6 blank | 4 comment | 8 complexity | 92cdec79f1b2a7b2c16660480908c95b MD5 | raw file
 1"""
 2Manage the OpenID consumer and related data stores.
 3"""
 4
 5import os, pickle, logging
 6
 7from galaxy import eggs
 8eggs.require( 'python-openid' )
 9
10import openid
11from openid import oidutil
12from openid.store import filestore
13from openid.consumer import consumer
14from openid.extensions import sreg
15
16log = logging.getLogger( __name__ )
17def oidlog( message, level=0 ):
18    log.debug( message )
19oidutil.log = oidlog
20
21class OpenIDManager( object ):
22    def __init__( self, cache_path ):
23        self.session_path = os.path.join( cache_path, 'session' )
24        self.store_path = os.path.join( cache_path, 'store' )
25        for dir in self.session_path, self.store_path:
26            if not os.path.exists( dir ):
27                os.makedirs( dir )
28        self.store = filestore.FileOpenIDStore( self.store_path )
29    def get_session( self, trans ):
30        session_file = os.path.join( self.session_path, str( trans.galaxy_session.id ) )
31        if not os.path.exists( session_file ):
32            pickle.dump( dict(), open( session_file, 'w' ) )
33        return pickle.load( open( session_file ) )
34    def persist_session( self, trans, oidconsumer ):
35        session_file = os.path.join( self.session_path, str( trans.galaxy_session.id ) )
36        pickle.dump( oidconsumer.session, open( session_file, 'w' ) )
37    def get_consumer( self, trans ):
38        return consumer.Consumer( self.get_session( trans ), self.store )
39    def add_sreg( self, trans, request, required=None, optional=None ):
40        if required is None:
41            required = []
42        if optional is None:
43            optional = []
44        sreg_request = sreg.SRegRequest( required=required, optional=optional )
45        request.addExtension( sreg_request )
46    def get_sreg( self, info ):
47        return sreg.SRegResponse.fromSuccessResponse( info )
48
49    # so I don't have to expose all of openid.consumer.consumer
50    FAILURE = consumer.FAILURE
51    SUCCESS = consumer.SUCCESS
52    CANCEL = consumer.CANCEL
53    SETUP_NEEDED = consumer.SETUP_NEEDED