本文整理汇总了Python中onelogin.saml2.idp_metadata_parser.OneLogin_Saml2_IdPMetadataParser.merge_settings方法的典型用法代码示例。如果您正苦于以下问题:Python OneLogin_Saml2_IdPMetadataParser.merge_settings方法的具体用法?Python OneLogin_Saml2_IdPMetadataParser.merge_settings怎么用?Python OneLogin_Saml2_IdPMetadataParser.merge_settings使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类onelogin.saml2.idp_metadata_parser.OneLogin_Saml2_IdPMetadataParser
的用法示例。
在下文中一共展示了OneLogin_Saml2_IdPMetadataParser.merge_settings方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMergeSettings
# 需要导入模块: from onelogin.saml2.idp_metadata_parser import OneLogin_Saml2_IdPMetadataParser [as 别名]
# 或者: from onelogin.saml2.idp_metadata_parser.OneLogin_Saml2_IdPMetadataParser import merge_settings [as 别名]
def testMergeSettings(self):
"""
Tests the merge_settings method of the OneLogin_Saml2_IdPMetadataParser
"""
with self.assertRaises(AttributeError):
settings_result = OneLogin_Saml2_IdPMetadataParser.merge_settings(None, {})
with self.assertRaises(TypeError):
settings_result = OneLogin_Saml2_IdPMetadataParser.merge_settings({}, None)
xml_idp_metadata = self.file_contents(join(self.data_path, 'metadata', 'idp_metadata.xml'))
data = OneLogin_Saml2_IdPMetadataParser.parse(xml_idp_metadata)
settings = self.loadSettingsJSON()
settings_result = OneLogin_Saml2_IdPMetadataParser.merge_settings(settings, data)
expected_data = {u'sp': {'NameIDFormat': 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress'}, u'idp': {'singleLogoutService': {'url': 'https://app.onelogin.com/trust/saml2/http-post/sso/383123'}, 'entityId': 'https://app.onelogin.com/saml/metadata/383123', 'x509cert': 'MIIEHjCCAwagAwIBAgIBATANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJVUzET\nMBEGA1UECAwKQ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qEIyj6Te9gx5z6wyfv+Lo8RFvBLlnB1lXqbC+fTGcV\ngG/4oKLJ5UwRFxInqpZPnOAudVNnd0PYOODn9FWs6u+OTIQIaIcPUv3MhB9lwHIJ\nsTk/bs9xcru5TPyLIxLLd6ib/pRceKH2mTkzUd0DYk9CQNXXeoGx/du5B9nh3ClP\nTbVakRzl3oswgI5MQIphYxkW70SopEh4kOFSRE1ND31NNIq1YrXlgtkguQBFsZWu\nQOPR6cEwFZzP0tHTYbI839WgxX6hfhIUTUz6mLqq4+3P4BG3+1OXeVDg63y8Uh78\n1sE='}, u'strict': False, u'contactPerson': {u'technical': {u'givenName': u'technical_name', u'emailAddress': u'[email protected]'}, u'support': {u'givenName': u'support_name', u'emailAddress': u'[email protected]'}}, u'debug': False, u'organization': {u'en-US': {u'url': u'http://sp.example.com', u'displayname': u'SP test', u'name': u'sp_test'}}, u'security': {u'signMetadata': False, u'wantAssertionsSigned': False, u'authnRequestsSigned': False}, u'custom_base_path': u'../../../tests/data/customPath/'}
self.assertEqual(expected_data, settings_result)
expected_data2 = {'sp': {u'singleLogoutService': {u'url': u'http://stuff.com/endpoints/endpoints/sls.php'}, u'assertionConsumerService': {u'url': u'http://stuff.com/endpoints/endpoints/acs.php'}, u'entityId': u'http://stuff.com/endpoints/metadata.php', u'NameIDFormat': u'urn:oasis:names:tc:SAML:2.0:nameid-format:unspecified'}, 'idp': {u'singleLogoutService': {u'url': u'http://idp.example.com/SingleLogoutService.php'}, u'entityId': u'http://idp.example.com/', u'x509cert': u'MIICgTCCAeoCCQCbOlrWDdX7FTANBgkqhkiG9w0BAQUFADCBhDELMAkGA1UEBhMCTk8xGDAWBgNVBAgTD0FuZHJlYXMgU29sYmVyZzEMMAoGA1UEBxMDRm9vMRAwDgYDVQQKEwdVTklORVRUMRgwFgYDVQQDEw9mZWlkZS5lcmxhbmcubm8xITAfBgkqhkiG9w0BCQEWEmFuZHJlYXNAdW5pbmV0dC5ubzAeFw0wNzA2MTUxMjAxMzVaFw0wNzA4MTQxMjAxMzVaMIGEMQswCQYDVQQGEwJOTzEYMBYGA1UECBMPQW5kcmVhcyBTb2xiZXJnMQwwCgYDVQQHEwNGb28xEDAOBgNVBAoTB1VOSU5FVFQxGDAWBgNVBAMTD2ZlaWRlLmVybGFuZy5ubzEhMB8GCSqGSIb3DQEJARYSYW5kcmVhc0B1bmluZXR0Lm5vMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDivbhR7P516x/S3BqKxupQe0LONoliupiBOesCO3SHbDrl3+q9IbfnfmE04rNuMcPsIxB161TdDpIesLCn7c8aPHISKOtPlAeTZSnb8QAu7aRjZq3+PbrP5uW3TcfCGPtKTytHOge/OlJbo078dVhXQ14d1EDwXJW1rRXuUt4C8QIDAQABMA0GCSqGSIb3DQEBBQUAA4GBACDVfp86HObqY+e8BUoWQ9+VMQx1ASDohBjwOsg2WykUqRXF+dLfcUH9dWR63CtZIKFDbStNomPnQz7nbK+onygwBspVEbnHuUihZq3ZUdmumQqCw4Uvs/1Uvq3orOo/WJVhTyvLgFVK2QarQ4/67OZfHd7R+POBXhophSMv1ZOo', u'singleSignOnService': {u'url': u'http://idp.example.com/SSOService.php'}}, u'strict': False, u'contactPerson': {u'technical': {u'givenName': u'technical_name', u'emailAddress': u'[email protected]'}, u'support': {u'givenName': u'support_name', u'emailAddress': u'[email protected]'}}, u'debug': False, u'organization': {u'en-US': {u'url': u'http://sp.example.com', u'displayname': u'SP test', u'name': u'sp_test'}}, u'security': {u'signMetadata': False, u'wantAssertionsSigned': False, u'authnRequestsSigned': False}, u'custom_base_path': u'../../../tests/data/customPath/'}
settings_result2 = OneLogin_Saml2_IdPMetadataParser.merge_settings(data, settings)
self.assertEqual(expected_data2, settings_result2)
示例2: _get_saml_settings
# 需要导入模块: from onelogin.saml2.idp_metadata_parser import OneLogin_Saml2_IdPMetadataParser [as 别名]
# 或者: from onelogin.saml2.idp_metadata_parser.OneLogin_Saml2_IdPMetadataParser import merge_settings [as 别名]
def _get_saml_settings():
# load settings from environment
settings = current_app.config.get('SAML_SETTINGS')
# if settings doesn't exist and a file is provided, load the file
settings_file = current_app.config.get('SAML_SETTINGS_FILE')
if not settings and settings_file:
with open(settings_file, 'r') as json_data_file:
settings = json.load(json_data_file)
# if saml metadata url is provided, load idp settings via metadata
idp_metadata_url = current_app.config.get('SAML_METADATA_URL')
idp_metadata_entity_id = current_app.config.get('SAML_METADATA_ENTITY_ID', None)
if idp_metadata_url:
idp_settings = OneLogin_Saml2_IdPMetadataParser.parse_remote(
idp_metadata_url,
entity_id=idp_metadata_entity_id
)
settings = OneLogin_Saml2_IdPMetadataParser.merge_settings(settings, idp_settings)
return settings
示例3: handle_sso_command
# 需要导入模块: from onelogin.saml2.idp_metadata_parser import OneLogin_Saml2_IdPMetadataParser [as 别名]
# 或者: from onelogin.saml2.idp_metadata_parser.OneLogin_Saml2_IdPMetadataParser import merge_settings [as 别名]
#.........这里部分代码省略.........
return 0, 'SSO is "disabled".', ''
if cmd['prefix'] == 'dashboard sso show saml2':
return 0, json.dumps(SSO_DB.saml2.to_dict()), ''
if cmd['prefix'] == 'dashboard sso setup saml2':
ceph_dashboard_base_url = cmd['ceph_dashboard_base_url']
idp_metadata = cmd['idp_metadata']
idp_username_attribute = _get_optional_attr(cmd, 'idp_username_attribute', 'uid')
idp_entity_id = _get_optional_attr(cmd, 'idp_entity_id', None)
sp_x_509_cert = _get_optional_attr(cmd, 'sp_x_509_cert', '')
sp_private_key = _get_optional_attr(cmd, 'sp_private_key', '')
if sp_x_509_cert and not sp_private_key:
return -errno.EINVAL, '', 'Missing parameter `sp_private_key`.'
if not sp_x_509_cert and sp_private_key:
return -errno.EINVAL, '', 'Missing parameter `sp_x_509_cert`.'
has_sp_cert = sp_x_509_cert != "" and sp_private_key != ""
try:
# pylint: disable=undefined-variable
FileNotFoundError
except NameError:
# pylint: disable=redefined-builtin
FileNotFoundError = IOError
try:
f = open(sp_x_509_cert, 'r')
sp_x_509_cert = f.read()
f.close()
except FileNotFoundError:
pass
try:
f = open(sp_private_key, 'r')
sp_private_key = f.read()
f.close()
except FileNotFoundError:
pass
try:
idp_settings = OneLogin_Saml2_IdPMetadataParser.parse_remote(idp_metadata,
validate_cert=False,
entity_id=idp_entity_id)
# pylint: disable=broad-except
except Exception:
try:
f = open(idp_metadata, 'r')
idp_metadata = f.read()
f.close()
except FileNotFoundError:
pass
try:
idp_settings = OneLogin_Saml2_IdPMetadataParser.parse(idp_metadata,
entity_id=idp_entity_id)
# pylint: disable=broad-except
except Exception:
return -errno.EINVAL, '', 'Invalid parameter `idp_metadata`.'
url_prefix = prepare_url_prefix(mgr.get_config('url_prefix', default=''))
settings = {
'sp': {
'entityId': '{}{}/auth/saml2/metadata'.format(ceph_dashboard_base_url, url_prefix),
'assertionConsumerService': {
'url': '{}{}/auth/saml2'.format(ceph_dashboard_base_url, url_prefix),
'binding': "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST"
},
'attributeConsumingService': {
'serviceName': "Ceph Dashboard",
"serviceDescription": "Ceph Dashboard Service",
"requestedAttributes": [
{
"name": idp_username_attribute,
"isRequired": True
}
]
},
'singleLogoutService': {
'url': '{}{}/auth/saml2/logout'.format(ceph_dashboard_base_url, url_prefix),
'binding': 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect'
},
"x509cert": sp_x_509_cert,
"privateKey": sp_private_key
},
'security': {
"nameIdEncrypted": has_sp_cert,
"authnRequestsSigned": has_sp_cert,
"logoutRequestSigned": has_sp_cert,
"logoutResponseSigned": has_sp_cert,
"signMetadata": has_sp_cert,
"wantMessagesSigned": has_sp_cert,
"wantAssertionsSigned": has_sp_cert,
"wantAssertionsEncrypted": has_sp_cert,
"wantNameIdEncrypted": has_sp_cert,
"metadataValidUntil": '',
"wantAttributeStatement": False
}
}
settings = OneLogin_Saml2_IdPMetadataParser.merge_settings(settings, idp_settings)
SSO_DB.saml2.onelogin_settings = settings
SSO_DB.protocol = 'saml2'
SSO_DB.save()
return 0, json.dumps(SSO_DB.saml2.onelogin_settings), ''
return -errno.ENOSYS, '', ''
示例4: test_merge_settings
# 需要导入模块: from onelogin.saml2.idp_metadata_parser import OneLogin_Saml2_IdPMetadataParser [as 别名]
# 或者: from onelogin.saml2.idp_metadata_parser.OneLogin_Saml2_IdPMetadataParser import merge_settings [as 别名]
def test_merge_settings(self):
"""
Tests the merge_settings method of the OneLogin_Saml2_IdPMetadataParser
"""
with self.assertRaises(TypeError):
settings_result = OneLogin_Saml2_IdPMetadataParser.merge_settings(None, {})
with self.assertRaises(TypeError):
settings_result = OneLogin_Saml2_IdPMetadataParser.merge_settings({}, None)
xml_idp_metadata = self.file_contents(join(self.data_path, 'metadata', 'idp_metadata.xml'))
# Parse XML metadata.
data = OneLogin_Saml2_IdPMetadataParser.parse(xml_idp_metadata)
# Read base settings.
settings = self.loadSettingsJSON()
# Merge settings from XML metadata into base settings,
# let XML metadata have priority if there are conflicting
# attributes.
settings_result = OneLogin_Saml2_IdPMetadataParser.merge_settings(settings, data)
# Generate readable JSON representation:
# print("%s" % json.dumps(settings_result, indent=2).replace(r'\n', r'\\n'))
expected_settings_json = """
{
"custom_base_path": "../../../tests/data/customPath/",
"contactPerson": {
"support": {
"emailAddress": "[email protected]",
"givenName": "support_name"
},
"technical": {
"emailAddress": "[email protected]",
"givenName": "technical_name"
}
},
"idp": {
"singleSignOnService": {
"url": "https://app.onelogin.com/trust/saml2/http-post/sso/383123",
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
},
"entityId": "https://app.onelogin.com/saml/metadata/383123",
"singleLogoutService": {
"url": "http://idp.example.com/SingleLogoutService.php"
},
"x509cert": "MIIEHjCCAwagAwIBAgIBATANBgkqhkiG9w0BAQUFADBnMQswCQYDVQQGEwJVUzETMBEGA1UECAwKQ2FsaWZvcm5pYTEVMBMGA1UEBwwMU2FudGEgTW9uaWNhMREwDwYDVQQKDAhPbmVMb2dpbjEZMBcGA1UEAwwQYXBwLm9uZWxvZ2luLmNvbTAeFw0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DYk9CQNXXeoGx/du5B9nh3ClPTbVakRzl3oswgI5MQIphYxkW70SopEh4kOFSRE1ND31NNIq1YrXlgtkguQBFsZWuQOPR6cEwFZzP0tHTYbI839WgxX6hfhIUTUz6mLqq4+3P4BG3+1OXeVDg63y8Uh781sE="
},
"sp": {
"NameIDFormat": "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
"entityId": "http://stuff.com/endpoints/metadata.php",
"assertionConsumerService": {
"url": "http://stuff.com/endpoints/endpoints/acs.php"
},
"singleLogoutService": {
"url": "http://stuff.com/endpoints/endpoints/sls.php"
}
},
"security": {
"wantAssertionsSigned": false,
"authnRequestsSigned": false,
"signMetadata": false
},
"debug": false,
"organization": {
"en-US": {
"displayname": "SP test",
"url": "http://sp.example.com",
"name": "sp_test"
}
},
"strict": false
}
"""
expected_settings = json.loads(expected_settings_json)
self.assertEqual(expected_settings, settings_result)
# Commute merge operation. As the order determines which settings
# dictionary has priority, here we expect a different result.
settings_result2 = OneLogin_Saml2_IdPMetadataParser.merge_settings(data, settings)
expected_settings2_json = """
{
"debug": false,
"idp": {
"singleLogoutService": {
"url": "http://idp.example.com/SingleLogoutService.php"
},
"singleSignOnService": {
"url": "http://idp.example.com/SSOService.php",
"binding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect"
},
"entityId": "http://idp.example.com/",
"x509cert": "MIICgTCCAeoCCQCbOlrWDdX7FTANBgkqhkiG9w0BAQUFADCBhDELMAkGA1UEBhMCTk8xGDAWBgNVBAgTD0FuZHJlYXMgU29sYmVyZzEMMAoGA1UEBxMDRm9vMRAwDgYDVQQKEwdVTklORVRUMRgwFgYDVQQDEw9mZWlkZS5lcmxhbmcubm8xITAfBgkqhkiG9w0BCQEWEmFuZHJlYXNAdW5pbmV0dC5ubzAeFw0wNzA2MTUxMjAxMzVaFw0wNzA4MTQxMjAxMzVaMIGEMQswCQYDVQQGEwJOTzEYMBYGA1UECBMPQW5kcmVhcyBTb2xiZXJnMQwwCgYDVQQHEwNGb28xEDAOBgNVBAoTB1VOSU5FVFQxGDAWBgNVBAMTD2ZlaWRlLmVybGFuZy5ubzEhMB8GCSqGSIb3DQEJARYSYW5kcmVhc0B1bmluZXR0Lm5vMIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDivbhR7P516x/S3BqKxupQe0LONoliupiBOesCO3SHbDrl3+q9IbfnfmE04rNuMcPsIxB161TdDpIesLCn7c8aPHISKOtPlAeTZSnb8QAu7aRjZq3+PbrP5uW3TcfCGPtKTytHOge/OlJbo078dVhXQ14d1EDwXJW1rRXuUt4C8QIDAQABMA0GCSqGSIb3DQEBBQUAA4GBACDVfp86HObqY+e8BUoWQ9+VMQx1ASDohBjwOsg2WykUqRXF+dLfcUH9dWR63CtZIKFDbStNomPnQz7nbK+onygwBspVEbnHuUihZq3ZUdmumQqCw4Uvs/1Uvq3orOo/WJVhTyvLgFVK2QarQ4/67OZfHd7R+POBXhophSMv1ZOo"
},
"security": {
"authnRequestsSigned": false,
"wantAssertionsSigned": false,
"signMetadata": false
#.........这里部分代码省略.........