Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
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.

cred_file.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. # -*- test-case-name: twisted.test.test_strcred -*-
  2. #
  3. # Copyright (c) Twisted Matrix Laboratories.
  4. # See LICENSE for details.
  5. """
  6. Cred plugin for a file of the format 'username:password'.
  7. """
  8. import sys
  9. from zope.interface import implementer
  10. from twisted import plugin
  11. from twisted.cred.checkers import FilePasswordDB
  12. from twisted.cred.credentials import IUsernameHashedPassword, IUsernamePassword
  13. from twisted.cred.strcred import ICheckerFactory
  14. fileCheckerFactoryHelp = """
  15. This checker expects to receive the location of a file that
  16. conforms to the FilePasswordDB format. Each line in the file
  17. should be of the format 'username:password', in plain text.
  18. """
  19. invalidFileWarning = "Warning: not a valid file"
  20. @implementer(ICheckerFactory, plugin.IPlugin)
  21. class FileCheckerFactory:
  22. """
  23. A factory for instances of L{FilePasswordDB}.
  24. """
  25. authType = "file"
  26. authHelp = fileCheckerFactoryHelp
  27. argStringFormat = "Location of a FilePasswordDB-formatted file."
  28. # Explicitly defined here because FilePasswordDB doesn't do it for us
  29. credentialInterfaces = (IUsernamePassword, IUsernameHashedPassword)
  30. errorOutput = sys.stderr
  31. def generateChecker(self, argstring):
  32. """
  33. This checker factory expects to get the location of a file.
  34. The file should conform to the format required by
  35. L{FilePasswordDB} (using defaults for all
  36. initialization parameters).
  37. """
  38. from twisted.python.filepath import FilePath
  39. if not argstring.strip():
  40. raise ValueError("%r requires a filename" % self.authType)
  41. elif not FilePath(argstring).isfile():
  42. self.errorOutput.write(f"{invalidFileWarning}: {argstring}\n")
  43. return FilePasswordDB(argstring)
  44. theFileCheckerFactory = FileCheckerFactory()