736 def sendPushNotificationImpl(self, client_redirect_uri, user, super_gluu_request):
737 if not self.enabledPushNotifications:
740 user_name = user.getUserId()
741 print "Super-Gluu. Send push notification. Loading user '%s' devices" % user_name
743 send_notification =
False 744 send_notification_result =
True 746 userService = CdiUtil.bean(UserService)
747 deviceRegistrationService = CdiUtil.bean(DeviceRegistrationService)
749 user_inum = userService.getUserInum(user_name)
753 u2f_devices_list = deviceRegistrationService.findUserDeviceRegistrations(user_inum, client_redirect_uri,
"oxId",
"oxDeviceData",
"oxDeviceNotificationConf")
754 if u2f_devices_list.size() > 0:
755 for u2f_device
in u2f_devices_list:
756 device_data = u2f_device.getDeviceData()
759 if device_data ==
None:
762 platform = device_data.getPlatform()
763 push_token = device_data.getPushToken()
766 if StringHelper.equalsIgnoreCase(platform,
"ios")
and StringHelper.isNotEmpty(push_token):
768 if self.pushAppleService ==
None:
769 print "Super-Gluu. Send push notification. Apple native push notification service is not enabled" 771 send_notification =
True 774 message =
"Super-Gluu login request to: %s" % client_redirect_uri
776 if self.pushSnsMode
or self.pushGluuMode:
777 pushSnsService = CdiUtil.bean(PushSnsService)
778 targetEndpointArn = self.getTargetEndpointArn(deviceRegistrationService, pushSnsService, PushPlatform.APNS, user, u2f_device)
779 if targetEndpointArn ==
None:
782 send_notification =
True 784 sns_push_request_dictionary = {
"aps":
786 "alert" : {
"body": message,
"title" : title},
787 "category":
"ACTIONABLE",
788 "content-available":
"1",
791 "request" : super_gluu_request
793 push_message = json.dumps(sns_push_request_dictionary, separators=(
',',
':'))
796 apple_push_platform = PushPlatform.APNS
797 if not self.pushAppleServiceProduction:
798 apple_push_platform = PushPlatform.APNS_SANDBOX
800 send_notification_result = pushSnsService.sendPushMessage(self.pushAppleService, apple_push_platform, targetEndpointArn, push_message,
None)
802 print "Super-Gluu. Send iOS SNS push notification. token: '%s', message: '%s', send_notification_result: '%s', apple_push_platform: '%s'" % (push_token, push_message, send_notification_result, apple_push_platform)
803 elif self.pushGluuMode:
804 send_notification_result = self.pushAppleService.sendNotification(self.pushAppleServiceAuth, targetEndpointArn, push_message)
806 print "Super-Gluu. Send iOS Gluu push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
808 additional_fields = {
"request" : super_gluu_request }
810 msgBuilder = APNS.newPayload().alertBody(message).alertTitle(title).sound(
"default")
811 msgBuilder.category(
'ACTIONABLE').badge(0)
812 msgBuilder.forNewsstand()
813 msgBuilder.customFields(additional_fields)
814 push_message = msgBuilder.build()
816 send_notification_result = self.pushAppleService.push(push_token, push_message)
818 print "Super-Gluu. Send iOS Native push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
819 send_ios = send_ios + 1
821 if StringHelper.equalsIgnoreCase(platform,
"android")
and StringHelper.isNotEmpty(push_token):
823 if self.pushAndroidService ==
None:
824 print "Super-Gluu. Send native push notification. Android native push notification service is not enabled" 826 send_notification =
True 829 if self.pushSnsMode
or self.pushGluuMode:
830 pushSnsService = CdiUtil.bean(PushSnsService)
831 targetEndpointArn = self.getTargetEndpointArn(deviceRegistrationService, pushSnsService, PushPlatform.GCM, user, u2f_device)
832 if targetEndpointArn ==
None:
835 send_notification =
True 837 sns_push_request_dictionary = {
"collapse_key":
"single",
838 "content_available":
True,
841 {
"message" : super_gluu_request,
844 push_message = json.dumps(sns_push_request_dictionary, separators=(
',',
':'))
847 send_notification_result = pushSnsService.sendPushMessage(self.pushAndroidService, PushPlatform.GCM, targetEndpointArn, push_message,
None)
849 print "Super-Gluu. Send Android SNS push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
850 elif self.pushGluuMode:
851 send_notification_result = self.pushAndroidService.sendNotification(self.pushAndroidServiceAuth, targetEndpointArn, push_message)
853 print "Super-Gluu. Send Android Gluu push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
855 msgBuilder = Message.Builder().addData(
"message", super_gluu_request).addData(
"title", title).collapseKey(
"single").contentAvailable(
True)
856 push_message = msgBuilder.build()
858 send_notification_result = self.pushAndroidService.send(push_message, push_token, 3)
860 print "Super-Gluu. Send Android Native push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
861 send_android = send_android + 1
863 print "Super-Gluu. Send push notification. send_android: '%s', send_ios: '%s'" % (send_android, send_ios)