Skip to content

Commit bbd0566

Browse files
fabiomontefuscologuusdk
authored andcommitted
Add OpenFire plugin to authenticate users against a token generated by TikiWiki CMS
1 parent 5dcd759 commit bbd0566

File tree

12 files changed

+532
-0
lines changed

12 files changed

+532
-0
lines changed

src/plugins/tikitoken/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Openfire TikiToken plugin
2+
3+
This project is a plugin for the [Openfire Realtime Collaboration Server](http://www.igniterealtime.org/projects/openfire/).
4+
5+
This plugin adds a SASL mechanism that allows users to authenticate against a token that is generated by an instance of [Tiki Wiki CMS GroupWare](https://tiki.org/).
6+
7+
## Building the source
8+
To create an Openfire plugin from the source code in this project:
9+
10+
- Download a copy of the sources of this project into `PLUGINDIR`
11+
- Download a copy of the [Openfire sources](https://github.com/igniterealtime/Openfire) into `OPENFIRE_SOURCE_DIR`
12+
- From within `OPENFIRE_SOURCE_DIR` execute: `ant -f build/build.xml -Dplugin.src.dir=PLUGINDIR/.. -Dplugin=tikitoken openfire plugin`
13+
14+
## Installing the plugin
15+
16+
After a plugin JAR file has been created, place that file in the plugin directory of a running Openfire instance.
17+
Openfire will automatically detect and activate the plugin.
18+
19+
More detailed usage instructions are available in the [readme](readme.html) file that is available as part of the source
20+
code of this project.

src/plugins/tikitoken/changelog.html

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2+
3+
<html>
4+
<head>
5+
<title>TikiToken Plugin Changelog</title>
6+
<style type="text/css">
7+
BODY {
8+
font-size : 100%;
9+
}
10+
BODY, TD, TH {
11+
font-family : tahoma, verdana, arial, helvetica, sans-serif;
12+
font-size : 0.8em;
13+
}
14+
H2 {
15+
font-size : 10pt;
16+
font-weight : bold;
17+
}
18+
A:hover {
19+
text-decoration : none;
20+
}
21+
H1 {
22+
font-family : tahoma, arial, helvetica, sans-serif;
23+
font-size : 1.4em;
24+
font-weight: bold;
25+
border-bottom : 1px #ccc solid;
26+
padding-bottom : 2px;
27+
}
28+
TT {
29+
font-family : courier new;
30+
font-weight : bold;
31+
color : #060;
32+
}
33+
PRE {
34+
font-family : courier new;
35+
font-size : 100%;
36+
}
37+
</style>
38+
</head>
39+
<body>
40+
41+
<h1>TikiToken Plugin Changelog</h1>
42+
43+
<p><b>0.2</b> -- March 21, 2017</p>
44+
<ul>
45+
<li>Replaced AuthProvider-based approach by a SASL mechanism-based approach.</li>
46+
</ul>
47+
48+
<p><b>0.1</b> -- March 19, 2017</p>
49+
<ul>
50+
<li>Initial release</li>
51+
</ul>
52+
53+
</body>
54+
</html>
377 KB
Binary file not shown.

src/plugins/tikitoken/logo_large.png

4.14 KB
Loading

src/plugins/tikitoken/logo_small.png

1.12 KB
Loading

src/plugins/tikitoken/plugin.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<plugin>
2+
<class>org.tiki.tikitoken.TikiTokenPlugin</class>
3+
<name>TikiToken</name>
4+
<description>Allows users to authenticate with a Tiki token.</description>
5+
<author>Tiki Wiki CMS GroupWare</author>
6+
<version>0.2</version>
7+
<date>04/24/2017</date>
8+
<url>https://dev.tiki.org/OpenFire</url>
9+
<minServerVersion>4.1.3</minServerVersion>
10+
<licenseType>gpl</licenseType>
11+
</plugin>

src/plugins/tikitoken/readme.html

Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2+
3+
<html>
4+
<head>
5+
<title>TikiToken Plugin Readme</title>
6+
<style type="text/css">
7+
BODY {
8+
font-size : 100%;
9+
}
10+
11+
BODY, TD, TH {
12+
font-family : tahoma, verdana, arial, helvetica, sans-serif;
13+
font-size : 0.8em;
14+
}
15+
16+
H2 {
17+
font-size : 10pt;
18+
font-weight : bold;
19+
}
20+
21+
A:hover {
22+
text-decoration : none;
23+
}
24+
25+
H1 {
26+
font-family : tahoma, arial, helvetica, sans-serif;
27+
font-size : 1.4em;
28+
font-weight: bold;
29+
border-bottom : 1px #ccc solid;
30+
padding-bottom : 2px;
31+
}
32+
33+
TT {
34+
font-family : courier new;
35+
font-weight : bold;
36+
color : #060;
37+
}
38+
39+
PRE {
40+
font-family : courier new;
41+
font-size : 100%;
42+
}
43+
</style>
44+
</head>
45+
<body>
46+
47+
<h1>
48+
TikiToken Plugin Readme
49+
</h1>
50+
51+
<h2>Overview</h2>
52+
<p>
53+
This plugin adds a SASL mechanism to Openfire that allows users to authenticate with a Tiki-generated access token.
54+
</p>
55+
56+
<h2>Installation</h2>
57+
<p>
58+
Copy the plugin JAR file into the plugins directory of your Openfire installation. The plugin will then be
59+
automatically deployed.
60+
</p>
61+
62+
<h2>Upgrade</h2>
63+
<p>
64+
To upgrade to a new version, copy the new plugin JAR file into the plugins directory of your Openfire installation,
65+
overwriting the JAR file from the previous version. Within a minute or so, Openfire will detect the new plugin,
66+
unload the previous version and load the new version. You can verify that the new version has been loaded by
67+
observing the plugin version number in the Openfire Admin Console.
68+
</p>
69+
70+
<h2>Configuration</h2>
71+
<p>
72+
The base URL of the Tiki suite against which authentication is performed needs to be defined in a property named
73+
<tt>org.tiki.tikitoken.baseUrl</tt>
74+
</p>
75+
76+
</body>
77+
</html>
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package org.tiki.tikitoken;
2+
3+
import org.jivesoftware.openfire.container.Plugin;
4+
import org.jivesoftware.openfire.container.PluginManager;
5+
import org.jivesoftware.openfire.net.SASLAuthentication;
6+
7+
import java.io.File;
8+
import java.security.Security;
9+
10+
/**
11+
* An Openfire plugin that adds the TikiToken SASL mechanism.
12+
*/
13+
public class TikiTokenPlugin implements Plugin
14+
{
15+
@Override
16+
public void initializePlugin( PluginManager manager, File pluginDirectory )
17+
{
18+
Security.addProvider( new TikiTokenSaslProvider() );
19+
SASLAuthentication.addSupportedMechanism( TikiTokenSaslServer.MECHANISM_NAME );
20+
}
21+
22+
@Override
23+
public void destroyPlugin()
24+
{
25+
SASLAuthentication.removeSupportedMechanism( TikiTokenSaslServer.MECHANISM_NAME );
26+
Security.removeProvider( TikiTokenSaslProvider.NAME );
27+
}
28+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package org.tiki.tikitoken;
2+
3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
import java.net.MalformedURLException;
6+
import java.net.URISyntaxException;
7+
import java.net.URL;
8+
import java.util.Map;
9+
import java.util.Scanner;
10+
11+
import org.jivesoftware.util.JiveGlobals;
12+
13+
import com.owlike.genson.Genson;
14+
15+
16+
public class TikiTokenQuery {
17+
private final String DEFAULT_BASE_URL = "http://tikiconverse.docker/";
18+
private String username;
19+
private String token;
20+
21+
public TikiTokenQuery(String username, String token) {
22+
this.username = username;
23+
this.token = token;
24+
}
25+
26+
public URL getUrl() throws MalformedURLException, URISyntaxException {
27+
String baseAddress = JiveGlobals.getProperty("org.tiki.tikitoken.baseUrl", this.DEFAULT_BASE_URL);
28+
String script = String.format("tiki-ajax_services.php?controller=xmpp&action=check_token&user=%s&token=%s", this.username, this.token);
29+
30+
URL baseUrl = new URL(baseAddress);
31+
URL fullUrl = new URL(baseUrl, script);
32+
33+
return fullUrl;
34+
35+
}
36+
37+
public boolean isValid() {
38+
String content = this.fetch();
39+
Genson genson = new Genson();
40+
Map<String, Boolean> root = genson.deserialize(content, Map.class);
41+
return root.get("valid");
42+
}
43+
44+
public String fetch() {
45+
try {
46+
URL url = this.getUrl();
47+
InputStream stream = url.openStream();
48+
Scanner s = new java.util.Scanner( stream ).useDelimiter( "\\A" );
49+
String result = s.hasNext() ? s.next() : "";
50+
s.close();
51+
return result;
52+
} catch (IOException | URISyntaxException e) {
53+
e.printStackTrace();
54+
}
55+
return null;
56+
}
57+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
package org.tiki.tikitoken;
2+
3+
import java.security.Provider;
4+
5+
/**
6+
* A Provider implementation for a SASL mechanism that uses a Tiki token.
7+
*
8+
* This implementation makes use of a Tiki server for token validation.
9+
*
10+
* @see <a href="https://tools.ietf.org/html/rfc7628">RFC 7628</a>
11+
*/
12+
public class TikiTokenSaslProvider extends Provider
13+
{
14+
/**
15+
* The provider name.
16+
*/
17+
public static final String NAME = "TikiSasl";
18+
19+
/**
20+
* The provider version number.
21+
*/
22+
public static final double VERSION = 1.0;
23+
24+
/**
25+
* A description of the provider and its services.
26+
*/
27+
public static final String INFO = "Provides a SASL mechanism that uses a Tiki instance to verify authentication tokens.";
28+
29+
public TikiTokenSaslProvider()
30+
{
31+
super( NAME, VERSION, INFO );
32+
33+
put( "SaslServerFactory." + TikiTokenSaslServer.MECHANISM_NAME, TikiTokenSaslServerFactory.class.getCanonicalName() );
34+
}
35+
}

0 commit comments

Comments
 (0)