本文整理汇总了Python中saml2.BINDING_HTTP_REDIRECT属性的典型用法代码示例。如果您正苦于以下问题:Python saml2.BINDING_HTTP_REDIRECT属性的具体用法?Python saml2.BINDING_HTTP_REDIRECT怎么用?Python saml2.BINDING_HTTP_REDIRECT使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类saml2
的用法示例。
在下文中一共展示了saml2.BINDING_HTTP_REDIRECT属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_signed_redirect
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def test_signed_redirect(self):
msg_str = "%s" % self.client.create_authn_request(
"http://localhost:8088/sso", message_id="id1")[1]
info = self.client.apply_binding(
BINDING_HTTP_REDIRECT, msg_str, destination="",
relay_state="relay2", sigalg=SIG_RSA_SHA256)
loc = info["headers"][0][1]
qs = parse_qs(loc[1:])
assert _leq(qs.keys(),
['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'])
assert verify_redirect_signature(list_values2simpletons(qs),
self.client.sec.sec_backend)
res = self.server.parse_authn_request(qs["SAMLRequest"][0],
BINDING_HTTP_REDIRECT)
print(res)
示例2: test_do_negotiated_authn
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def test_do_negotiated_authn(self):
binding = BINDING_HTTP_REDIRECT
response_binding = BINDING_HTTP_POST
sid, auth_binding, http_args = \
self.client.prepare_for_negotiated_authenticate(
IDP, "http://www.example.com/relay_state",
binding=binding, response_binding=response_binding)
assert binding == auth_binding
assert isinstance(sid, six.string_types)
assert len(http_args) == 4
assert http_args["headers"][0][0] == "Location"
assert http_args["data"] == []
redirect_url = http_args["headers"][0][1]
_, _, _, _, qs, _ = urlparse(redirect_url)
qs_dict = parse_qs(qs)
req = self.server.parse_authn_request(qs_dict["SAMLRequest"][0],
binding)
resp_args = self.server.response_args(req.message, [response_binding])
assert resp_args["binding"] == response_binding
示例3: test_parse_faulty_request_to_err_status
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def test_parse_faulty_request_to_err_status(self):
req_id, authn_request = self.client.create_authn_request(
destination="http://www.example.com")
binding = BINDING_HTTP_REDIRECT
htargs = self.client.apply_binding(binding, "%s" % authn_request,
"http://www.example.com", "abcd")
_dict = parse_qs(htargs["headers"][0][1].split('?')[1])
print(_dict)
try:
self.server.parse_authn_request(_dict["SAMLRequest"][0], binding)
status = None
except OtherError as oe:
print(oe.args)
status = s_utils.error_status_factory(oe)
assert status
print(status)
assert _eq(status.keyswv(), ["status_code", "status_message"])
assert status.status_message.text == 'Not destined for me!'
status_code = status.status_code
assert _eq(status_code.keyswv(), ["status_code", "value"])
assert status_code.value == samlp.STATUS_RESPONDER
assert status_code.status_code.value == samlp.STATUS_UNKNOWN_PRINCIPAL
示例4: test_1
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def test_1(self):
with closing(Server("idp_slo_redirect_conf")) as server:
req_id, request = _logout_request("sp_slo_redirect_conf")
print(request)
bindings = [BINDING_HTTP_REDIRECT]
response = server.create_logout_response(request, bindings)
binding, destination = server.pick_binding("single_logout_service",
bindings, "spsso",
request)
http_args = server.apply_binding(binding, "%s" % response, destination,
"relay_state", response=True)
assert len(http_args) == 4
assert http_args["headers"][0][0] == "Location"
assert http_args["data"] == []
示例5: _sso_location
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def _sso_location(self, entityid=None, binding=BINDING_HTTP_REDIRECT):
if entityid:
# verify that it's in the metadata
srvs = self.metadata.single_sign_on_service(entityid, binding)
if srvs:
return destinations(srvs)[0]
else:
logger.info("_sso_location: %s, %s", entityid, binding)
raise IdpUnspecified("No IdP to send to given the premises")
# get the idp location from the metadata. If there is more than one
# IdP in the configuration raise exception
eids = self.metadata.with_descriptor("idpsso")
if len(eids) > 1:
raise IdpUnspecified("Too many IdPs to choose from: %s" % eids)
try:
srvs = self.metadata.single_sign_on_service(list(eids.keys())[0],
binding)
return destinations(srvs)[0]
except IndexError:
raise IdpUnspecified("No IdP to send to given the premises")
示例6: response
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def response(self, binding, http_args, do_not_start_response=False):
if binding == BINDING_HTTP_ARTIFACT:
resp = Redirect()
elif binding == BINDING_HTTP_REDIRECT:
for param, value in http_args["headers"]:
if param == "Location":
resp = SeeOther(str(value))
break
else:
resp = ServiceError("Parameter error")
else:
resp = Response(http_args["data"], headers=http_args["headers"])
if do_not_start_response:
return resp
else:
return resp(self.environ, self.start_response)
示例7: saml2_handler
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def saml2_handler(session, request, config_filename = None):
config_filename = config_filename or os.path.join(request.folder,'private','sp_conf')
client = Saml2Client(config_file = config_filename)
idps = client.metadata.with_descriptor("idpsso")
entityid = idps.keys()[0]
bindings = [BINDING_HTTP_REDIRECT, BINDING_HTTP_POST]
binding, destination = client.pick_binding(
"single_sign_on_service", bindings, "idpsso", entity_id=entityid)
if request.env.request_method == 'GET':
binding = BINDING_HTTP_REDIRECT
elif request.env.request_method == 'POST':
binding = BINDING_HTTP_POST
if not request.vars.SAMLResponse:
req_id, req = client.create_authn_request(destination, binding=binding)
relay_state = web2py_uuid().replace('-','')
session.saml_outstanding_queries = {req_id: request.url}
session.saml_req_id = req_id
http_args = client.apply_binding(binding, str(req), destination,
relay_state=relay_state)
return {'url':dict(http_args["headers"])['Location']}
else:
relay_state = request.vars.RelayState
req_id = session.saml_req_id
unquoted_response = request.vars.SAMLResponse
res = {}
try:
data = client.parse_authn_request_response(
unquoted_response, binding, session.saml_outstanding_queries)
res['response'] = data if data else {}
except Exception as e:
import traceback
res['error'] = traceback.format_exc()
return res
示例8: saml2_handler
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def saml2_handler(session, request, config_filename = None):
config_filename = config_filename or os.path.join(request.folder,'private','sp_conf')
client = Saml2Client(config_file = config_filename)
idps = client.metadata.with_descriptor("idpsso")
entityid = idps.keys()[0]
bindings = [BINDING_HTTP_REDIRECT, BINDING_HTTP_POST]
binding, destination = client.pick_binding(
"single_sign_on_service", bindings, "idpsso", entity_id=entityid)
if request.env.request_method == 'GET':
binding = BINDING_HTTP_REDIRECT
elif request.env.request_method == 'POST':
binding = BINDING_HTTP_POST
if not request.vars.SAMLResponse:
req_id, req = client.create_authn_request(destination, binding=binding)
relay_state = web2py_uuid().replace('-','')
session.saml_outstanding_queries = {req_id: request.url}
session.saml_req_id = req_id
http_args = client.apply_binding(binding, str(req), destination,
relay_state=relay_state)
return {'url':dict(http_args["headers"])['Location']}
else:
relay_state = request.vars.RelayState
req_id = session.saml_req_id
unquoted_response = request.vars.SAMLResponse
res = {}
try:
data = client.parse_authn_request_response(
unquoted_response, binding, session.saml_outstanding_queries)
res['response'] = data if data else {}
except Exception, e:
import traceback
res['error'] = traceback.format_exc()
return res
示例9: saml2_handler
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def saml2_handler(session, request, config_filename = None):
config_filename = config_filename or os.path.join(request.folder,'private','sp_conf')
client = Saml2Client(config_file = config_filename)
idps = client.metadata.with_descriptor("idpsso")
entityid = idps.keys()[0]
bindings = [BINDING_HTTP_REDIRECT]
binding, destination = client.pick_binding(
"single_sign_on_service", bindings, "idpsso", entity_id=entityid)
binding = BINDING_HTTP_REDIRECT
if not request.vars.SAMLResponse:
req_id, req = client.create_authn_request(destination, binding=binding)
relay_state = web2py_uuid().replace('-','')
session.saml_outstanding_queries = {req_id: request.url}
session.saml_req_id = req_id
http_args = client.apply_binding(binding, str(req), destination,
relay_state=relay_state)
return {'url':dict(http_args["headers"])['Location']}
else:
relay_state = request.vars.RelayState
req_id = session.saml_req_id
unquoted_response = request.vars.SAMLResponse
res = {}
try:
data = client.parse_authn_request_response(
unquoted_response, binding, session.saml_outstanding_queries)
res['response'] = data if data else {}
except Exception, e:
import traceback
res['error'] = traceback.format_exc()
return res
示例10: logout_service
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def logout_service(request, *args, **kwargs):
return do_logout_service(request, request.GET, BINDING_HTTP_REDIRECT, *args, **kwargs)
示例11: test_ext_2
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def test_ext_2():
mds = MetadataStore(ATTRCONV, sec_config,
disable_ssl_certificate_validation=True)
mds.imp(METADATACONF["3"])
# No specific binding defined
ents = mds.with_descriptor("spsso")
for binding in [BINDING_SOAP, BINDING_HTTP_POST, BINDING_HTTP_ARTIFACT,
BINDING_HTTP_REDIRECT]:
assert mds.single_logout_service(list(ents.keys())[0], binding, "spsso")
示例12: test_mdx_service
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def test_mdx_service():
entity_id = "http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
url = "http://mdx.example.com/entities/{}".format(
quote_plus(MetaDataMDX.sha1_entity_transform(entity_id)))
responses.add(responses.GET, url, body=TEST_METADATA_STRING, status=200,
content_type=SAML_METADATA_CONTENT_TYPE)
mdx = MetaDataMDX("http://mdx.example.com")
sso_loc = mdx.service(entity_id, "idpsso_descriptor", "single_sign_on_service")
assert sso_loc[BINDING_HTTP_REDIRECT][0]["location"] == "http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
certs = mdx.certs(entity_id, "idpsso")
assert len(certs) == 1
示例13: test_mdx_single_sign_on_service
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def test_mdx_single_sign_on_service():
entity_id = "http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
url = "http://mdx.example.com/entities/{}".format(
quote_plus(MetaDataMDX.sha1_entity_transform(entity_id)))
responses.add(responses.GET, url, body=TEST_METADATA_STRING, status=200,
content_type=SAML_METADATA_CONTENT_TYPE)
mdx = MetaDataMDX("http://mdx.example.com")
sso_loc = mdx.single_sign_on_service(entity_id, BINDING_HTTP_REDIRECT)
assert sso_loc[0]["location"] == "http://xenosmilus.umdc.umu.se/simplesaml/saml2/idp/metadata.php"
# pyff-test not available
# def test_mdx_service():
# sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
# http = HTTPBase(verify=False, ca_bundle=None)
#
# mdx = MetaDataMDX(quote_plus, ATTRCONV,
# "http://pyff-test.nordu.net",
# sec_config, None, http)
# foo = mdx.service("https://idp.umu.se/saml2/idp/metadata.php",
# "idpsso_descriptor", "single_sign_on_service")
#
# assert len(foo) == 1
# assert foo.keys()[0] == BINDING_HTTP_REDIRECT
#
#
# def test_mdx_certs():
# sec_config.xmlsec_binary = sigver.get_xmlsec_binary(["/opt/local/bin"])
# http = HTTPBase(verify=False, ca_bundle=None)
#
# mdx = MetaDataMDX(quote_plus, ATTRCONV,
# "http://pyff-test.nordu.net",
# sec_config, None, http)
# foo = mdx.certs("https://idp.umu.se/saml2/idp/metadata.php", "idpsso")
#
# assert len(foo) == 1
示例14: test_do_logout_signed_redirect
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def test_do_logout_signed_redirect(self):
conf = config.SPConfig()
conf.load_file("sp_slo_redirect_conf")
client = Saml2Client(conf)
# information about the user from an IdP
session_info = {
"name_id": nid,
"issuer": "urn:mace:example.com:saml:roland:idp",
"not_on_or_after": in_a_while(minutes=15),
"ava": {
"givenName": "Anders",
"sn": "Andersson",
"mail": "[email protected]"
}
}
client.users.add_information_about_person(session_info)
entity_ids = client.users.issuers_of_info(nid)
assert entity_ids == ["urn:mace:example.com:saml:roland:idp"]
resp = client.do_logout(nid, entity_ids, "Tired", in_a_while(minutes=5),
sign=True,
expected_binding=BINDING_HTTP_REDIRECT)
assert list(resp.keys()) == entity_ids
binding, info = resp[entity_ids[0]]
assert binding == BINDING_HTTP_REDIRECT
loc = info["headers"][0][1]
_, _, _, _, qs, _ = urlparse(loc)
qs = parse_qs(qs)
assert _leq(qs.keys(),
['SigAlg', 'SAMLRequest', 'RelayState', 'Signature'])
assert verify_redirect_signature(list_values2simpletons(qs),
client.sec.sec_backend)
res = self.server.parse_logout_request(qs["SAMLRequest"][0],
BINDING_HTTP_REDIRECT)
print(res)
示例15: authn_request_endpoint
# 需要导入模块: import saml2 [as 别名]
# 或者: from saml2 import BINDING_HTTP_REDIRECT [as 别名]
def authn_request_endpoint(self, req, binding, relay_state):
req = self.parse_authn_request(req, binding)
if req.message.protocol_binding == BINDING_HTTP_REDIRECT:
_binding = BINDING_HTTP_POST
else:
_binding = req.message.protocol_binding
try:
resp_args = self.response_args(req.message, [_binding])
except Exception:
raise
identity = {"surName": "Hedberg", "givenName": "Roland",
"title": "supertramp", "mail": "[email protected]"}
userid = "Pavill"
authn_resp = self.create_authn_response(identity,
userid=userid,
authn=AUTHN,
**resp_args)
response = "%s" % authn_resp
_dict = pack.factory(_binding, response,
resp_args["destination"], relay_state,
"SAMLResponse")
return DummyResponse(200, **_dict)