本文整理匯總了Python中linotp.lib.challenges.Challenges.delete_challenges方法的典型用法代碼示例。如果您正苦於以下問題:Python Challenges.delete_challenges方法的具體用法?Python Challenges.delete_challenges怎麽用?Python Challenges.delete_challenges使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類linotp.lib.challenges.Challenges
的用法示例。
在下文中一共展示了Challenges.delete_challenges方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: checkTokenList
# 需要導入模塊: from linotp.lib.challenges import Challenges [as 別名]
# 或者: from linotp.lib.challenges.Challenges import delete_challenges [as 別名]
#.........這裏部分代碼省略.........
log.debug('Found user with loginId %r: %r:\n',
token.getUserId(), token.getSerial())
audit_entry['serial'] = token.getSerial()
audit_entry['token_type'] = token.getType()
# preselect: the token must be in the same realm as the user
if user is not None:
t_realms = token.token.getRealmNames()
u_realm = user.getRealm()
if (len(t_realms) > 0 and len(u_realm) > 0 and
u_realm.lower() not in t_realms):
audit_entry['action_detail'] = ("Realm mismatch for "
"token and user")
continue
# check if the token is the list of supported tokens
# if not skip to the next token in list
typ = token.getType()
if typ.lower() not in tokenclasses:
log.error('token typ %r not found in tokenclasses: %r' %
(typ, tokenclasses))
audit_entry['action_detail'] = "Unknown Token type"
continue
if not token.isActive():
audit_entry['action_detail'] = "Token inactive"
continue
if token.getFailCount() >= token.getMaxFailCount():
audit_entry['action_detail'] = "Failcounter exceeded"
continue
if not token.check_auth_counter():
audit_entry['action_detail'] = "Authentication counter exceeded"
continue
if not token.check_validity_period():
audit_entry['action_detail'] = "validity period mismatch"
continue
# start the token validation
try:
# are there outstanding challenges
(_ex_challenges,
challenges) = Challenges.get_challenges(token,
options=check_options)
(ret, reply) = token.check_token(
passw, user, options=check_options, challenges=challenges)
except Exception as exx:
# in case of a failure during checking token, we log the error
# and continue with the next one
log.exception("checking token %r failed: %r" % (token, exx))
ret = -1
reply = "%r" % exx
audit_entry['action_detail'] = ("checking token %r "
"failed: %r" % (token, exx))
continue
finally:
validation_results[token.getSerial()] = (ret, reply)
(cToken, pToken, iToken, vToken) = token.get_verification_result()
related_challenges.extend(token.related_challenges)
challenge_tokens.extend(cToken)
pin_matching_tokens.extend(pToken)
invalid_tokens.extend(iToken)
valid_tokens.extend(vToken)
# end of token verification loop
# if there are related / sub challenges, we have to call their janitor
Challenges.handle_related_challenge(related_challenges)
# now we finalize the token validation result
fh = FinishTokens(valid_tokens,
challenge_tokens,
pin_matching_tokens,
invalid_tokens,
validation_results,
user, options,
audit_entry=audit_entry)
(res, reply) = fh.finish_checked_tokens()
# add to all tokens the last accessd time stamp
linotp.lib.token.add_last_accessed_info(
[valid_tokens, pin_matching_tokens, challenge_tokens, valid_tokens])
# now we care for all involved tokens and their challenges
for token in (valid_tokens + pin_matching_tokens +
challenge_tokens + valid_tokens):
expired, _valid = Challenges.get_challenges(token)
if expired:
Challenges.delete_challenges(None, expired)
log.debug("Number of valid tokens found "
"(validTokenNum): %d" % len(valid_tokens))
return (res, reply)
示例2: check_status
# 需要導入模塊: from linotp.lib.challenges import Challenges [as 別名]
# 或者: from linotp.lib.challenges.Challenges import delete_challenges [as 別名]
def check_status(self, transid=None, user=None, serial=None,
password=None):
"""
check for open transactions - for polling support
:param transid: the transaction id where we request the status from
:param user: the token owner user
:param serial: or the serial we are searching for
:param password: the pin/password for authorization the request
:return: tuple of success and detail dict
"""
expired, challenges = Challenges.get_challenges(None, transid=transid)
# remove all expired challenges
if expired:
Challenges.delete_challenges(None, expired)
if not challenges:
return False, None
# there is only one challenge per transaction id
# if not multiple challenges, where transaction id is the parent one
reply = {}
pin_policies = linotp.lib.policy.get_pin_policies(user)
if 1 in pin_policies:
pin_match = check_pin(None, password, user=user, options=None)
if not pin_match:
return False, None
involved_tokens = []
transactions = {}
for ch in challenges:
# only look for challenges that are not compromised
if not Challenges.verify_checksum(ch):
continue
# is the requester authorized
serial = ch.getTokenSerial()
tokens = getTokens4UserOrSerial(serial=serial)
if not tokens:
continue
involved_tokens.extend(tokens)
if 1 not in pin_policies:
pin_match = check_pin(tokens[0], password, user=user,
options=None)
if not pin_match:
ret = False
continue
ret = True
trans_dict = {}
trans_dict['transactionid'] = ch.transid
trans_dict['received_count'] = ch.received_count
trans_dict['received_tan'] = ch.received_tan
trans_dict['valid_tan'] = ch.valid_tan
trans_dict['linotp_tokenserial'] = serial
trans_dict['linotp_tokentype'] = tokens[0].type
trans_dict['message'] = ch.challenge
transactions[serial] = trans_dict
if transactions:
reply['transactions'] = transactions
return ret, reply
示例3: checkTokenList
# 需要導入模塊: from linotp.lib.challenges import Challenges [as 別名]
# 或者: from linotp.lib.challenges.Challenges import delete_challenges [as 別名]
#.........這裏部分代碼省略.........
if token_access_exceed:
msg = "Authentication counter exceeded"
if token_success_excceed:
msg = "Authentication sucess counter exceeded"
if token_expiry:
msg = "Authentication validity period exceeded!"
audit_entry['action_detail'] = msg
token.incOtpFailCounter()
# what should happen with exceeding tokens
t_realms = None
if not user.login and not user.realm:
t_realms = token.token.getRealmNames()
if disable_on_authentication_exceed(user, realms=t_realms):
token.enable(False)
if delete_on_authentication_exceed(user, realms=t_realms):
token.deleteToken()
continue
# -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
# start the token validation
if not transid:
# if there is no transaction id given we check all token
# related challenges
(_ex_challenges,
challenges) = Challenges.get_challenges(token,
options=check_options,
filter_open=True)
try:
(ret, reply) = token.check_token(
passw, user, options=check_options, challenges=challenges)
except Exception as exx:
# in case of a failure during checking token, we log the error
# and continue with the next one
log.exception("checking token %r failed: %r" % (token, exx))
ret = -1
reply = "%r" % exx
audit_entry['action_detail'] = ("checking token %r "
"failed: %r" % (token, exx))
audit_entry['info'] = audit_entry.get('info','') + "%r" % exx
continue
finally:
validation_results[token.getSerial()] = (ret, reply)
(cToken, pToken, iToken, vToken) = token.get_verification_result()
related_challenges.extend(token.related_challenges)
challenge_tokens.extend(cToken)
pin_matching_tokens.extend(pToken)
invalid_tokens.extend(iToken)
valid_tokens.extend(vToken)
# end of token verification loop
matching_challenges = []
for token in valid_tokens:
matching_challenges.extend(token.matching_challenges)
# if there are related / sub challenges, we have to call their janitor
Challenges.handle_related_challenge(matching_challenges)
# now we finalize the token validation result
fh = FinishTokens(valid_tokens,
challenge_tokens,
pin_matching_tokens,
invalid_tokens,
validation_results,
user, options,
audit_entry=audit_entry)
(res, reply) = fh.finish_checked_tokens()
# add to all tokens the last accessd time stamp
add_last_accessed_info(
[valid_tokens, pin_matching_tokens, challenge_tokens, valid_tokens])
# now we care for all involved tokens and their challenges
for token in (valid_tokens + pin_matching_tokens +
challenge_tokens + invalid_tokens):
expired, _valid = Challenges.get_challenges(token)
if expired:
Challenges.delete_challenges(None, expired)
log.debug("Number of valid tokens found "
"(validTokenNum): %d" % len(valid_tokens))
return (res, reply)
示例4: check_status
# 需要導入模塊: from linotp.lib.challenges import Challenges [as 別名]
# 或者: from linotp.lib.challenges.Challenges import delete_challenges [as 別名]
def check_status(self, transid=None, user=None, serial=None,
password=None, use_offline=False):
"""
check for open transactions - for polling support
:param transid: the transaction id where we request the status from
:param user: the token owner user
:param serial: or the serial we are searching for
:param password: the pin/password for authorization the request
:param use_offline: on success the offline info is returned
:return: tuple of success and detail dict
"""
expired, challenges = Challenges.get_challenges(None, transid=transid)
# remove all expired challenges
if expired:
Challenges.delete_challenges(None, expired)
if not challenges:
return False, None
# there is only one challenge per transaction id
# if not multiple challenges, where transaction id is the parent one
reply = {}
pin_policies = linotp.lib.policy.get_pin_policies(user)
if 1 in pin_policies:
pin_match = check_pin(None, password, user=user, options=None)
if not pin_match:
return False, None
involved_tokens = []
transactions = {}
for ch in challenges:
# only look for challenges that are not compromised
if not Challenges.verify_checksum(ch):
continue
# is the requester authorized
serial = ch.getTokenSerial()
tokens = getTokens4UserOrSerial(serial=serial)
if not tokens:
continue
involved_tokens.extend(tokens)
# as one challenge belongs exactly to only one token,
# we take this one as the token
token = tokens[0]
if 1 not in pin_policies:
pin_match = check_pin(token, password, user=user,
options=None)
if not pin_match:
ret = False
continue
ret = True
trans_dict = {}
trans_dict['received_count'] = ch.received_count
trans_dict['received_tan'] = ch.received_tan
trans_dict['valid_tan'] = ch.valid_tan
trans_dict['message'] = ch.challenge
trans_dict['status'] = ch.getStatus()
token_dict = {'serial': serial, 'type': token.type}
# 1. check if token supports offline at all
supports_offline_at_all = token.supports_offline_mode
# 2. check if policy allows to use offline authentication
if user is not None and user.login and user.realm:
realms = [user.realm]
else:
realms = token.getRealms()
offline_is_allowed = supports_offline(realms, token)
if not ch.is_open() and ch.valid_tan and \
supports_offline_at_all and \
offline_is_allowed and \
use_offline:
token_dict['offline_info'] = token.getOfflineInfo()
trans_dict['token'] = token_dict
transactions[ch.transid] = trans_dict
if transactions:
reply['transactions'] = transactions
return ret, reply
示例5: check_status
# 需要導入模塊: from linotp.lib.challenges import Challenges [as 別名]
# 或者: from linotp.lib.challenges.Challenges import delete_challenges [as 別名]
def check_status(self, transid=None, user=None, serial=None,
password=None, use_offline=False):
"""
check for open transactions - for polling support
:param transid: the transaction id where we request the status from
:param user: the token owner user
:param serial: or the serial we are searching for
:param password: the pin/password for authorization the request
:param use_offline: on success the offline info is returned
:return: tuple of success and detail dict
"""
expired, challenges = Challenges.get_challenges(token=None, transid=transid)
# remove all expired challenges
if expired:
Challenges.delete_challenges(None, expired)
if not challenges:
return False, None
# there is only one challenge per transaction id
# if not multiple challenges, where transaction id is the parent one
reply = {}
involved_tokens = []
transactions = {}
for ch in challenges:
# only look for challenges that are not compromised
if not Challenges.verify_checksum(ch):
continue
# is the requester authorized
challenge_serial = ch.getTokenSerial()
if serial and challenge_serial != serial:
continue
tokens = getTokens4UserOrSerial(serial=challenge_serial)
if not tokens:
continue
involved_tokens.extend(tokens)
# as one challenge belongs exactly to only one token,
# we take this one as the token
token = tokens[0]
owner = get_token_owner(token)
if user and user != owner:
continue
involved_tokens.extend(tokens)
# we only check the user password / token pin if the user
# paranmeter is given
if user and owner:
pin_match = check_pin(token, password, user=owner,
options=None)
else:
pin_match = token.checkPin(password)
if not pin_match:
continue
trans_dict = {}
trans_dict['received_count'] = ch.received_count
trans_dict['received_tan'] = ch.received_tan
trans_dict['valid_tan'] = ch.valid_tan
trans_dict['message'] = ch.challenge
trans_dict['status'] = ch.getStatus()
# -------------------------------------------------------------- --
# extend the check status with the accept or deny of a transaction
challenge_session = ch.getSession()
if challenge_session:
challenge_session_dict = json.loads(challenge_session)
if 'accept' in challenge_session_dict:
trans_dict['accept'] = challenge_session_dict['accept']
if 'reject' in challenge_session_dict:
trans_dict['reject'] = challenge_session_dict['reject']
# -------------------------------------------------------------- --
token_dict = {'serial': token.getSerial(), 'type': token.type}
# 1. check if token supports offline at all
supports_offline_at_all = token.supports_offline_mode
# 2. check if policy allows to use offline authentication
#.........這裏部分代碼省略.........