From a9178d497bc8d242ee9e1902ca142f63b13638a0 Mon Sep 17 00:00:00 2001 From: Guus der Kinderen Date: Thu, 31 Aug 2023 17:49:25 +0200 Subject: [PATCH] fixes #34: Openfire 4.8.0 compatibility Replaced all usage of code removed or deprecated in Openfire 4.8.0 --- pom.xml | 2 +- src/changelog.html | 1 + .../plugins/pushnotification/Push0IQHandler.java | 4 ++-- .../plugins/pushnotification/PushInterceptor.java | 13 ++++++------- 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 22e859f..09a5196 100644 --- a/pom.xml +++ b/pom.xml @@ -7,7 +7,7 @@ plugins org.igniterealtime.openfire - 4.6.4 + 4.7.5 org.igniterealtime.openfire.plugins diff --git a/src/changelog.html b/src/changelog.html index bd5a6ff..aaca94b 100644 --- a/src/changelog.html +++ b/src/changelog.html @@ -47,6 +47,7 @@

1.0.0 -- (tbd)

0.9.3 -- August 31, 2023

diff --git a/src/main/java/org/igniterealtime/openfire/plugins/pushnotification/Push0IQHandler.java b/src/main/java/org/igniterealtime/openfire/plugins/pushnotification/Push0IQHandler.java index 7141258..3033908 100644 --- a/src/main/java/org/igniterealtime/openfire/plugins/pushnotification/Push0IQHandler.java +++ b/src/main/java/org/igniterealtime/openfire/plugins/pushnotification/Push0IQHandler.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2019-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -105,7 +105,7 @@ public IQ handleIQ( final IQ packet ) throws UnauthorizedException return result; } - if ( !XMPPServer.getInstance().getUserManager().isRegisteredUser( packet.getFrom() ) ) + if ( !XMPPServer.getInstance().getUserManager().isRegisteredUser( packet.getFrom(), false ) ) { Log.info( "Denying service for an entity that's not recognized as a registered user: {}", packet.getFrom() ); throw new UnauthorizedException( "This service is only available to registered, local users." ); diff --git a/src/main/java/org/igniterealtime/openfire/plugins/pushnotification/PushInterceptor.java b/src/main/java/org/igniterealtime/openfire/plugins/pushnotification/PushInterceptor.java index 20f0e51..2ff03b6 100644 --- a/src/main/java/org/igniterealtime/openfire/plugins/pushnotification/PushInterceptor.java +++ b/src/main/java/org/igniterealtime/openfire/plugins/pushnotification/PushInterceptor.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2019 Ignite Realtime Foundation. All rights reserved. + * Copyright (C) 2019-2023 Ignite Realtime Foundation. All rights reserved. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,6 @@ import org.jivesoftware.openfire.session.Session; import org.jivesoftware.openfire.user.User; import org.jivesoftware.openfire.user.UserNotFoundException; -import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.SystemProperty; import org.jivesoftware.util.cache.Cache; import org.jivesoftware.util.cache.CacheFactory; @@ -197,7 +196,7 @@ private void tryPushNotification( User user, Message message ) } // Basic throttling. - final Lock lock = CacheFactory.getLock(user.getUsername(), MESSAGES_BY_USER); + final Lock lock = MESSAGES_BY_USER.getLock(user.getUsername()); lock.lock(); try { if ( wasPushAttemptedFor( user, message, Duration.ofMinutes(5)) ) { @@ -326,7 +325,7 @@ public boolean wasPushAttemptedFor( final User user, final Message message, fina { final String identifier = getMessageIdentifier(user, message); - final Lock lock = CacheFactory.getLock(user.getUsername(), MESSAGES_BY_USER); + final Lock lock = MESSAGES_BY_USER.getLock(user.getUsername()); lock.lock(); try { /* This can be short-circuited, as the same identifier is used in the secondary cache. @@ -359,7 +358,7 @@ public boolean wasPushAttemptedFor( final User user, final Message message, fina */ public long attemptsForLast( final User user, final Duration duration ) { - final Lock lock = CacheFactory.getLock(user.getUsername(), MESSAGES_BY_USER); + final Lock lock = MESSAGES_BY_USER.getLock(user.getUsername()); lock.lock(); try { final HashSet messageIdentifiers = MESSAGES_BY_USER.get(user.getUsername()); @@ -390,7 +389,7 @@ public void addAttemptFor( final User user, final Message message ) { final String identifier = getMessageIdentifier(user, message); - final Lock lock = CacheFactory.getLock(user.getUsername(), MESSAGES_BY_USER); + final Lock lock = MESSAGES_BY_USER.getLock(user.getUsername()); lock.lock(); try { HashSet messageIdentifiers = MESSAGES_BY_USER.get(user.getUsername()); @@ -426,7 +425,7 @@ public void purgeAllOlderThan(final Instant cutoff) // Iterate over all message identifiers for each user, to be able to apply the required user-specific lock. for ( final String username : userNames ) { - final Lock lock = CacheFactory.getLock(username, MESSAGES_BY_USER); + final Lock lock = MESSAGES_BY_USER.getLock(username); lock.lock(); try {