blob: 19135aec9aec599124fe17cdb71eb31df0dd851c [file] [log] [blame]
<!DOCTYPE html>
<html lang="en">
<head>
<title>Vysper User Management &mdash; Apache MINA</title>
<link href="/assets/css/common.css" rel="stylesheet" type="text/css"/>
<link href="/assets/css/vysper.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<script src="https://www.apachecon.com/event-images/snippet.js"></script>
<div id="container">
<div id="header">
<div id="subProjectsNavBar">
<a href="/">
Apache MINA Project
</a>
&nbsp;|&nbsp;
<a href="/mina-project/">
MINA
</a>
&nbsp;|&nbsp;
<a href="/asyncweb-project/">
AsyncWeb
</a>
&nbsp;|&nbsp;
<a href="/ftpserver-project/">
FtpServer
</a>
&nbsp;|&nbsp;
<a href="/sshd-project/">
SSHD
</a>
&nbsp;|&nbsp;
<a href="/vysper-project/">
<strong>Vysper</strong>
</a>
</div>
</div>
<div id="content">
<div id="leftColumn">
<div id="navigation">
<a class="acevent" data-format="wide" data-width="170"></a>
<h5>Social Networks</h5>
<ul>
<li><a href="https://fosstodon.org/@apachemina">Apache MINA Mastodon</a></li>
</ul>
<h5>Overview</h5>
<ul>
<li><a href="/vysper-project/index.html">Home</a> </li>
<li><a href="/vysper-project/documentation.html">Documentation</a></li>
<li><a href="/vysper-project/downloads.html">Downloads</a></li>
<li><a href="/vysper-project/sources.html">Source</a></li>
</ul>
<h5>Community</h5>
<ul>
<li><a href="/vysper-project/mailing_lists.html">Mailing Lists</a></li>
<li><a href="/vysper-project/getting_involved.html">Getting Involved</a></li>
<li><a href="/vysper-project/issue_tracking.html">Issue Tracking</a></li>
<li><a href="https://www.apache.org/foundation/contributing.html">Contributing</a></li>
<li><a href="https://www.apache.org/licenses/">License</a></li>
<li><a href="https://www.apache.org/security/">Security</a></li>
</ul>
<h5>Sponsorship</h5>
<ul>
<li><a href="https://www.apache.org/foundation/thanks.html">Thanks</a></li>
<li><a href="https://www.apache.org/foundation/sponsorship.html">Sponsorship</a></li>
<li><a href="https://www.apache.org/">apache.org</a></li>
</ul>
</div>
</div>
<div id="rightColumn">
<h1 id="user-management">User Management</h1>
<p>Apache Vysper comes with very basic user management support out of the box. But, frequently you would rather want to integrate Vysper with your already existing authentication solution. To enable this, Vysper comes with a simple API to implement your own authentication and user management.</p>
<h2 id="authentication">Authentication</h2>
<p>UserAuthentication is the interface which will get called when a client authenticates itself using SASL. Vysper currently ships with two implementations, one in-memory and one based on JCR. To write your own, simple create a class which implements UserAuthentication. In the example below, we implement an authentication provider backed by an LDAP directory.</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">class</span> <span style="color:#00f">MyLdapAuthentication</span> <span style="color:#a2f;font-weight:bold">implements</span> UserAuthentication <span style="color:#666">{</span>
<span style="color:#a2f">@Override</span>
<span style="color:#a2f;font-weight:bold">public</span> <span style="color:#0b0;font-weight:bold">boolean</span> <span style="color:#00a000">verifyCredentials</span><span style="color:#666">(</span>Entity jid<span style="color:#666">,</span> String passwordCleartext<span style="color:#666">,</span> Object credentials<span style="color:#666">)</span> <span style="color:#666">{</span>
Hashtable<span style="color:#666">&lt;</span>String<span style="color:#666">,</span> String<span style="color:#666">&gt;</span> env <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> Hashtable<span style="color:#666">&lt;</span>String<span style="color:#666">,</span> String<span style="color:#666">&gt;</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
env<span style="color:#666">.</span><span style="color:#b44">put</span><span style="color:#666">(</span>Context<span style="color:#666">.</span><span style="color:#b44">INITIAL_CONTEXT_FACTORY</span><span style="color:#666">,</span> <span style="color:#b44">&#34;com.sun.jndi.ldap.LdapCtxFactory&#34;</span><span style="color:#666">)</span><span style="color:#666">;</span>
env<span style="color:#666">.</span><span style="color:#b44">put</span><span style="color:#666">(</span>Context<span style="color:#666">.</span><span style="color:#b44">PROVIDER_URL</span><span style="color:#666">,</span> <span style="color:#b44">&#34;ldap://localhost:389/&#34;</span><span style="color:#666">)</span><span style="color:#666">;</span>
env<span style="color:#666">.</span><span style="color:#b44">put</span><span style="color:#666">(</span>Context<span style="color:#666">.</span><span style="color:#b44">SECURITY_AUTHENTICATION</span><span style="color:#666">,</span> <span style="color:#b44">&#34;simple&#34;</span><span style="color:#666">)</span><span style="color:#666">;</span>
<span style="color:#080;font-style:italic">// extract the user name from the entity, e.g. from foo@example.com, foo will be used
</span><span style="color:#080;font-style:italic"></span> env<span style="color:#666">.</span><span style="color:#b44">put</span><span style="color:#666">(</span>Context<span style="color:#666">.</span><span style="color:#b44">SECURITY_PRINCIPAL</span><span style="color:#666">,</span> String<span style="color:#666">.</span><span style="color:#b44">format</span><span style="color:#666">(</span><span style="color:#b44">&#34;cn=%s, ou=Users, o=Acme&#34;</span><span style="color:#666">,</span> jid<span style="color:#666">.</span><span style="color:#b44">getNode</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
env<span style="color:#666">.</span><span style="color:#b44">put</span><span style="color:#666">(</span>Context<span style="color:#666">.</span><span style="color:#b44">SECURITY_CREDENTIALS</span><span style="color:#666">,</span> passwordCleartext<span style="color:#666">)</span><span style="color:#666">;</span>
<span style="color:#a2f;font-weight:bold">try</span> <span style="color:#666">{</span>
<span style="color:#080;font-style:italic">// connect and authenticate with the directory
</span><span style="color:#080;font-style:italic"></span> <span style="color:#a2f;font-weight:bold">new</span> InitialDirContext<span style="color:#666">(</span>env<span style="color:#666">)</span><span style="color:#666">;</span>
<span style="color:#a2f;font-weight:bold">return</span> <span style="color:#a2f;font-weight:bold">true</span><span style="color:#666">;</span>
<span style="color:#666">}</span> <span style="color:#a2f;font-weight:bold">catch</span> <span style="color:#666">(</span>NamingException e<span style="color:#666">)</span> <span style="color:#666">{</span>
<span style="color:#a2f;font-weight:bold">return</span> <span style="color:#a2f;font-weight:bold">false</span><span style="color:#666">;</span>
<span style="color:#666">}</span>
<span style="color:#666">}</span>
<span style="color:#666">}</span>
</code></pre></div><p>Next, you need to hook the authentication provider into the Vysper XMPP server:</p>
<div class="highlight"><pre style="background-color:#f8f8f8;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-java" data-lang="java"><span style="color:#a2f;font-weight:bold">public</span> <span style="color:#a2f;font-weight:bold">static</span> <span style="color:#0b0;font-weight:bold">void</span> <span style="color:#00a000">main</span><span style="color:#666">(</span>String<span style="color:#666">[</span><span style="color:#666">]</span> args<span style="color:#666">)</span> <span style="color:#a2f;font-weight:bold">throws</span> Exception <span style="color:#666">{</span>
OpenStorageProviderRegistry providerRegistry <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> OpenStorageProviderRegistry<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
<span style="color:#080;font-style:italic">// add your custom authentication provider
</span><span style="color:#080;font-style:italic"></span> providerRegistry<span style="color:#666">.</span><span style="color:#b44">add</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> MyLdapAuthentication<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
<span style="color:#080;font-style:italic">// a roster manager is also required
</span><span style="color:#080;font-style:italic"></span> providerRegistry<span style="color:#666">.</span><span style="color:#b44">add</span><span style="color:#666">(</span><span style="color:#a2f;font-weight:bold">new</span> MemoryRosterManager<span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">)</span><span style="color:#666">;</span>
XMPPServer server <span style="color:#666">=</span> <span style="color:#a2f;font-weight:bold">new</span> XMPPServer<span style="color:#666">(</span><span style="color:#b44">&#34;acme.com&#34;</span><span style="color:#666">)</span><span style="color:#666">;</span>
<span style="color:#080;font-style:italic">// other initialization
</span><span style="color:#080;font-style:italic"></span> <span style="color:#080;font-style:italic">// ...
</span><span style="color:#080;font-style:italic"></span>
server<span style="color:#666">.</span><span style="color:#b44">setStorageProviderRegistry</span><span style="color:#666">(</span>providerRegistry<span style="color:#666">)</span><span style="color:#666">;</span>
server<span style="color:#666">.</span><span style="color:#b44">start</span><span style="color:#666">(</span><span style="color:#666">)</span><span style="color:#666">;</span>
<span style="color:#666">}</span>
</code></pre></div><p>In this example, we use the OpenStorageProviderRegistry to provide the different storage providers. Only two are required, UserAuthentication and RosterManager.</p>
<p>That&rsquo;s all that&rsquo;s needed to implement a custom authentication provider.</p>
<h2 id="user-management-1">User management</h2>
<p>Some Vysper modules, in particular in-band registration and service administration, requires the ability to add users and change users password. For that, Vysper uses the interface AccountManagement. This interface has three methods:</p>
<ul>
<li>addUser(username, password): to add a new user</li>
<li>changePassword(username, newPassword): to change the password of a user</li>
<li>verifyAccountExists(username): checks if a user exists</li>
</ul>
<p>If you need to make use of any of these modules, provide an AccountManagement implementation in OpenStorageProviderRegistry as in the example above.</p>
</div>
<div id="endContent"></div>
</div>
<div id="footer">
&copy; 2003-2024, <a href="https://www.apache.org">The Apache Software Foundation</a> - <a href="https://privacy.apache.org/policies/privacy-policy-public.html">Privacy Policy</a><br />
Apache MINA, MINA, Apache Vysper, Vysper, Apache SSHd, SSHd, Apache FtpServer, FtpServer, Apache AsyncWeb, AsyncWeb,
Apache, the Apache feather logo, and the Apache Mina project logos are trademarks of The Apache Software Foundation.
</div>
</div>
</body>
</html>