65 def authenticate(self, configurationAttributes, requestParameters, step):
66 userService = CdiUtil.bean(UserService)
67 authenticationService = CdiUtil.bean(AuthenticationService)
69 identity = CdiUtil.bean(Identity)
70 credentials = identity.getCredentials()
72 toopher_user_timeout = int(configurationAttributes.get(
"toopher_user_timeout").getValue2())
74 user_name = credentials.getUsername()
77 print "Toopher. Authenticate for step 1" 79 user_password = credentials.getPassword()
81 if (StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password)):
82 userService = CdiUtil.bean(UserService)
83 logged_in = authenticationService.authenticate(user_name, user_password)
89 userService = CdiUtil.bean(UserService)
90 find_user_by_uid = authenticationService.getAuthenticatedUser()
91 if (find_user_by_uid ==
None):
92 print "Toopher. Authenticate for step 1. Failed to find user" 96 user_external_uid_attr = userService.getCustomAttribute(find_user_by_uid,
"oxExternalUid")
97 if ((user_external_uid_attr ==
None)
or (user_external_uid_attr.getValues() ==
None)):
98 print "Toopher. Authenticate for step 1. There is no external UIDs for user: ", user_name
100 topher_user_uid =
None 101 for ext_uid
in user_external_uid_attr.getValues():
102 if (ext_uid.startswith(
'toopher:')):
103 topher_user_uid = ext_uid[8:len(ext_uid)]
106 if (topher_user_uid ==
None):
107 print "Toopher. Authenticate for step 1. There is no Topher UID for user: ", user_name
109 identity.setWorkingParameter(
"toopher_user_uid", topher_user_uid)
113 print "Toopher. Authenticate for step 2" 115 passed_step1 = self.isPassedDefaultAuthentication
116 if (
not passed_step1):
119 sessionAttributes = identity.getSessionId().getSessionAttributes()
120 if (sessionAttributes ==
None)
or not sessionAttributes.containsKey(
"toopher_user_uid"):
121 print "Toopher. Authenticate for step 2. toopher_user_uid is empty" 124 pairing_phrase_array = requestParameters.get(
"pairing_phrase")
125 if ArrayHelper.isEmpty(pairing_phrase_array):
126 print "Toopher. Authenticate for step 2. pairing_phrase is empty" 129 pairing_phrase = pairing_phrase_array[0]
131 pairing_status = self.tapi.pair(pairing_phrase, user_name)
132 toopher_user_uid = pairing_status.id
133 except RequestError, err:
134 print "Toopher. Authenticate for step 2. Failed pair with phone: ", err
137 pairing_result = self.checkPairingStatus(toopher_user_uid, toopher_user_timeout)
139 if (
not pairing_result):
140 print "Toopher. Authenticate for step 2. The pairing has not been authorized by the phone yet" 143 print "Toopher. Authenticate for step 2. Storing toopher_user_uid in user entry", toopher_user_uid
146 find_user_by_uid = userService.addUserAttribute(user_name,
"oxExternalUid",
"toopher:" + toopher_user_uid)
147 if (find_user_by_uid ==
None):
148 print "Toopher. Authenticate for step 2. Failed to update current user" 151 identity.setWorkingParameter(
"toopher_user_uid", toopher_user_uid)
153 toopher_user_uid = sessionAttributes.get(
"toopher_user_uid")
156 print "Toopher. Authenticate for step 2. toopher_user_uid: ", toopher_user_uid
157 pairing_result = self.checkPairingStatus(toopher_user_uid, 0)
158 if (
not pairing_result):
159 print "Toopher. Authenticate for step 2. The pairing has not been authorized by the phone yet" 164 print "Toopher. Authenticate for step 3" 166 passed_step1 = self.isPassedDefaultAuthentication
167 if (
not passed_step1):
170 sessionAttributes = identity.getSessionId().getSessionAttributes()
171 if (sessionAttributes ==
None)
or not sessionAttributes.containsKey(
"toopher_user_uid"):
172 print "Toopher. Authenticate for step 3. toopher_user_uid is empty" 175 toopher_user_uid = sessionAttributes.get(
"toopher_user_uid")
176 passed_step1 = StringHelper.isNotEmptyString(toopher_user_uid)
177 if (
not passed_step1):
180 toopher_terminal_name = configurationAttributes.get(
"toopher_terminal_name").getValue2()
183 request_status = self.tapi.authenticate(toopher_user_uid, toopher_terminal_name)
184 request_id = request_status.id
185 except RequestError, err:
186 print "Toopher. Authenticate for step 3. Failed to send authentication request to phone: ", err
189 print "Toopher. Authenticate for step 3. request_id: ", request_id
190 request_result = self.checkRequestStatus(request_id, toopher_user_timeout)
192 if (
not request_result):
193 print "Toopher. Authenticate for step 3. The authentication request has not received a response from the phone yet" 196 print "Toopher. Authenticate for step 3. The request was granted"