本文整理匯總了Python中saml2.authn_context.AuthnBroker.get_authn_by_accr方法的典型用法代碼示例。如果您正苦於以下問題:Python AuthnBroker.get_authn_by_accr方法的具體用法?Python AuthnBroker.get_authn_by_accr怎麽用?Python AuthnBroker.get_authn_by_accr使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類saml2.authn_context.AuthnBroker
的用法示例。
在下文中一共展示了AuthnBroker.get_authn_by_accr方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: handle_authn_request
# 需要導入模塊: from saml2.authn_context import AuthnBroker [as 別名]
# 或者: from saml2.authn_context.AuthnBroker import get_authn_by_accr [as 別名]
def handle_authn_request(self, saml_request, relay_state, binding, userid):
self.authn_req = self.idp.parse_authn_request(saml_request, binding)
_encrypt_cert = encrypt_cert_from_item(self.authn_req.message)
self.binding_out, self.destination = self.idp.pick_binding(
"assertion_consumer_service",
bindings=None,
entity_id=self.authn_req.message.issuer.text,
request=self.authn_req.message)
resp_args = self.idp.response_args(self.authn_req.message)
AUTHN_BROKER = AuthnBroker()
AUTHN_BROKER.add(authn_context_class_ref(PASSWORD),
username_password_authn_dummy,
10,
"http://test.idp.se")
AUTHN_BROKER.get_authn_by_accr(PASSWORD)
resp_args["authn"] = AUTHN_BROKER.get_authn_by_accr(PASSWORD)
_resp = self.idp.create_authn_response(TestIdP.USERS[userid],
userid=userid,
encrypt_cert=_encrypt_cert,
encrypt_assertion_self_contained=True,
encrypted_advice_attributes=True,
**resp_args)
kwargs = {}
http_args = self.idp.apply_binding(BINDING_HTTP_POST,
"%s" % _resp,
self.destination,
relay_state,
response=True,
**kwargs)
action, body = get_post_action_body(http_args["data"][3])
return action, urllib.urlencode(body)
示例2: outgoing
# 需要導入模塊: from saml2.authn_context import AuthnBroker [as 別名]
# 或者: from saml2.authn_context.AuthnBroker import get_authn_by_accr [as 別名]
def outgoing(self, response, org_response, instance):
"""
An authentication response has been received and now an authentication
response from this server should be constructed.
:param response: The Authentication response
:param instance: SP instance that received the authentication response
:return: response
"""
_idp = self.create_SamlIDP(instance.environ, instance.start_response, self.outgoing)
_state = instance.sp.state[response.in_response_to]
orig_authn_req, relay_state, req_args = instance.sp.state[_state]
# The Subject NameID
try:
subject = response.get_subject()
except:
pass
resp_args = _idp.idp.response_args(orig_authn_req)
try:
_authn_info = response.authn_info()[0]
AUTHN_BROKER = AuthnBroker()
AUTHN_BROKER.add(authn_context_class_ref(_authn_info[0]), username_password_authn_dummy, 0, self.issuer)
_authn = AUTHN_BROKER.get_authn_by_accr(_authn_info[0])
#_authn = {"class_ref": _authn_info[0], "authn_auth": self.issuer}
except:
AUTHN_BROKER = AuthnBroker()
AUTHN_BROKER.add(authn_context_class_ref(UNSPECIFIED), username_password_authn_dummy, 0, self.issuer)
_authn = AUTHN_BROKER.get_authn_by_accr(UNSPECIFIED)
identity = response.ava
if identity is None and response.response.encrypted_assertion is not None:
#Add dummy value
identity = {"uid": "dummyuser"}
# Will signed the response by default
resp = _idp.construct_authn_response(identity, userid="dummyuser",
authn=_authn, name_id=None, resp_args=resp_args,
relay_state=relay_state, sign_response=True,
org_resp=response, org_xml_response=org_response)
return resp
示例3: handle_auth_req
# 需要導入模塊: from saml2.authn_context import AuthnBroker [as 別名]
# 或者: from saml2.authn_context.AuthnBroker import get_authn_by_accr [as 別名]
def handle_auth_req(self, saml_request, relay_state, binding, userid,
response_binding=BINDING_HTTP_POST):
"""
Handles a SAML request, validates and creates a SAML response.
:type saml_request: str
:type relay_state: str
:type binding: str
:type userid: str
:rtype:
:param saml_request:
:param relay_state: RelayState is a parameter used by some SAML protocol implementations to
identify the specific resource at the resource provider in an IDP initiated single sign on
scenario.
:param binding:
:param userid: The user identification.
:return: A tuple with
"""
auth_req = self.parse_authn_request(saml_request, binding)
binding_out, destination = self.pick_binding(
'assertion_consumer_service',
bindings=[response_binding],
entity_id=auth_req.message.issuer.text, request=auth_req.message)
resp_args = self.response_args(auth_req.message)
authn_broker = AuthnBroker()
authn_broker.add(authn_context_class_ref(PASSWORD), lambda: None, 10,
'unittest_idp.xml')
authn_broker.get_authn_by_accr(PASSWORD)
resp_args['authn'] = authn_broker.get_authn_by_accr(PASSWORD)
_resp = self.create_authn_response(self.user_db[userid],
userid=userid,
**resp_args)
if response_binding == BINDING_HTTP_POST:
saml_response = base64.b64encode(str(_resp).encode("utf-8"))
resp = {"SAMLResponse": saml_response, "RelayState": relay_state}
elif response_binding == BINDING_HTTP_REDIRECT:
http_args = self.apply_binding(response_binding, '%s' % _resp,
destination, relay_state, response=True)
resp = dict(parse_qsl(urlparse(dict(http_args["headers"])["Location"]).query))
return destination, resp
示例4: __create_authn_response
# 需要導入模塊: from saml2.authn_context import AuthnBroker [as 別名]
# 或者: from saml2.authn_context.AuthnBroker import get_authn_by_accr [as 別名]
def __create_authn_response(self, saml_request, relay_state, binding,
userid, response_binding=BINDING_HTTP_POST):
"""
Handles a SAML request, validates and creates a SAML response but
does not apply the binding to encode it.
:type saml_request: str
:type relay_state: str
:type binding: str
:type userid: str
:rtype: tuple [string, saml2.samlp.Response]
:param saml_request:
:param relay_state: RelayState is a parameter used by some SAML
protocol implementations to identify the specific resource at the
resource provider in an IDP initiated single sign on scenario.
:param binding:
:param userid: The user identification.
:return: A tuple containing the destination and instance of
saml2.samlp.Response
"""
auth_req = self.parse_authn_request(saml_request, binding)
binding_out, destination = self.pick_binding(
'assertion_consumer_service',
bindings=[response_binding],
entity_id=auth_req.message.issuer.text, request=auth_req.message)
resp_args = self.response_args(auth_req.message)
authn_broker = AuthnBroker()
authn_broker.add(authn_context_class_ref(PASSWORD), lambda: None, 10,
'unittest_idp.xml')
authn_broker.get_authn_by_accr(PASSWORD)
resp_args['authn'] = authn_broker.get_authn_by_accr(PASSWORD)
resp = self.create_authn_response(self.user_db[userid],
userid=userid,
**resp_args)
return destination, resp
示例5: handle_auth_req
# 需要導入模塊: from saml2.authn_context import AuthnBroker [as 別名]
# 或者: from saml2.authn_context.AuthnBroker import get_authn_by_accr [as 別名]
def handle_auth_req(self, saml_request, relay_state, binding, userid):
auth_req = self.parse_authn_request(saml_request, binding)
binding_out, destination = self.pick_binding(
'assertion_consumer_service',
entity_id=auth_req.message.issuer.text, request=auth_req.message)
resp_args = self.response_args(auth_req.message)
authn_broker = AuthnBroker()
authn_broker.add(authn_context_class_ref(PASSWORD), lambda: None, 10,
'unittest_idp.xml')
authn_broker.get_authn_by_accr(PASSWORD)
resp_args['authn'] = authn_broker.get_authn_by_accr(PASSWORD)
_resp = self.create_authn_response(self.user_db[userid],
userid=userid,
**resp_args)
http_args = self.apply_binding(BINDING_HTTP_POST, '%s' % _resp,
destination, relay_state, response=True)
url = http_args['url']
saml_response = base64.b64encode(str(_resp).encode("utf-8"))
resp = {'SAMLResponse': saml_response, 'RelayState': relay_state}
return url, resp