43 def authenticate(self, configurationAttributes, requestParameters, step):
44 identity = CdiUtil.bean(Identity)
46 userService = CdiUtil.bean(UserService)
47 authenticationService = CdiUtil.bean(AuthenticationService)
48 httpService = CdiUtil.bean(HttpService)
50 server_flag = configurationAttributes.get(
"oneid_server_flag").getValue2()
51 callback_attrs = configurationAttributes.get(
"oneid_callback_attrs").getValue2()
52 creds_file = configurationAttributes.get(
"oneid_creds_file").getValue2()
55 authn = OneID(server_flag)
58 authn.creds_file = creds_file
61 print "OneId. Authenticate for step 1" 64 json_data_array = requestParameters.get(
"json_data")
65 if ArrayHelper.isEmpty(json_data_array):
66 print "OneId. Authenticate for step 1. json_data is empty" 69 request = json_data_array[0]
70 print "OneId. Authenticate for step 1. request: " + request
72 if (StringHelper.isEmptyString(request)):
75 authn.set_credentials()
78 http_client = httpService.getHttpsClientDefaulTrustStore()
79 auth_data = httpService.encodeBase64(authn.api_id +
":" + authn.api_key)
80 http_response = httpService.executePost(http_client, authn.helper_server +
"/validate", auth_data, request, ContentType.APPLICATION_JSON)
81 validation_content = httpService.convertEntityToString(httpService.getResponseContent(http_response))
82 print "OneId. Authenticate for step 1. validation_content: " + validation_content
84 if (StringHelper.isEmptyString(validation_content)):
87 validation_resp = json.loads(validation_content)
88 print "OneId. Authenticate for step 1. validation_resp: " + str(validation_resp)
90 if (
not authn.success(validation_resp)):
93 response = json.loads(request)
94 for x
in validation_resp:
95 response[x] = validation_resp[x]
97 oneid_user_uid = response[
'uid']
98 print "OneId. Authenticate for step 1. oneid_user_uid: " + oneid_user_uid
101 find_user_by_uid = userService.getUserByAttribute(
"oxExternalUid",
"oneid:" + oneid_user_uid)
103 if (find_user_by_uid ==
None):
104 print "OneId. Authenticate for step 1. Failed to find user" 105 print "OneId. Authenticate for step 1. Setting count steps to 2" 106 identity.setWorkingParameter(
"oneid_count_login_steps", 2)
107 identity.setWorkingParameter(
"oneid_user_uid", oneid_user_uid)
110 found_user_name = find_user_by_uid.getUserId()
111 print "OneId. Authenticate for step 1. found_user_name: " + found_user_name
113 identity = CdiUtil.bean(Identity)
114 credentials = identity.getCredentials()
116 credentials.setUsername(found_user_name)
117 credentials.setUser(find_user_by_uid)
119 print "OneId. Authenticate for step 1. Setting count steps to 1" 120 identity.setWorkingParameter(
"oneid_count_login_steps", 1)
124 print "OneId. Authenticate for step 2" 126 sessionAttributes = identity.getSessionId().getSessionAttributes()
127 if (sessionAttributes ==
None)
or not sessionAttributes.containsKey(
"oneid_user_uid"):
128 print "OneId. Authenticate for step 2. oneid_user_uid is empty" 131 oneid_user_uid = sessionAttributes.get(
"oneid_user_uid")
132 passed_step1 = StringHelper.isNotEmptyString(oneid_user_uid)
133 if (
not passed_step1):
136 identity = CdiUtil.bean(Identity)
137 credentials = identity.getCredentials()
139 user_name = credentials.getUsername()
140 passed_step1 = StringHelper.isNotEmptyString(user_name)
142 if (
not passed_step1):
145 identity = CdiUtil.bean(Identity)
146 credentials = identity.getCredentials()
148 user_name = credentials.getUsername()
149 user_password = credentials.getPassword()
151 if (StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password)):
152 logged_in = authenticationService.authenticate(user_name, user_password)
159 find_user_by_uid = userService.getUserByAttribute(
"oxExternalUid",
"oneid:" + oneid_user_uid)
161 if (find_user_by_uid ==
None):
163 find_user_by_uid = userService.addUserAttribute(user_name,
"oxExternalUid",
"oneid:" + oneid_user_uid)
164 if (find_user_by_uid ==
None):
165 print "OneId. Authenticate for step 2. Failed to update current user" 170 found_user_name = find_user_by_uid.getUserId()
171 print "OneId. Authenticate for step 2. found_user_name: " + found_user_name
173 if StringHelper.equals(user_name, found_user_name):