45 def authenticate(self, configurationAttributes, requestParameters, step):
46 userService = CdiUtil.bean(UserService)
47 authenticationService = CdiUtil.bean(AuthenticationService)
49 identity = CdiUtil.bean(Identity)
50 credentials = identity.getCredentials()
52 oxpush_user_timeout = int(configurationAttributes.get(
"oxpush_user_timeout").getValue2())
53 oxpush_application_name = configurationAttributes.get(
"oxpush_application_name").getValue2()
55 user_name = credentials.getUsername()
58 print "oxPush. Authenticate for step 1" 60 user_password = credentials.getPassword()
62 if (StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password)):
63 userService = CdiUtil.bean(UserService)
64 logged_in = authenticationService.authenticate(user_name, user_password)
70 userService = CdiUtil.bean(UserService)
71 find_user_by_uid = authenticationService.getAuthenticatedUser()
72 if (find_user_by_uid ==
None):
73 print "oxPush. Authenticate for step 1. Failed to find user" 77 user_external_uid_attr = userService.getCustomAttribute(find_user_by_uid,
"oxExternalUid")
78 if ((user_external_uid_attr ==
None)
or (user_external_uid_attr.getValues() ==
None)):
79 print "oxPush. Authenticate for step 1. There is no external UIDs for user: ", user_name
81 oxpush_user_uid =
None 82 for ext_uid
in user_external_uid_attr.getValues():
83 if (ext_uid.startswith(
'oxpush:')):
84 oxpush_user_uid = ext_uid[7:len(ext_uid)]
87 if (oxpush_user_uid ==
None):
88 print "oxPush. Authenticate for step 1. There is no oxPush UID for user: ", user_name
91 print "oxPush. Authenticate for step 1. oxpush_user_uid: ", oxpush_user_uid
92 deployment_status = self.oxPushClient.getDeploymentStatus(oxpush_user_uid)
93 if (deployment_status.result):
94 print "oxPush. Authenticate for step 1. Deployment status is valid" 95 if (
"enabled" == deployment_status.status):
96 print "oxPush. Authenticate for step 1. Deployment is enabled" 97 identity.setWorkingParameter(
"oxpush_user_uid", oxpush_user_uid)
99 print "oxPush. Authenticate for step 1. Deployment is disabled" 102 print "oxPush. Authenticate for step 1. Deployment status is invalid. Force user to pair again" 104 find_user_by_uid = userService.removeUserAttribute(user_name,
"oxExternalUid",
"oxpush:" + oxpush_user_uid)
105 if (find_user_by_uid ==
None):
106 print "oxPush. Authenticate for step 1. Failed to update current user" 111 print "oxPush. Authenticate for step 2" 113 passed_step1 = self.isPassedDefaultAuthentication
114 if (
not passed_step1):
117 sessionAttributes = identity.getSessionId().getSessionAttributes()
118 if (sessionAttributes ==
None)
or not sessionAttributes.containsKey(
"oxpush_user_uid"):
119 print "oxPush. Authenticate for step 2. oxpush_user_uid is empty" 121 if (
not sessionAttributes.containsKey(
"oxpush_pairing_uid")):
122 print "oxPush. Authenticate for step 2. oxpush_pairing_uid is empty" 125 oxpush_pairing_uid = sessionAttributes.get(
"oxpush_pairing_uid")
128 pairing_status = self.checkStatus(
"pair", oxpush_pairing_uid, oxpush_user_timeout)
129 if (pairing_status ==
None):
130 print "oxPush. Authenticate for step 2. The pairing has not been authorized by user" 133 oxpush_user_uid = pairing_status.deploymentId
135 print "oxPush. Authenticate for step 2. Storing oxpush_user_uid in user entry", oxpush_user_uid
138 find_user_by_uid = userService.addUserAttribute(user_name,
"oxExternalUid",
"oxpush:" + oxpush_user_uid)
139 if (find_user_by_uid ==
None):
140 print "oxPush. Authenticate for step 2. Failed to update current user" 143 identity.setWorkingParameter(
"oxpush_count_login_steps", 2)
144 identity.setWorkingParameter(
"oxpush_user_uid", oxpush_user_uid)
146 print "oxPush. Authenticate for step 2. Deployment status is valid" 150 print "oxPush. Authenticate for step 3" 152 passed_step1 = self.isPassedDefaultAuthentication
153 if (
not passed_step1):
156 sessionAttributes = identity.getWorkingParameter(
"oxpush_user_uid")
157 if (sessionAttributes ==
None)
or not sessionAttributes.containsKey(
"oxpush_user_uid"):
158 print "oxPush. Authenticate for step 3. oxpush_user_uid is empty" 161 oxpush_user_uid = sessionAttributes.get(
"oxpush_user_uid")
162 passed_step1 = StringHelper.isNotEmptyString(oxpush_user_uid)
163 if (
not passed_step1):
167 authentication_request =
None 169 authentication_request = self.oxPushClient.authenticate(oxpush_user_uid, user_name)
170 except java.lang.Exception, err:
171 print "oxPush. Authenticate for step 3. Failed to initialize authentication process: ", err
174 if (
not authentication_request.result):
175 print "oxPush. Authenticate for step 3. Failed to initialize authentication process" 179 authentication_status = self.checkStatus(
"authenticate", authentication_request.authenticationId, oxpush_user_timeout)
180 if (authentication_status ==
None):
181 print "oxPush. Authenticate for step 3. The authentication has not been authorized by user" 184 print "oxPush. Authenticate for step 3. The request was granted"