38 def authenticate(self, configurationAttributes, requestParameters, step):
39 authenticationService = CdiUtil.bean(AuthenticationService)
40 userService = CdiUtil.bean(UserService)
42 identity = CdiUtil.bean(Identity)
43 credentials = identity.getCredentials()
45 print "Basic (with password update). Authenticate for step 1" 46 user_name = credentials.getUsername()
47 user_password = credentials.getPassword()
50 if StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password):
51 logged_in = authenticationService.authenticate(user_name, user_password)
56 find_user_by_uid = authenticationService.getAuthenticatedUser()
57 user_expDate = find_user_by_uid.getAttribute(
"oxPasswordExpirationDate",
False)
59 if user_expDate ==
None:
60 print "Basic (with password update). Authenticate for step 1. User has no oxPasswordExpirationDate date" 63 dt = StaticUtils.decodeGeneralizedTime(user_expDate)
66 calendar = GregorianCalendar(TimeZone.getTimeZone(
"UTC"));
67 now = calendar.getTime()
68 if now.compareTo(dt) > 0:
71 calendar.add(calendar.DATE, 90)
72 dt_plus_90 = calendar.getTime()
73 expDate = StaticUtils.encodeGeneralizedTime(dt_plus_90)
74 identity.setWorkingParameter(
"expDate", expDate)
78 print "Basic (with password update). Authenticate for step 2" 79 user = authenticationService.getAuthenticatedUser()
81 print "Basic (with password update). Authenticate for step 2. Failed to determine user name" 84 user_name = user.getUserId()
85 find_user_by_uid = userService.getUser(user_name)
86 newExpDate = identity.getWorkingParameter(
"expDate")
88 if find_user_by_uid ==
None:
89 print "Basic (with password update). Authenticate for step 2. Failed to find user" 92 print "Basic (with password update). Authenticate for step 2" 93 update_button = requestParameters.get(
"loginForm:updateButton")
95 if ArrayHelper.isEmpty(update_button):
98 find_user_by_uid.setAttribute(
"oxPasswordExpirationDate", newExpDate)
99 new_password_array = requestParameters.get(
"new_password")
100 if ArrayHelper.isEmpty(new_password_array)
or StringHelper.isEmpty(new_password_array[0]):
101 print "Basic (with password update). Authenticate for step 2. New password is empty" 104 new_password = new_password_array[0]
105 find_user_by_uid.setAttribute(
"userPassword", new_password)
106 print "Basic (with password update). Authenticate for step 2. Attempting to set new user '%s' password" % user_name
108 userService.updateUser(find_user_by_uid)
109 print "Basic (with password update). Authenticate for step 2. Password updated successfully"