71 def authenticate(self, configurationAttributes, requestParameters, step):
72 userService = CdiUtil.bean(UserService)
73 authenticationService = CdiUtil.bean(AuthenticationService)
75 identity = CdiUtil.bean(Identity)
76 session_attributes = identity.getSessionId().getSessionAttributes()
78 form_passcode = ServerUtil.getFirstValue(requestParameters,
"passcode")
79 form_name = ServerUtil.getFirstValue(requestParameters,
"TwilioSmsloginForm")
81 print "TwilioSMS. form_response_passcode: %s" % str(form_passcode)
84 print "TwilioSMS. Step 1 Password Authentication" 85 identity = CdiUtil.bean(Identity)
86 credentials = identity.getCredentials()
88 user_name = credentials.getUsername()
89 user_password = credentials.getPassword()
92 if StringHelper.isNotEmptyString(user_name)
and StringHelper.isNotEmptyString(user_password):
93 logged_in = authenticationService.authenticate(user_name, user_password)
101 foundUser = authenticationService.getAuthenticatedUser()
103 print 'TwilioSMS, Error retrieving user %s from LDAP' % (user_name)
107 isVerified = foundUser.getAttribute(
"phoneNumberVerified")
109 mobile_number = foundUser.getAttribute(
"employeeNumber")
110 if mobile_number ==
None:
111 mobile_number = foundUser.getAttribute(
"mobile")
112 if mobile_number ==
None:
113 mobile_number = foundUser.getAttribute(
"telephoneNumber")
114 if mobile_number ==
None:
115 print "TwilioSMS, Error finding mobile number for user '%'" % user_name
118 print 'TwilioSMS, Error finding mobile number for' % (user_name)
122 code = random.randint(100000, 999999)
125 identity.setWorkingParameter(
"code", code)
128 Twilio.init(self.ACCOUNT_SID, self.AUTH_TOKEN);
129 message = Message.creator(PhoneNumber(mobile_number), PhoneNumber(self.FROM_NUMBER), str(code)).create();
131 print 'TwilioSMs, Message Sid: %s' % (message.getSid())
133 except Exception, ex:
134 print "TwilioSMS. Error sending message to Twilio" 135 print "TwilioSMS. Unexpected error:", ex
140 print "TwilioSMS. Step 2 SMS/OTP Authentication" 141 code = session_attributes.get(
"code")
142 print "TwilioSMS. Code: %s" % str(code)
145 print "TwilioSMS. Failed to find previously sent code" 148 if form_passcode
is None:
149 print "TwilioSMS. Passcode is empty" 152 if len(form_passcode) != 6:
153 print "TwilioSMS. Passcode from response is not 6 digits: %s" % form_passcode
156 if form_passcode == code:
157 print "TiwlioSMS, SUCCESS! User entered the same code!" 160 print "TwilioSMS. FAIL! User entered the wrong code! %s != %s" % (form_passcode, code)
164 print "TwilioSMS. ERROR: step param not found or != (1|2)"