Development of an internal social media platform with personalised dashboards for students
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

sessiontrack.py 2.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # -*- coding: utf-8 -*-
  2. """
  3. ldap.controls.sessiontrack - class for session tracking control
  4. (see draft-wahl-ldap-session)
  5. See https://www.python-ldap.org/ for project details.
  6. """
  7. from ldap.controls import RequestControl
  8. from pyasn1.type import namedtype,univ
  9. from pyasn1.codec.ber import encoder
  10. from pyasn1_modules.rfc2251 import LDAPString,LDAPOID
  11. # OID constants
  12. SESSION_TRACKING_CONTROL_OID = "1.3.6.1.4.1.21008.108.63.1"
  13. SESSION_TRACKING_FORMAT_OID_RADIUS_ACCT_SESSION_ID = SESSION_TRACKING_CONTROL_OID+".1"
  14. SESSION_TRACKING_FORMAT_OID_RADIUS_ACCT_MULTI_SESSION_ID = SESSION_TRACKING_CONTROL_OID+".2"
  15. SESSION_TRACKING_FORMAT_OID_USERNAME = SESSION_TRACKING_CONTROL_OID+".3"
  16. class SessionTrackingControl(RequestControl):
  17. """
  18. Class for Session Tracking Control
  19. Because criticality MUST be false for this control it cannot be set
  20. from the application.
  21. sessionSourceIp
  22. IP address of the request source as string
  23. sessionSourceName
  24. Name of the request source as string
  25. formatOID
  26. OID as string specifying the format
  27. sessionTrackingIdentifier
  28. String containing a specific tracking ID
  29. """
  30. class SessionIdentifierControlValue(univ.Sequence):
  31. componentType = namedtype.NamedTypes(
  32. namedtype.NamedType('sessionSourceIp',LDAPString()),
  33. namedtype.NamedType('sessionSourceName',LDAPString()),
  34. namedtype.NamedType('formatOID',LDAPOID()),
  35. namedtype.NamedType('sessionTrackingIdentifier',LDAPString()),
  36. )
  37. controlType = SESSION_TRACKING_CONTROL_OID
  38. def __init__(self,sessionSourceIp,sessionSourceName,formatOID,sessionTrackingIdentifier):
  39. # criticality MUST be false for this control
  40. self.criticality = False
  41. self.sessionSourceIp,self.sessionSourceName,self.formatOID,self.sessionTrackingIdentifier = \
  42. sessionSourceIp,sessionSourceName,formatOID,sessionTrackingIdentifier
  43. def encodeControlValue(self):
  44. s = self.SessionIdentifierControlValue()
  45. s.setComponentByName('sessionSourceIp',LDAPString(self.sessionSourceIp))
  46. s.setComponentByName('sessionSourceName',LDAPString(self.sessionSourceName))
  47. s.setComponentByName('formatOID',LDAPOID(self.formatOID))
  48. s.setComponentByName('sessionTrackingIdentifier',LDAPString(self.sessionTrackingIdentifier))
  49. return encoder.encode(s)