Skip to content

Commit 1185d7f

Browse files
authored
Merge pull request #24 from guusdk/20_Openfire-4.9.0-compat
Openfire 4.9.0 compatibility & admin console page fixes
2 parents 1c13e6d + caa4220 commit 1185d7f

File tree

10 files changed

+579
-619
lines changed

10 files changed

+579
-619
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
target
1+
target
2+
.idea

changelog.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,12 @@ <h1>
4444
Bookmarks Plugin Changelog
4545
</h1>
4646

47-
<p><b>1.1.2</b> -- tbd</p>
47+
<p><b>1.2.0</b> -- tbd</p>
4848
<ul>
49+
<li>Now requires Openfire 4.4.0 or later.</li>
50+
<li><a href="https://github.com/igniterealtime/openfire-bookmarks-plugin/issues/20">Issue #20</a>: Fix compatibility with Openfire 4.9.0.</li>
51+
<li><a href="https://github.com/igniterealtime/openfire-bookmarks-plugin/issues/21">Issue #21</a>: Fix visual alignment issue in admin console</li>
52+
<li><a href="https://github.com/igniterealtime/openfire-bookmarks-plugin/issues/22">Issue #22</a>: Guard against Cross Site Scripting</li>
4953
</ul>
5054

5155
<p><b>1.1.1</b> -- October 6, 2022</p>

plugin.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<description>Allows clients to store URL and group chat bookmarks (XEP-0048)</description>
1010
<author>Ignite Realtime</author>
1111
<version>${project.version}</version>
12-
<date>2022-10-06</date>
13-
<minServerVersion>4.0.0</minServerVersion>
12+
<date>2024-08-23</date>
13+
<minServerVersion>4.4.0</minServerVersion>
1414
<minJavaVersion>1.8</minJavaVersion>
1515

1616
<!-- Keep the 'clientcontrol' database key for backwards compatibility. Client control itself does not have any database. -->

pom.xml

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@
44
<parent>
55
<artifactId>plugins</artifactId>
66
<groupId>org.igniterealtime.openfire</groupId>
7-
<version>4.3.0</version>
7+
<version>4.4.0</version>
88
</parent>
99
<groupId>org.igniterealtime.openfire.plugins</groupId>
1010
<artifactId>bookmarks</artifactId>
11-
<version>1.1.2-SNAPSHOT</version>
11+
<version>1.2.0-SNAPSHOT</version>
1212
<name>Bookmarks Plugin</name>
1313
<description>Allows clients to store URL and group chat bookmarks (XEP-0048)</description>
1414

@@ -21,8 +21,6 @@
2121
<plugin>
2222
<groupId>org.eclipse.jetty</groupId>
2323
<artifactId>jetty-jspc-maven-plugin</artifactId>
24-
<!-- Force the Openfire 4.2.x compatible version of JSP -->
25-
<version>9.2.14.v20151106</version>
2624
<dependencies>
2725
<dependency>
2826
<groupId>org.igniterealtime.openfire</groupId>
@@ -32,26 +30,26 @@
3230
<dependency>
3331
<groupId>org.apache.commons</groupId>
3432
<artifactId>commons-lang3</artifactId>
35-
<version>3.11</version>
36-
</dependency>
33+
<version>3.11</version>
34+
</dependency>
3735
</dependencies>
3836
</plugin>
3937
</plugins>
4038
</build>
41-
<dependencies>
42-
<!-- API, java.xml.bind module -->
43-
<dependency>
44-
<groupId>javax.xml.bind</groupId>
45-
<artifactId>jaxb-api</artifactId>
46-
<version>2.3.1</version>
47-
</dependency>
48-
<!-- Runtime, com.sun.xml.bind module -->
49-
<dependency>
50-
<groupId>org.glassfish.jaxb</groupId>
51-
<artifactId>jaxb-runtime</artifactId>
52-
<version>2.3.2</version>
53-
</dependency>
54-
</dependencies>
39+
<dependencies>
40+
<!-- API, java.xml.bind module -->
41+
<dependency>
42+
<groupId>javax.xml.bind</groupId>
43+
<artifactId>jaxb-api</artifactId>
44+
<version>2.3.1</version>
45+
</dependency>
46+
<!-- Runtime, com.sun.xml.bind module -->
47+
<dependency>
48+
<groupId>org.glassfish.jaxb</groupId>
49+
<artifactId>jaxb-runtime</artifactId>
50+
<version>2.3.2</version>
51+
</dependency>
52+
</dependencies>
5553

5654
<distributionManagement>
5755
<!-- Repository in which we deploy this project, when desired. -->
Lines changed: 28 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,30 @@
1+
/**
2+
* Copyright (C) 2016-2024 Ignite Realtime Foundation. All rights reserved.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
116
package org.igniterealtime.openfire.plugin;
217

3-
import org.dom4j.Document;
4-
import org.dom4j.DocumentException;
5-
import org.dom4j.Element;
6-
import org.dom4j.io.SAXReader;
718
import org.jivesoftware.openfire.container.Plugin;
819
import org.jivesoftware.openfire.container.PluginManager;
20+
import org.jivesoftware.openfire.container.PluginMetadataHelper;
921
import org.jivesoftware.openfire.plugin.spark.BookmarkInterceptor;
10-
import org.jivesoftware.util.JiveGlobals;
1122
import org.jivesoftware.util.Version;
1223
import org.slf4j.Logger;
1324
import org.slf4j.LoggerFactory;
1425

26+
import javax.annotation.Nonnull;
1527
import java.io.*;
16-
import java.util.jar.JarFile;
17-
import java.util.zip.ZipEntry;
1828

1929
/**
2030
* A plugin that implements XEP-0048 "Bookmarks".
@@ -34,14 +44,14 @@ public void initializePlugin( PluginManager manager, File pluginDirectory )
3444
try
3545
{
3646
// Check if we Enterprise is installed and stop loading this plugin if found
37-
if ( checkForEnterprisePlugin() )
47+
if ( checkForEnterprisePlugin(manager) )
3848
{
3949
System.out.println( "Enterprise plugin found. Stopping Bookmarks Plugin." );
4050
foundIncompatiblePlugin = true;
4151
}
4252

4353
// Check if we ClientControl (version <= 1.3.1) is installed and stop loading this plugin if found
44-
if ( checkForIncompatibleClientControlPlugin() )
54+
if ( checkForIncompatibleClientControlPlugin(manager) )
4555
{
4656
System.out.println( "ClientControl plugin v1.3.1 or earlier found. Stopping Bookmarks Plugin." );
4757
foundIncompatiblePlugin = true;
@@ -75,83 +85,29 @@ public void destroyPlugin()
7585
/**
7686
* Checks if there's a plugin named "enterprise" in the Openfire plugin directory.
7787
*
88+
* @param manager The Openfire plugin manager
7889
* @return true if the enterprise plugin is found, otherwise false.
7990
*/
80-
private static boolean checkForEnterprisePlugin() throws IOException
91+
private static boolean checkForEnterprisePlugin(@Nonnull final PluginManager manager)
8192
{
82-
return getPluginJar( "enterprise" ) != null;
93+
return manager.getPluginByName("enterprise").isPresent();
8394
}
8495

8596
/**
8697
* Checks if there's a plugin named "clientControl" in the Openfire plugin directory of which the version is equal
8798
* to or earlier than 1.3.1.
8899
*
100+
* @param manager The Openfire plugin manager
89101
* @return true if the clientControl plugin (<= 1.3.1) is found, otherwise false.
90102
*/
91-
private static boolean checkForIncompatibleClientControlPlugin() throws IOException, DocumentException
103+
private static boolean checkForIncompatibleClientControlPlugin(@Nonnull final PluginManager manager)
92104
{
93-
final JarFile jar = getPluginJar( "clientControl" );
94-
95-
if ( jar == null )
96-
{
97-
return false;
98-
}
99-
100-
final ZipEntry pluginXml = jar.getEntry( "plugin.xml" );
101-
if ( pluginXml == null )
102-
{
103-
// Odd - not a plugin?
104-
Log.warn( "Found a clientControl.jar file that does not appear to include a plugin.xml.", jar.getName() );
105+
final Plugin clientControlPlugin = manager.getPluginByName("clientControl").orElse(null);
106+
if (clientControlPlugin == null) {
105107
return false;
106108
}
107109

108-
final File tempFile = File.createTempFile( "plugin-xml", "xml" );
109-
try ( final InputStream is = jar.getInputStream( pluginXml );
110-
final FileOutputStream os = new FileOutputStream( tempFile ) )
111-
{
112-
while ( is.available() > 0 )
113-
{
114-
os.write( is.read() );
115-
}
116-
117-
final SAXReader saxReader = new SAXReader();
118-
saxReader.setEncoding( "UTF-8" );
119-
final Document pluginXML = saxReader.read( tempFile );
120-
Element element = (Element) pluginXML.selectSingleNode( "/plugin/version" );
121-
if ( element != null )
122-
{
123-
final Version version = new Version( element.getTextTrim() );
124-
return !version.isNewerThan( new Version( "1.3.1" ) );
125-
}
126-
}
127-
return false;
128-
}
129-
130-
/**
131-
* Returns the plugin JAR for the plugin of the provided name.
132-
*
133-
* @param pluginName the name of the plugin (cannot be null or empty).
134-
* @return The plugin JAR file, or null when not found.
135-
*/
136-
private static JarFile getPluginJar( final String pluginName ) throws IOException
137-
{
138-
File pluginDir = new File( JiveGlobals.getHomeDirectory(), "plugins" );
139-
File[] jars = pluginDir.listFiles( new FileFilter()
140-
{
141-
public boolean accept( File pathname )
142-
{
143-
return pathname.getName().equalsIgnoreCase( pluginName + ".jar" );
144-
}
145-
} );
146-
147-
final File jar;
148-
if ( jars.length > 0 )
149-
{
150-
return new JarFile( jars[ 0 ] );
151-
}
152-
else
153-
{
154-
return null;
155-
}
110+
final Version version = PluginMetadataHelper.getVersion(clientControlPlugin);
111+
return !version.isNewerThan( new Version( "1.3.1" ) );
156112
}
157113
}

src/java/org/jivesoftware/openfire/plugin/spark/Bookmark.java

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
/**
2-
* $Revision: 3034 $
3-
* $Date: 2005-11-04 21:02:33 -0300 (Fri, 04 Nov 2005) $
4-
*
5-
* Copyright (C) 2006-2008 Jive Software. All rights reserved.
2+
* Copyright (C) 2006-2008 Jive Software. 2016-2024 Ignite Realtime Foundation. All rights reserved.
63
*
74
* Licensed under the Apache License, Version 2.0 (the "License");
85
* you may not use this file except in compliance with the License.
@@ -402,6 +399,42 @@ public void setProperty(String name, String value)
402399
}
403400
}
404401

402+
/**
403+
* A short-cut method for checking if a property of name 'autojoin' is set to 'true'.
404+
*
405+
* @return if the 'autojoin' property is set to 'true'
406+
*/
407+
public boolean isAutojoin() {
408+
return getProperty("autojoin") != null && getProperty("autojoin").equals("true");
409+
}
410+
411+
/**
412+
* A short-cut method for checking if a property of name 'nameasnick' is set to 'true'.
413+
*
414+
* @return if the 'nameasnick' property is set to 'true'
415+
*/
416+
public boolean isNameAsNick() {
417+
return getProperty("nameasnick") != null && getProperty("nameasnick").equals("true");
418+
}
419+
420+
/**
421+
* A short-cut method for checking if a property of name 'rss' is set to 'true'.
422+
*
423+
* @return if the 'nameasnick' property is set to 'true'
424+
*/
425+
public boolean isRss() {
426+
return getProperty("rss") != null && getProperty("rss").equals("true");
427+
}
428+
429+
/**
430+
* A short-cut method for getting the value of the property with name 'avatar_uri'.
431+
*
432+
* @return the 'avatar_uri' property value
433+
*/
434+
public String getAvatarUri() {
435+
return getProperty("avatar_uri");
436+
}
437+
405438
/**
406439
* Deletes an extended property. If the property specified by
407440
* <code>name</code> does not exist, this method will do nothing.
@@ -431,6 +464,18 @@ public Iterator<String> getPropertyNames() {
431464
return Collections.unmodifiableSet(properties.keySet()).iterator();
432465
}
433466

467+
/**
468+
* Returns an unmodifiable copy of the extended properties.
469+
*
470+
* @return the extended properties.
471+
*/
472+
public Map<String, String> getProperties() {
473+
if (properties == null) {
474+
loadPropertiesFromDb();
475+
}
476+
return Collections.unmodifiableMap(properties);
477+
}
478+
434479
/**
435480
* Tye type of the bookmark.
436481
*/

0 commit comments

Comments
 (0)