66 def authenticate(self, configurationAttributes, requestParameters, step):
67 authenticationService = CdiUtil.bean(AuthenticationService)
69 identity = CdiUtil.bean(Identity)
70 credentials = identity.getCredentials()
72 user_name = credentials.getUsername()
74 print "PhoneFactor. Authenticate for step 1" 76 user_password = credentials.getPassword()
78 if (StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password)):
79 userService = CdiUtil.bean(UserService)
80 logged_in = authenticationService.authenticate(user_name, user_password)
87 print "PhoneFactor. Authenticate for step 2" 89 passed_step1 = self.isPassedDefaultAuthentication
90 if (
not passed_step1):
93 pf_phone_number_attr = configurationAttributes.get(
"pf_phone_number_attr").getValue2()
96 authenticationService = CdiUtil.bean(AuthenticationService)
97 credentials_user = authenticationService.getAuthenticatedUser()
99 userService = CdiUtil.bean(UserService)
100 phone_number_with_country_code_attr = userService.getCustomAttribute(credentials_user, pf_phone_number_attr)
101 if (phone_number_with_country_code_attr ==
None):
102 print "PhoneFactor. Authenticate for step 2. There is no phone number: ", user_name
105 phone_number_with_country_code = phone_number_with_country_code_attr.getValue()
106 if (phone_number_with_country_code ==
None):
107 print "PhoneFactor. Authenticate for step 2. There is no phone number: ", user_name
110 pf_country_delimiter = configurationAttributes.get(
"pf_country_delimiter").getValue2()
112 phone_number_with_country_code_array = string.split(phone_number_with_country_code, pf_country_delimiter, 1)
114 phone_number_with_country_code_array_len = len(phone_number_with_country_code_array)
116 if (phone_number_with_country_code_array_len == 1):
118 phone_number = phone_number_with_country_code_array[0]
120 country_code = phone_number_with_country_code_array[0]
121 phone_number = phone_number_with_country_code_array[1]
123 print "PhoneFactor. Authenticate for step 2. user_name: ", user_name,
", country_code: ", country_code,
", phone_number: ", phone_number
125 pf_auth_result =
None 127 pf_auth_result = self.pf.authenticate(user_name, country_code, phone_number,
None,
None,
None)
128 except SecurityException, err:
129 print "PhoneFactor. Authenticate for step 2. BAD AUTH -- Security issue: ", err
130 except TimeoutException, err:
131 print "PhoneFactor. Authenticate for step 2. BAD AUTH -- Server timeout: ", err
132 except PFException, err:
133 print "PhoneFactor. Authenticate for step 2. BAD AUTH -- PFAuth failed with a PFException: ", err
135 if (pf_auth_result ==
None):
138 print "PhoneFactor. Authenticate for step 2. Call Status: ", pf_auth_result.getCallStatusString()
139 if (pf_auth_result.getAuthenticated()):
140 print "PhoneFactor. Authenticate for step 2. GOOD AUTH:", user_name
142 if (pf_auth_result.getCallStatus() == PFAuthResult.CALL_STATUS_PIN_ENTERED):
143 print "PhoneFactor. Authenticate for step 2. I have detected that a PIN was entered" 144 elif (pf_auth_result.getCallStatus() == PFAuthResult.CALL_STATUS_NO_PIN_ENTERED):
145 print "PhoneFactor. Authenticate for step 2. I have detected that NO PIN was entered" 149 print "PhoneFactor. Authenticate for step 2. BAD AUTH:", user_name
151 if (pf_auth_result.getCallStatus() == PFAuthResult.CALL_STATUS_USER_HUNG_UP):
152 print "PhoneFactor. Authenticate for step 2. I have detected that the user hung up" 153 elif (pf_auth_result.getCallStatus() == PFAuthResult.CALL_STATUS_PHONE_BUSY):
154 print "PhoneFactor. Authenticate for step 2. I have detected that the phone was busy" 156 if (pf_auth_result.getMessageErrorId() != 0):
157 print "PhoneFactor. Authenticate for step 2. Message Error ID: ", pf_auth_result.getMessageErrorId()
159 message_error = pf_auth_result.getMessageError()
160 if (message_error != null):
161 print "PhoneFactor. Authenticate for step 2. Message Error: ", message_error