本文整理汇总了Python中saml2.config.SPConfig.getattr方法的典型用法代码示例。如果您正苦于以下问题:Python SPConfig.getattr方法的具体用法?Python SPConfig.getattr怎么用?Python SPConfig.getattr使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类saml2.config.SPConfig
的用法示例。
在下文中一共展示了SPConfig.getattr方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: from saml2.config import SPConfig [as 别名]
# 或者: from saml2.config.SPConfig import getattr [as 别名]
def __init__(self, outgoing, internal_attributes, config, base_url, name):
"""
:type outgoing:
(satosa.context.Context, satosa.internal.InternalData) -> satosa.response.Response
:type internal_attributes: dict[str, dict[str, list[str] | str]]
:type config: dict[str, Any]
:type base_url: str
:type name: str
:param outgoing: Callback should be called by the module after
the authorization in the backend is done.
:param internal_attributes: Internal attribute map
:param config: The module config
:param base_url: base url of the service
:param name: name of the plugin
"""
super().__init__(outgoing, internal_attributes, base_url, name)
self.config = self.init_config(config)
sp_config = SPConfig().load(copy.deepcopy(config[self.KEY_SP_CONFIG]), False)
self.sp = Base(sp_config)
self.discosrv = config.get(self.KEY_DISCO_SRV)
self.encryption_keys = []
self.outstanding_queries = {}
self.idp_blacklist_file = config.get('idp_blacklist_file', None)
sp_keypairs = sp_config.getattr('encryption_keypairs', '')
sp_key_file = sp_config.getattr('key_file', '')
if sp_keypairs:
key_file_paths = [pair['key_file'] for pair in sp_keypairs]
elif sp_key_file:
key_file_paths = [sp_key_file]
else:
key_file_paths = []
for p in key_file_paths:
with open(p) as key_file:
self.encryption_keys.append(key_file.read())
示例2: test_2
# 需要导入模块: from saml2.config import SPConfig [as 别名]
# 或者: from saml2.config.SPConfig import getattr [as 别名]
def test_2():
c = SPConfig().load(sp2)
c.context = "sp"
print c
assert c._sp_endpoints
assert c.getattr("endpoints", "sp")
assert c._sp_idp
assert c._sp_optional_attributes
assert c.name
assert c._sp_required_attributes
assert len(c._sp_idp) == 1
assert c._sp_idp.keys() == [""]
assert c._sp_idp.values() == ["https://example.com/saml2/idp/SSOService.php"]
assert c.only_use_keys_in_metadata is True
示例3: test_set_force_authn
# 需要导入模块: from saml2.config import SPConfig [as 别名]
# 或者: from saml2.config.SPConfig import getattr [as 别名]
def test_set_force_authn():
cnf = SPConfig().load(sp2)
assert bool(cnf.getattr('force_authn', 'sp')) == True
示例4: Saml
# 需要导入模块: from saml2.config import SPConfig [as 别名]
# 或者: from saml2.config.SPConfig import getattr [as 别名]
class Saml(object):
"""
SAML Wrapper around pysaml2.
Implements SAML2 Service Provider functionality for Flask.
"""
def __init__(self, config):
"""Initialize SAML Service Provider.
Args:
config (dict): Service Provider config info in dict form
"""
if config.get('metadata') is not None:
config['metadata'] = _parse_metadata_dict_to_inline(
config['metadata'])
self._config = SPConfig().load(config)
self._config.setattr('', 'allow_unknown_attributes', True)
# Set discovery end point, if configured for.
if config['service']['sp'].get('ds'):
self.discovery_service_end_point = \
config['service']['sp'].get('ds')[0]
def authenticate(self, next_url="/", binding=BINDING_HTTP_REDIRECT,
selected_idp=None):
"""Start SAML Authentication login process.
Args:
next_url (string): HTTP URL to return user to when authentication
is complete.
binding (binding): Saml2 binding method to use for request.
Defaults to BINDING_HTTP_REDIRECT (don't change til HTTP_POST
support is complete in pysaml2).
selected_idp (string): A specfic IdP that should be used to
authenticate. Defaults to `None`.
Returns:
Flask Response object to return to user containing either
HTTP_REDIRECT or HTTP_POST SAML message.
Raises:
AuthException: when unable to locate valid IdP.
BadRequest: when invalid result returned from SAML client.
"""
# Fail if signing requested but no private key configured.
if self._config.getattr('authn_requests_signed') == True:
if not self._config.key_file \
or not os.path.exists(self._config.key_file):
raise AuthException(
"Signature requested for this Saml authentication" + \
" request, but no private key file configured")
# Find configured for IdPs for requested binding method.
bindable_idps = []
all_idps = self._config.metadata.identity_providers()
# Filter IdPs to allowed IdPs, if we have some.
if self._config.getattr('idp') is not None:
all_idps = list(set(all_idps) & set(self._config.getattr('idp')))
# Filter IdPs to selected IdP, if we have one.
if selected_idp is not None:
all_idps = list(set(all_idps) & set([selected_idp]))
# From all IdPs allowed/selected, get the ones we can bind to.
for idp in all_idps:
if self._config.metadata.single_sign_on_service(idp, binding) != []:
bindable_idps.append(idp)
if not len(bindable_idps):
raise AuthException("Unable to locate valid IdP for this request")
# Retrieve cache.
outstanding_queries_cache = \
AuthDictCache(session, '_saml_outstanding_queries')
LOGGER.debug("Outstanding queries cache %s", outstanding_queries_cache)
if len(bindable_idps) > 1:
# Redirect to discovery service
(session_id, response) = self._handle_discovery_request()
else:
idp_entityid = bindable_idps[0]
LOGGER.debug("Connecting to Identity Provider %s", idp_entityid)
# Make pysaml2 call to authenticate.
client = Saml2Client(self._config)
(session_id, result) = client.prepare_for_authenticate(
entityid=idp_entityid,
relay_state=next_url,
sign=self._config.getattr('authn_requests_signed'),
binding=binding)
# The psaml2 source for this method indicates that
# BINDING_HTTP_POST should not be used right now to authenticate.
# Regardless, we'll check for it and act accordingly.
if binding == BINDING_HTTP_REDIRECT:
LOGGER.debug("Redirect to Identity Provider %s ( %s )",
idp_entityid, result)
response = make_response("", 302, dict(result['headers']))
elif binding == BINDING_HTTP_POST:
LOGGER.debug("Post to Identity Provider %s ( %s )",
idp_entityid, result)
#.........这里部分代码省略.........
示例5: test_unset_force_authn
# 需要导入模块: from saml2.config import SPConfig [as 别名]
# 或者: from saml2.config.SPConfig import getattr [as 别名]
def test_unset_force_authn():
cnf = SPConfig().load(sp1)
assert bool(cnf.getattr('force_authn', 'sp')) == False