86 def authenticate(self, configurationAttributes, requestParameters, step):
87 identity = CdiUtil.bean(Identity)
88 credentials = identity.getCredentials()
90 session_attributes = identity.getSessionId().getSessionAttributes()
92 self.setRequestScopedParameters(identity)
95 print "UAF. Authenticate for step 1" 97 user_name = credentials.getUsername()
99 authenticated_user = self.processBasicAuthentication(credentials)
100 if authenticated_user ==
None:
103 uaf_auth_method =
"authenticate" 109 if uaf_auth_method ==
"authenticate":
110 user_enrollments = self.findEnrollments(credentials)
111 if len(user_enrollments) == 0:
112 uaf_auth_method =
"enroll" 113 print "UAF. Authenticate for step 1. There is no UAF enrollment for user '%s'. Changing uaf_auth_method to '%s'" % (user_name, uaf_auth_method)
115 print "UAF. Authenticate for step 1. uaf_auth_method: '%s'" % uaf_auth_method
117 identity.setWorkingParameter(
"uaf_auth_method", uaf_auth_method)
121 print "UAF. Authenticate for step 2" 123 session_id = CdiUtil.bean(SessionIdService).getSessionIdFromCookie()
124 if StringHelper.isEmpty(session_id):
125 print "UAF. Prepare for step 2. Failed to determine session_id" 128 user = authenticationService.getAuthenticatedUser()
130 print "UAF. Authenticate for step 2. Failed to determine user name" 132 user_name = user.getUserId()
134 uaf_auth_result = ServerUtil.getFirstValue(requestParameters,
"auth_result")
135 if uaf_auth_result !=
"success":
136 print "UAF. Authenticate for step 2. auth_result is '%s'" % uaf_auth_result
140 uaf_auth_method = session_attributes.get(
"uaf_auth_method")
142 if not uaf_auth_method
in [
'enroll',
'authenticate']:
143 print "UAF. Authenticate for step 2. Failed to authenticate user. uaf_auth_method: '%s'" % uaf_auth_method
150 uaf_user_device_handle = ServerUtil.getFirstValue(requestParameters,
"auth_handle")
152 uaf_obb_auth_method = session_attributes.get(
"uaf_obb_auth_method")
153 uaf_obb_server_uri = session_attributes.get(
"uaf_obb_server_uri")
154 uaf_obb_start_response = session_attributes.get(
"uaf_obb_start_response")
157 uaf_obb_start_response_json = json.loads(uaf_obb_start_response)
158 uaf_obb_status_request_dictionary = {
"operation":
"STATUS_%s" % uaf_obb_auth_method,
159 "userName": user_name,
161 "oobStatusHandle": uaf_obb_start_response_json[
"oobStatusHandle"],
164 uaf_obb_status_request = json.dumps(uaf_obb_status_request_dictionary, separators=(
',',
':'))
165 print "UAF. Authenticate for step 2. Prepared STATUS request: '%s' to send to '%s'" % (uaf_obb_status_request, uaf_obb_server_uri)
167 uaf_status_obb_response = self.executePost(uaf_obb_server_uri, uaf_obb_status_request)
168 if uaf_status_obb_response ==
None:
171 print "UAF. Authenticate for step 2. Get STATUS response: '%s'" % uaf_status_obb_response
172 uaf_status_obb_response_json = json.loads(uaf_status_obb_response)
174 if uaf_status_obb_response_json[
"statusCode"] != 4000:
175 print "UAF. Authenticate for step 2. UAF operation status is invalid. statusCode: '%s'" % uaf_status_obb_response_json[
"statusCode"]
178 uaf_user_device_handle = uaf_status_obb_response_json[
"additionalInfo"][
"authenticatorsResult"][
"handle"]
180 if StringHelper.isEmpty(uaf_user_device_handle):
181 print "UAF. Prepare for step 2. Failed to get UAF handle" 184 uaf_user_external_uid =
"uaf:%s" % uaf_user_device_handle
185 print "UAF. Authenticate for step 2. UAF handle: '%s'" % uaf_user_external_uid
187 if uaf_auth_method ==
"authenticate":
189 user_enrollments = self.findEnrollments(credentials)
190 if len(user_enrollments) == 0:
191 uaf_auth_method =
"enroll" 192 print "UAF. Authenticate for step 2. There is no UAF enrollment for user '%s'." % user_name
195 for user_enrollment
in user_enrollments:
196 if StringHelper.equalsIgnoreCase(user_enrollment, uaf_user_device_handle):
197 print "UAF. Authenticate for step 2. There is UAF enrollment for user '%s'. User authenticated successfully" % user_name
200 userService = CdiUtil.bean(UserService)
205 find_user_by_external_uid = userService.getUserByAttribute(
"oxExternalUid", uaf_user_external_uid)
206 if find_user_by_external_uid ==
None:
208 find_user_by_external_uid = userService.addUserAttribute(user_name,
"oxExternalUid", uaf_user_external_uid)
209 if find_user_by_external_uid ==
None:
210 print "UAF. Authenticate for step 2. Failed to update current user"