Esempio n. 1
0
def pas_logger(event):
    """Log authentication events like users logging in and loggin out."""
    name = IFingerPointingSettings.__identifier__ + '.audit_pas'
    try:
        audit_pas = api.portal.get_registry_record(name, default=False)
    except ComponentLookupError:  # plonectl adduser
        return

    if not audit_pas:
        return

    user, ip = get_request_information()

    if IUserLoggedInEvent.providedBy(event):
        action = 'login'
        extras = ''
    elif IUserLoggedOutEvent.providedBy(event):
        action = 'logout'
        extras = ''
    elif IPrincipalCreatedEvent.providedBy(event):
        action = 'create'
        extras = 'principal=' + str(event.principal)
    elif IPrincipalDeletedEvent.providedBy(event):
        action = 'remove'
        extras = 'user='******'remove'
        extras = 'group=' + str(event.principal)
    else:  # should never happen
        action = 'UNKNOWN'
        extras = ''

    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
Esempio n. 2
0
def pas_logger(event):
    """Log authentication events like users logging in and loggin out."""
    # subscriber is registered even if package has not yet been installed
    # ignore any error caused by missing registry records
    try:
        record = IFingerPointingSettings.__identifier__ + '.audit_pas'
        audit_pas = api.portal.get_registry_record(record)
    except InvalidParameterError:
        return

    if audit_pas:
        user, ip = get_request_information()
        if IUserLoggedInEvent.providedBy(event):
            action = 'login'
            extras = ''
        elif IUserLoggedOutEvent.providedBy(event):
            action = 'logout'
            extras = ''
        elif IPrincipalCreatedEvent.providedBy(event):
            action = 'create'
            extras = u'principal={0}'.format(event.principal)
        elif IPrincipalDeletedEvent.providedBy(event):
            action = 'remove'
            extras = u'user={0}'.format(event.principal)
        if IGroupDeletedEvent.providedBy(event):
            action = 'remove'
            extras = u'group={0}'.format(event.principal)

        log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
def pas_logger(event):
    """Log authentication events like users logging in and loggin out."""
    name = IFingerPointingSettings.__identifier__ + '.audit_pas'
    try:
        audit_pas = api.portal.get_registry_record(name, default=False)
    except ComponentLookupError:  # plonectl adduser
        return

    if not audit_pas:
        return

    user, ip = get_request_information()

    if IUserLoggedInEvent.providedBy(event):
        action = 'login'
        extras = ''
    elif IUserLoggedOutEvent.providedBy(event):
        action = 'logout'
        extras = ''
    elif IPrincipalCreatedEvent.providedBy(event):
        action = 'create'
        extras = 'principal=' + str(event.principal)
    elif IPrincipalDeletedEvent.providedBy(event):
        action = 'remove'
        extras = 'user='******'remove'
        extras = 'group=' + str(event.principal)
    else:  # should never happen
        action = 'UNKNOWN'
        extras = ''

    log_info(AUDIT_MESSAGE.format(user, ip, action, extras))
    def testUserCreationEvent(self):
        provideHandler(userCreatedHandler)
        self.uf.events = []

        self.uf._doAddUser('event1', 'secret', ['role1'], [])

        self.assertEqual(len(self.uf.events), 1)
        event = self.uf.events[0]
        self.assertTrue(IPrincipalCreatedEvent.providedBy(event))
        self.assertEqual(event.principal.getUserName(), 'event1')
        self.assertEqual(event.principal.getId(), 'event1')
Esempio n. 5
0
    def testUserCreationEvent(self):
        provideHandler(userCreatedHandler)
        self.uf.events = []

        self.uf._doAddUser('event1', 'secret', ['role1'], [])

        self.assertEqual(len(self.uf.events), 1)
        event = self.uf.events[0]
        self.failUnless(IPrincipalCreatedEvent.providedBy(event))
        self.assertEqual(event.principal.getUserName(), 'event1')
        self.assertEqual(event.principal.getId(), 'event1')