__init__.py :  » Blog » Frog » FrogComplete-1.8 » snakeserver » plugins » sharedauth » Python Open Source

Home
Python Open Source
1.3.1.2 Python
2.Ajax
3.Aspect Oriented
4.Blog
5.Build
6.Business Application
7.Chart Report
8.Content Management Systems
9.Cryptographic
10.Database
11.Development
12.Editor
13.Email
14.ERP
15.Game 2D 3D
16.GIS
17.GUI
18.IDE
19.Installer
20.IRC
21.Issue Tracker
22.Language Interface
23.Log
24.Math
25.Media Sound Audio
26.Mobile
27.Network
28.Parser
29.PDF
30.Project Management
31.RSS
32.Search
33.Security
34.Template Engines
35.Test
36.UML
37.USB Serial
38.Web Frameworks
39.Web Server
40.Web Services
41.Web Unit
42.Wiki
43.Windows
44.XML
Python Open Source » Blog » Frog 
Frog » FrogComplete 1.8 » snakeserver » plugins » sharedauth » __init__.py
#############################################################################
#
#  $Id: __init__.py,v 1.5 2005/05/01 17:18:10 irmen Exp $
#  Shared Authentication plugin
#
#  This is part of "Snakelets" - Python Web Application Server
#  which is (c) Irmen de Jong - irmen@users.sourceforge.net
#
#############################################################################

from snakeserver.plugin import ServerPlugin
import logging
import weakref

log=logging.getLogger("Snakelets.logger")


#
#   Plugin to facilitate cross-webapp authentication (shared authentication)
#   so that different webapps can use a single authentication method
#   and a single userbase.
#   Note that single-signon (so that the user only has to log in one time,
#   and that other webapps share the login info) is not and cannot be done
#   by this service. You have to configure sharedSession for that.
#
#   When the authorization method from another webapp is called, there
#   is a special field in the Request object: authorizingWebApp
#   which is set to the authorizing webapp object. This is useful because
#   often the authorization method needs "its own" webapp to do stuff,
#   and the webapp from the Request object is not its own, in this case!
#
ENABLED=True
PLUGINS=[ "SharedAuth" ]      # this MUST be the name ("SharedAuth"); the server looks for this

class SharedAuth(ServerPlugin):
    # PLUGIN_NAME="SharedAuth" # the classname is correct so use that
    # PLUGIN_SEQ=... # default sequence is just fine
    def plug_init(self,server):
        log.debug("Shared Auth plugin init")
        self.webappMapping=weakref.WeakValueDictionary()    # webapp name string->webapp obj
    def plug_sessionCreated(self, webapp, session, request):
        pass
    def plug_sessionDestroyed(self, webapp, session, request):
        pass

    def addWebappMapping(self, srcWebappName, targetWebappObj):
        self.webappMapping[srcWebappName]=targetWebappObj
        
    def authorizeUser(self, authmethod, url, username, password, request):
        name=request.getWebApp().getName()[0]
        target=self.webappMapping.get(name)
        if target and target.authorizeUser:
            request.authorizingWebApp = target   # for easy reference from the auth method
            return target.authorizeUser(authmethod, url, username, password, request)
        return None

www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.