768 def sendPushNotificationImpl(self, client_redirect_uri, user, super_gluu_request):
769 if not self.enabledPushNotifications:
772 user_name = user.getUserId()
773 print "Super-Gluu. Send push notification. Loading user '%s' devices" % user_name
775 send_notification =
False 776 send_notification_result =
True 778 userService = CdiUtil.bean(UserService)
779 deviceRegistrationService = CdiUtil.bean(DeviceRegistrationService)
781 user_inum = userService.getUserInum(user_name)
785 u2f_devices_list = deviceRegistrationService.findUserDeviceRegistrations(user_inum, client_redirect_uri,
"oxId",
"oxDeviceData",
"oxDeviceNotificationConf")
786 if u2f_devices_list.size() > 0:
787 for u2f_device
in u2f_devices_list:
788 device_data = u2f_device.getDeviceData()
791 if device_data ==
None:
794 platform = device_data.getPlatform()
795 push_token = device_data.getPushToken()
798 if StringHelper.equalsIgnoreCase(platform,
"ios")
and StringHelper.isNotEmpty(push_token):
800 if self.pushAppleService ==
None:
801 print "Super-Gluu. Send push notification. Apple native push notification service is not enabled" 803 send_notification =
True 806 message =
"Super-Gluu login request to: %s" % client_redirect_uri
808 if self.pushSnsMode
or self.pushGluuMode:
809 pushSnsService = CdiUtil.bean(PushSnsService)
810 targetEndpointArn = self.getTargetEndpointArn(deviceRegistrationService, pushSnsService, PushPlatform.APNS, user, u2f_device)
811 if targetEndpointArn ==
None:
814 send_notification =
True 816 sns_push_request_dictionary = {
"aps":
818 "alert" : {
"body": message,
"title" : title},
819 "category":
"ACTIONABLE",
820 "content-available":
"1",
823 "request" : super_gluu_request
825 push_message = json.dumps(sns_push_request_dictionary, separators=(
',',
':'))
828 apple_push_platform = PushPlatform.APNS
829 if not self.pushAppleServiceProduction:
830 apple_push_platform = PushPlatform.APNS_SANDBOX
832 send_notification_result = pushSnsService.sendPushMessage(self.pushAppleService, apple_push_platform, targetEndpointArn, push_message,
None)
834 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)
835 elif self.pushGluuMode:
836 send_notification_result = self.pushAppleService.sendNotification(self.pushAppleServiceAuth, targetEndpointArn, push_message)
838 print "Super-Gluu. Send iOS Gluu push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
840 additional_fields = {
"request" : super_gluu_request }
842 msgBuilder = APNS.newPayload().alertBody(message).alertTitle(title).sound(
"default")
843 msgBuilder.category(
'ACTIONABLE').badge(0)
844 msgBuilder.forNewsstand()
845 msgBuilder.customFields(additional_fields)
846 push_message = msgBuilder.build()
848 send_notification_result = self.pushAppleService.push(push_token, push_message)
850 print "Super-Gluu. Send iOS Native push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
851 send_ios = send_ios + 1
853 if StringHelper.equalsIgnoreCase(platform,
"android")
and StringHelper.isNotEmpty(push_token):
855 if self.pushAndroidService ==
None:
856 print "Super-Gluu. Send native push notification. Android native push notification service is not enabled" 858 send_notification =
True 861 if self.pushSnsMode
or self.pushGluuMode:
862 pushSnsService = CdiUtil.bean(PushSnsService)
863 targetEndpointArn = self.getTargetEndpointArn(deviceRegistrationService, pushSnsService, PushPlatform.GCM, user, u2f_device)
864 if targetEndpointArn ==
None:
867 send_notification =
True 869 sns_push_request_dictionary = {
"collapse_key":
"single",
870 "content_available":
True,
873 {
"message" : super_gluu_request,
876 push_message = json.dumps(sns_push_request_dictionary, separators=(
',',
':'))
879 send_notification_result = pushSnsService.sendPushMessage(self.pushAndroidService, PushPlatform.GCM, targetEndpointArn, push_message,
None)
881 print "Super-Gluu. Send Android SNS push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
882 elif self.pushGluuMode:
883 send_notification_result = self.pushAndroidService.sendNotification(self.pushAndroidServiceAuth, targetEndpointArn, push_message)
885 print "Super-Gluu. Send Android Gluu push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
887 msgBuilder = Message.Builder().addData(
"message", super_gluu_request).addData(
"title", title).collapseKey(
"single").contentAvailable(
True)
888 push_message = msgBuilder.build()
890 send_notification_result = self.pushAndroidService.send(push_message, push_token, 3)
892 print "Super-Gluu. Send Android Native push notification. token: '%s', message: '%s', send_notification_result: '%s'" % (push_token, push_message, send_notification_result)
893 send_android = send_android + 1
895 print "Super-Gluu. Send push notification. send_android: '%s', send_ios: '%s'" % (send_android, send_ios)