diff options
author | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2020-10-28 00:21:21 +0200 |
---|---|---|
committer | Ivan Kanakarakis <ivan.kanak@gmail.com> | 2020-10-28 00:24:38 +0200 |
commit | cd7f2390971dcfea146947606f62c4188d70dbbd (patch) | |
tree | 372c42233e3ad4b3cbbbefae953095c42a273a92 | |
parent | f926ba9da277402b48dbe355a0054c8dcf2d3fc9 (diff) | |
download | pysaml2-cd7f2390971dcfea146947606f62c4188d70dbbd.tar.gz |
Warn and log warning messages
Signed-off-by: Ivan Kanakarakis <ivan.kanak@gmail.com>
-rw-r--r-- | src/saml2/client_base.py | 5 | ||||
-rw-r--r-- | src/saml2/config.py | 9 | ||||
-rw-r--r-- | src/saml2/cryptography/symmetric.py | 18 | ||||
-rw-r--r-- | src/saml2/server.py | 5 |
4 files changed, 27 insertions, 10 deletions
diff --git a/src/saml2/client_base.py b/src/saml2/client_base.py index 5a70d885..28e08b84 100644 --- a/src/saml2/client_base.py +++ b/src/saml2/client_base.py @@ -9,6 +9,7 @@ import threading import six import time import logging +from warnings import warn as _warn from saml2.entity import Entity @@ -189,10 +190,12 @@ class Base(Entity): self.want_assertions_or_response_signed, ] ): - logger.warning( + warn_msg = ( "The SAML service provider accepts unsigned SAML Responses " "and Assertions. This configuration is insecure." ) + logger.warning(warn_msg) + _warn(warn_msg) self.artifact2response = {} diff --git a/src/saml2/config.py b/src/saml2/config.py index 2f6e13b0..25218788 100644 --- a/src/saml2/config.py +++ b/src/saml2/config.py @@ -8,6 +8,7 @@ import os import re import sys from logging.config import dictConfig as configure_logging_by_dict +from warnings import warn as _warn import six @@ -353,10 +354,12 @@ class Config(object): configure_logging_by_dict(self.logging) if not self.delete_tmpfiles: - logger.warning( - "delete_tmpfiles is set to False; " - "temporary files will not be deleted." + warn_msg = ( + "Configuration option `delete_tmpfiles` is set to False; " + "consider setting this to True to have temporary files deleted." ) + logger.warning(warn_msg) + _warn(warn_msg) if "service" in cnf: for typ in ["aa", "idp", "sp", "pdp", "aq"]: diff --git a/src/saml2/cryptography/symmetric.py b/src/saml2/cryptography/symmetric.py index b6dd6c2c..ff73641e 100644 --- a/src/saml2/cryptography/symmetric.py +++ b/src/saml2/cryptography/symmetric.py @@ -6,7 +6,8 @@ library. Reference: https://cryptography.io/en/latest/fernet/ import base64 as _base64 import os as _os -import warnings as _warnings +import logging +from warnings import warn as _warn import cryptography.fernet as _fernet import cryptography.hazmat.backends as _backends @@ -15,6 +16,9 @@ import cryptography.hazmat.primitives.ciphers as _ciphers from .errors import SymmetricCryptographyError +logger = logging.getLogger(__name__) + + class Fernet(object): """The default symmetric cryptography method.""" @@ -61,7 +65,8 @@ class Fernet(object): "Remove any other arguements. " "In the next version, this method will not allow them." ) - _warnings.warn(_deprecation_msg, DeprecationWarning) + logger.warning(_deprecation_msg) + _warn(_deprecation_msg, DeprecationWarning) ciphertext = self._symmetric.encrypt(plaintext) return ciphertext @@ -79,7 +84,8 @@ class Fernet(object): "Remove any other arguements. " "In the next version, this method will not allow them." ) - _warnings.warn(_deprecation_msg, DeprecationWarning) + logger.warning(_deprecation_msg) + _warn(_deprecation_msg, DeprecationWarning) plaintext = self._symmetric.decrypt(ciphertext) return plaintext @@ -90,7 +96,8 @@ class Fernet(object): "Remove any calls to this method. " "In the next version, this method will be removed." ) - _warnings.warn(_deprecation_msg, DeprecationWarning) + logger.warning(_deprecation_msg) + _warn(_deprecation_msg, DeprecationWarning) class AESCipher(object): @@ -116,7 +123,8 @@ class AESCipher(object): 'or saml2.cryptography.symmetric.Fernet ' 'instead.' ).format(name=cls.__name__, type=type(cls).__name__) - _warnings.warn(_deprecation_msg, DeprecationWarning) + logger.warning(_deprecation_msg) + _warn(_deprecation_msg, DeprecationWarning) def __init__(self, key): """ diff --git a/src/saml2/server.py b/src/saml2/server.py index 7857004b..6051be3a 100644 --- a/src/saml2/server.py +++ b/src/saml2/server.py @@ -7,6 +7,7 @@ or attribute authority (AA) may use to conclude its tasks. """ import logging import os +from warnings import warn as _warn import importlib import dbm @@ -526,7 +527,9 @@ class Server(Entity): try: name_id = self.ident.construct_nameid(userid, policy, sp_entity_id) - logger.warning("Unspecified NameID format") + warn_msg = "Unspecified NameID format" + logger.warning(warn_msg) + _warn(warn_msg) except Exception: pass |