def prepareForStep(self, configurationAttributes, requestParameters, step): context = Contexts.getEventContext() if (step == 1): context.set("display_register_action", True) return True elif (step == 2): print "oxPush2. Prepare for step 2" credentials = Identity.instance().getCredentials() user = credentials.getUser() if (user == None): print "oxPush2. Prepare for step 2. Failed to determine user name" return False session_attributes = context.get("sessionAttributes") if session_attributes.containsKey("oxpush2_request"): print "oxPush2. Prepare for step 2. Request was generated already" return True session_state = SessionStateService.instance().getSessionStateFromCookie() if StringHelper.isEmpty(session_state): print "oxPush2. Prepare for step 2. Failed to determine session_state" return False auth_method = session_attributes.get("oxpush2_auth_method") if StringHelper.isEmpty(auth_method): print "oxPush2. Prepare for step 2. Failed to determine auth_method" return False print "oxPush2. Prepare for step 2. auth_method: '%s'" % auth_method issuer = ConfigurationFactory.instance().getConfiguration().getIssuer() oxpush2_request = json.dumps({'username': user.getUserId(), 'app': self.u2f_application_id, 'issuer': issuer, 'method': auth_method, 'state': session_state}, separators=(',',':')) print "oxPush2. Prepare for step 2. Prepared oxpush2_request:", oxpush2_request context.set("oxpush2_request", oxpush2_request) return True else: return False
def prepareForStep(self, configurationAttributes, requestParameters, step): context = Contexts.getEventContext() session_attributes = context.get("sessionAttributes") client_redirect_uri = self.getClientRedirecUri(session_attributes) if client_redirect_uri == None: print "Super-Gluu. Prepare for step. redirect_uri is not set" return False self.setEventContextParameters(context) if step == 1: print "Super-Gluu. Prepare for step 1" if self.oneStep: session_state = SessionStateService.instance().getSessionStateFromCookie() if StringHelper.isEmpty(session_state): print "Super-Gluu. Prepare for step 2. Failed to determine session_state" return False issuer = ConfigurationFactory.instance().getConfiguration().getIssuer() super_gluu_request_dictionary = {'app': client_redirect_uri, 'issuer': issuer, 'state': session_state, 'created': datetime.datetime.now().isoformat()} self.addGeolocationData(session_attributes, super_gluu_request_dictionary) super_gluu_request = json.dumps(super_gluu_request_dictionary, separators=(',',':')) print "Super-Gluu. Prepare for step 1. Prepared super_gluu_request:", super_gluu_request context.set("super_gluu_request", super_gluu_request) # elif self.twoStep: # context.set("display_register_action", True) return True elif step == 2: print "Super-Gluu. Prepare for step 2" if self.oneStep: return True authenticationService = AuthenticationService.instance() user = authenticationService.getAuthenticatedUser() if user == None: print "Super-Gluu. Prepare for step 2. Failed to determine user name" return False if session_attributes.containsKey("super_gluu_request"): print "Super-Gluu. Prepare for step 2. Request was generated already" return True session_state = SessionStateService.instance().getSessionStateFromCookie() if StringHelper.isEmpty(session_state): print "Super-Gluu. Prepare for step 2. Failed to determine session_state" return False auth_method = session_attributes.get("super_gluu_auth_method") if StringHelper.isEmpty(auth_method): print "Super-Gluu. Prepare for step 2. Failed to determine auth_method" return False print "Super-Gluu. Prepare for step 2. auth_method: '%s'" % auth_method issuer = ConfigurationFactory.instance().getConfiguration().getIssuer() super_gluu_request_dictionary = {'username': user.getUserId(), 'app': client_redirect_uri, 'issuer': issuer, 'method': auth_method, 'state': session_state, 'created': datetime.datetime.now().isoformat()} self.addGeolocationData(session_attributes, super_gluu_request_dictionary) super_gluu_request = json.dumps(super_gluu_request_dictionary, separators=(',',':')) print "Super-Gluu. Prepare for step 2. Prepared super_gluu_request:", super_gluu_request context.set("super_gluu_request", super_gluu_request) if auth_method in ['authenticate']: self.sendPushNotification(client_redirect_uri, user, super_gluu_request) return True else: return False