Пример #1
0
    def decorator(function):
        context = Context()
        context.addService(Logger("SECURITY_MODULE"))

        def wrapper(self, *__args, **__kw):
            # Check if there is a user.
            token = SecurityToken()
            context.Logger().message("Checking authentication for user %s" %
                                     (token.dn))

            # NOTE: this part should be clarified once front-end/back-end
            # certificate-based auth. rules will be in place
            # so we we should just fail over to login/pw schema
            ### If user browser provide cert, extract this info and update token
            userDN = ""
            try:
                import cherrypy, time
                #                print "###",cherrypy.request.headers
                #                userDN  = cherrypy.request.headers['Ssl-Client-S-Dn']
                #                access  = cherrypy.request.headers['Ssl-Client-Verify']
                #                if  userDN!='(null)' and access=='SUCCESS':
                userDN = cherrypy.request.headers['Cms-Client-S-Dn']
                access = cherrypy.request.headers['Cms-Auth-Status']
                if userDN != '(null)' and access == 'OK':
                    context.Logger().message("Found DN in user certificate")
                    # SiteDB usees token.dn as username rather then DN itself, so name is misleading
                    userName = self.securityApi.getUsernameFromDN(
                        userDN)[0]['username']
                    token.impl.dn = userName
                    #                    token.impl.dn = userDN
                    aTime = time.strftime("%Y-%m-%dT%H:%M:%S", time.gmtime())
                    token.impl.authenticationTime = aTime
            except:
                #                traceback.print_exc()
                # redirect to https://cmsweb.cern.ch/sitedb/people/showAllEntries
                #                return redirectionToSiteDB(userDN)
                pass

            if token.dn in (None, "guest"):
                return onFail(self)
            # Check that the session has not expired.
            if not token.authenticationTime:
                return onFail(self)
            authenticationTime = datetime(
                *strptime(token.authenticationTime, "%Y-%m-%dT%H:%M:%S")[0:6])
            currentTime = datetime.now()
            # TODO: this should come from the configuration file.
            maxPeriod = timedelta(seconds=3600 * 24)
            if authenticationTime + maxPeriod < currentTime:
                context.Logger().message(
                    "Cookie has expired, authorisation failed.")
                return onFail(self)
            return function(self, *__args, **__kw)

        return wrapper
Пример #2
0
from Framework import Context


class A:
    def __init__(self, arg):
        self.__arg = arg

    def arg(self):
        return self.__arg


mainContext = Context()
mainContext.addService(A(0))
context = {}

for i in range(1, 3):
    context[i] = Context(mainContext)
    context[i].addService(A(i))

for i in range(1, 3):
    assert context[i].A().arg() != 0
    assert context[i].A().arg() == i
Пример #3
0
 def __init__ (self):
     self.context = Context ()
     self.context.addService (OptionParser ())
     self.parser = self.context.OptionParser ()
     self.__addOptions ()
Пример #4
0
from Framework import Context
from Framework.Logger import Logger

from Tools.SiteDBCore import SiteDBApi

context = Context()
context.addService(Logger("sitedbtest"))
api = SiteDBApi(context)

api.connect()
print api.getTierList()
Пример #5
0
    def __init__(self, foo):
        self.__foo = foo

    def foo(self):
        return self.__foo


class C(object):
    def __init__(self, foo):
        self.__foo = foo

    def foo(self):
        return self.__foo


c1 = Context()
c2 = Context(c1)
c1.addService(A("Service A on C1"))
c2.addService(A("Service A on C2"))
c1.addService(B("Service B on C1"))
c2.addService(C("Service C on C2"))

assert type(c1.A()) == type(A(""))
assert type(c2.A()) == type(A(""))
assert type(c1.B()) == type(B(""))
assert type(c2.B()) == type(B(""))
assert type(c2.C()) == type(C(""))
assert type(c1.A().foo()) == type(str())

assert c1.A().foo() == "Service A on C1"
assert c2.A().foo() == "Service A on C2"
Пример #6
0
from Framework import Context


class Component(object):
    def foo(self):
        return "A component"


c = Context()
c.addService(Component())
assert c.Component().foo() == "A component"