Show last authors
1 {{box cssClass="floatinginfobox" title="**Contents**"}}
2 {{toc/}}
3 {{/box}}
4
5 XWiki supports several different authentication mechanisms for authenticating users.
6
7 {{info}}
8 XWiki currently allows only one method of authentication to be enabled at a time. This will probably be improved in the future.
9 {{/info}}
10
11 Also note that XWiki requires cookies to be enable in order to track your session and to keep you logged in between pages.
12
13 = Form Authentication =
14
15 Form authentication is the default way to get authenticated within a Wiki. It requires a user and a password.
16
17 = Basic Authentication =
18
19 XWiki supports [[basic access authentication>>https://en.wikipedia.org/wiki/Basic_access_authentication]], a method designed to allow a web browser or other client programs to provide credentials - in the form of a user name and password - when making a request. You can get authenticated against an XWiki server with the basic authentication protocol using the following URL scheme:
20
21 {{code}}
22 https://username:password@mywiki.xwiki.com/xwiki/bin/view/Main/WebHome?basicauth=1
23 {{/code}}
24
25 {{warning}}
26 Be careful that if you use the ##HTTP## protocol your password will be sent in clear over the network and is thus very unsafe. When using basic authentication you should make sure your wiki is configured to use ##HTTPS##.
27 {{/warning}}
28
29 = Container Authentication =
30
31 Delegates authentication to the Servlet Container. If it fails it falls back to the standard XWiki authentication.
32
33 To configure XWiki to use it, specify:
34
35 {{code language="properties"}}
36 xwiki.authentication.authclass=com.xpn.xwiki.user.impl.xwiki.AppServerTrustedAuthServiceImpl
37 {{/code}}
38
39 For users to be actually created and not just set as context user you must set in ##xwiki.cfg## configuration file (if the property does not already exist, create it):
40
41 {{code language="properties"}}
42 xwiki.authentication.createuser=empty
43 {{/code}}
44
45 = Social Login =
46
47 See the [[Social Login Application>>extensions:Extension.Social Login Application]].
48
49 = OpenId Connect Authentication =
50
51 See the [[OpenId Connect Authenticator Extension>>extensions:Extension.OpenID Connect.OpenID Connect Authenticator.WebHome]].
52
53 = Active Directory =
54
55 If you're looking to connect XWiki to an Active Directory server, you currently have 2 options:
56
57 * Using the manual and generic approach using the [[LDAP Authenticator extension>>extensions:Extension.LDAP.Authenticator]]
58 * Using the dedicated [[Active Directory Application>>https://store.xwiki.com/xwiki/bin/view/Extension/ActiveDirectoryApplication]] which is a paying application dedicated to simplifying the integration of Active Directory with XWiki. The Active Directory Application allows you to easily connect your Active Directory server to XWiki using a **visual editor**, update **advanced configuration** settings without restarting the application server, **technical support** provided by [[XWiki SAS>>https://xwiki.com/]], etc.
59
60 = LDAP =
61
62 See the [[LDAP Authenticator extension>>extensions:Extension.LDAP.Authenticator]].
63
64 The deprecated LDAP core authenticator (for XWiki < 7.4) can be found on [[OldLDAPAuthenticator]].
65
66 = Custom Authentication =
67
68 This allows plugging to any existing authentication mechanism such as SiteMinder, etc. To configure a custom authentication do the following:
69
70 * Implement the {{scm path="xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/user/api/XWikiAuthService.java"}}XWikiAuthService{{/scm}} interface.
71 * Edit the //WEB-INF/xwiki.cfg// file and add a //xwiki.authentication.authclass// property pointing to your class. For example:
72
73 {{code language="properties"}}
74 xwiki.authentication.authclass = com.acme.MyCustomAuthenticationService
75 {{/code}}
76
77 * {{version since="13.3RC1"}}To comply with latest best practices, your custom authentication should trigger a {{scm path="xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserAuthenticatedEvent.java"}}UserAuthenticatedEvent{{/scm}} event when user authenticates. You can find implementation examples in {{code}}xwiki-platform-oldcore{{/code}} as {{scm path="xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/user/impl/xwiki/MyFormAuthenticator.java"}}MyFormAuthenticator{{/scm}} and {{scm path="xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/user/impl/xwiki/MyBasicAuthenticator.java"}}MyBasicAuthenticator{{/scm}}. Note that a {{scm path="xwiki-platform-core/xwiki-platform-security/xwiki-platform-security-authentication/xwiki-platform-security-authentication-api/src/main/java/org/xwiki/security/authentication/UserAuthenticatedEvent.java"}}UserAuthenticatedEvent{{/scm}} should be created with a {{scm path="xwiki-platform-core/xwiki-platform-user/xwiki-platform-user-api/src/main/java/org/xwiki/user/UserReference.java"}}UserReference{{/scm}}.{{/version}}
78
79 You can find various authenticators examples in [[sandbox>>https://github.com/xwiki-contrib/sandbox/tree/master/authenticators]] or [[extensions>>http://extensions.xwiki.org/xwiki/bin/view/Main/WebHome#|t=extensions&p=1&l=30&s=doc.creationDate&d=desc&name=authenticator]].
80
81 Here's a [[tutorial on implementing a custom authentication class for authenticating against Oracle's SSO>>http://bodez.wordpress.com/2008/10/15/xwiki-user-authentication-with-oracle-sso/]].
82
83 Note that it's also possible to customize the right management system, see [[extensions:Extension.Security Module]] for more details.
84
85 == Custom Authentication using a Groovy script in a wiki page ==
86
87 Start by specifying you want to use the Groovy Authenticator:
88
89 {{code language="properties"}}
90 xwiki.authentication.authclass = com.xpn.xwiki.user.impl.xwiki.GroovyAuthServiceImpl
91 {{/code}}
92
93 Then add another configuration parameter to specify in which wiki page the authenticator is:
94
95 {{code language="properties"}}
96 xwiki.authentication.groovy.pagename = MySpace.MyPage
97 {{/code}}
98
99 Then put some Groovy code in a wiki page that returns a XWikiAuthService object.
100
101 = Authentication parameters =
102
103 You can set each of these parameters by setting:
104
105 {{code}}
106 xwiki.authentication.<param_name>=<param_value>
107 {{/code}}
108
109 |=Name|=Optional|=Allowed values|=Default value|=Description
110 |encryptionKey|No(1)|?|n/a|Set the Encryption Key used to create a secret key, the secret key is passed to the Cipher object to be used during encryption and decryption of cookie values.
111 |validationKey|No(2)|?|n/a|Set the Validation Key used to generate hash value; the hash value is stored with the cookie and used to verify that the cookie has not been tampered with.
112 |cookiedomains|Yes|String|Server host name|Which host(s) should your cookies be sent to; use only if you want to share cookies across domains, otherwise should be commented out
113 |cookielife|Yes|Number|14|Number of days cookies take to expire
114 |cookiepath|Yes|String|/|The webapp path that XWiki cookies should be sent to; if you have anything else running on your web server, this should be set to ///xwiki//
115 |default_page|Yes|String|/bin/view/ Main/WebHome|Page to redirect to if xredirect parameter is not set
116 |encryptionalgorithm|Yes|?|?|Set the Encryption Algorithm used to encrypt and decrypt cookies
117 |encryptionmode|Yes|?|?|Set the Encryption Mode used to encrypt and decrypt cookies
118 |encryptionpadding|Yes|?|?|Set the Encryption Padding used to encrypt and decrypt cookies
119 |errorpage|Yes|String|/bin/loginerror/ XWiki/XWikiLogin|Page to redirect to if there is an error logging in
120 |loginpage|Yes|String|/bin/login/ XWiki/XWikiLogin|Page to redirect to when not logged in
121 |loginsubmitpage|Yes|String|/loginsubmit/ XWiki/XWikiLogin|The URL where the username and password are posted to when logging in.
122 |logoutpage|Yes|String|/bin/logout/ XWiki/XWikiLogout|Page to redirect to after logged out
123 |realmname|Yes|String|XWiki|Sets the realm name
124 |protection|Yes|all, validation, encryption, none|all|Protection level for the "remember me" cookie functionality
125 |unauthorized_code|Yes|Number|403|The HTTP status code to return when the login has failed.
126 |useip|Yes|true / false|true|Specify to use the IP address when encrypting the cookie data; if IP address changes will need to re-login.
127
128 1. Only required if protection = encryption or all (default)
129 1. Only required if protection = validation or all (default)
130
131 = Kerberos SSO Authentication =
132
133 {{warning}}
134 This implementation of SSO is currently under review see: https://jira.xwiki.org/browse/XWIKI-2496 . The class which is described in this segment of documentation, AppServerTrustedKerberosAuthServiceImpl, is not part of the default XWiki distribution!
135 {{/warning}}
136
137 The following is an example of **mod_auth_kerb** for Apache being used to easily implement XWiki authentication of users via HTTP Negotiate on a linux server. This example assumes you already have a working Apache2 HTTPD and Apache Tomcat setup with mod_jk.
138
139 First of all you need to create a principal and keytab for the webserver:
140
141 {{code}}
142 # kadmin
143 kadmin> addprinc -randkey HTTP/wiki.example.com
144 kadmin> ktadd -k /etc/apache2/ssl/wiki.keytab HTTP/wiki.example.com
145 kadmin> quit
146 {{/code}}
147
148 Make sure the keytab has the right permissions and ownership:
149
150 {{code}}
151 chown www-data:www-data /etc/apache2/ssl/wiki.keytab
152 chmod 400 /etc/apache2/ssl/wiki.keytab
153 {{/code}}
154
155 Install **mod_auth_kerb** in your linux installation. On Debian or Ubuntu this would be achieved by running:
156
157 {{code}}
158 aptitude install libapache2-mod-auth-kerb
159 {{/code}}
160
161 Of course the installation procedure varies per Linux distribution.
162
163 If your xwiki installation is mounted in Apache HTTPD under /xwiki, add the following to the virtual host configuration:
164
165 {{code}}
166 <Location /xwiki></Location>
167 AuthType Kerberos
168 AuthName "Kerberos Login"
169 KrbAuthRealms EXAMPLE.COM
170 Krb5Keytab "/etc/apache2/ssl/wiki.keytab"
171 KrbMethodK5Passwd off
172 KrbMethodNegotiate on
173 KrbSaveCredentials on
174 require valid-user
175 </Location>
176 {{/code}}
177
178 Make sure Apache Tomcat uses the authentication performed by Apache HTTPD with the "tomcatAuthentication" property in the connector description (which is in the **server.xml** file of Apache Tomcat):
179
180 {{code}}
181 <Connector port="8009" address="127.0.0.1" enableLookups="false" tomcatAuthentication="false" redirectPort="8443" protocol="AJP/1.3" ></Connector>
182 {{/code}}
183
184 Place the **authkerb.jar** jar in the ##WEB-INF/lib## directory of XWiki in Apache Tomcat.
185
186 Have Xwiki use the authentication module by changing the "xwiki.authentication.authclass" property in the ##WEB-INF/lib/xwiki.cfg## file.
187
188 {{code}}
189 xwiki.authentication.authclass=com.xpn.xwiki.user.impl.xwiki.AppServerTrustedKerberosAuthServiceImpl
190 {{/code}}
191
192 If you use Firefox, do not forget to whitelist the xwiki URL for HTTP Negotiate in about:config with the "network.negotiate-auth.trusted-uris" property. Possible values for this property include: //https:~/~/// for all secured connections or **example.com** for all example.com subdomains.
193
194 When I used JBoss SPNEGO (Kerberos in combination with LDAP) I changed the code of the **XWikiLDAPAuthServiceImpl** to be able to detect the sso user. The authenication already happend by using the SPNEGO module (JAAS). After that I'm using the ldap synchronisation feature to make sure that the user is up to date. The combination leads to an automatic login in XWiki and the user rights are controlled in the Active Directory server. I hope you can adopt this code or that you can use it for your own projects.
195
196 The configuration of ldap:
197
198 {{code}}
199 xwiki.authentication.authclass=com.wiki.sso.SSOLdapAuthenicationImpl
200 xwiki.authentication.ldap=1
201 xwiki.authentication.ldap.server=<ad-server>
202 xwiki.authentication.ldap.port=389
203 xwiki.authentication.ldap.base_DN=<OU=Users,...............>
204 #use a fixed user to attach to the ldap database,
205 #the password is not provided with the SSOLdapAuthenicationImpl
206 xwiki.authentication.ldap.bind_DN=<domain>\\<user>
207 xwiki.authentication.ldap.bind_pass=<password>
208 #Microsoft AD configuration
209 xwiki.authentication.ldap.UID_attr=sAMAccountName
210 xwiki.authentication.ldap.fields_mapping=name=sAMAccountName,last_name=sn,first_name=givenName,fullname=displayName,mail=mail,ldap_dn=dn
211 xwiki.authentication.ldap.group_memberfields=member,uniqueMember
212 #LDAP group mapping
213 xwiki.authentication.ldap.group_mapping=XWiki.XWikiAdminGroup=CN=WIKI_Admin,............|\
214 XWiki.XWikiAllGroup=CN=WIKI_User,...........
215 {{/code}}
216
217 The java code:
218
219 {{code}}
220 package com.wiki.sso;
221
222
223 import org.apache.commons.logging.Log;
224 import org.apache.commons.logging.LogFactory;
225
226 import com.xpn.xwiki.XWikiContext;
227 import com.xpn.xwiki.XWikiException;
228 import com.xpn.xwiki.user.api.XWikiUser;
229 import com.xpn.xwiki.user.impl.LDAP.XWikiLDAPAuthServiceImpl;
230
231 import java.security.Principal;
232
233 public class SSOLdapAuthenicationImpl extends XWikiLDAPAuthServiceImpl {
234 /**
235 * Logging tool.
236 */
237 private static final Log LOG = LogFactory.getLog(SSOLdapAuthenicationImpl.class);
238
239
240 public XWikiUser checkAuth(XWikiContext context) throws XWikiException {
241 String user = getRemoteUser(context);
242 if ((user != null) || !user.equals("")) {
243 if (LOG.isInfoEnabled())
244 LOG.info("Launching create user for " + user);
245 if ( authenticate(user, context) != null ) {
246 if (LOG.isInfoEnabled())
247 LOG.info("Create user done for " + user);
248 user = "XWiki." + user;
249 context.setUser(user);
250 System.out.println("User is set to:" + user);
251 return new XWikiUser(user);
252 } else {
253 LOG.error( "User " + user + " can't be authenticated against ldap" );
254 }
255 }
256 return super.checkAuth(context);
257 }
258
259 /**
260 * We cannot authenticate locally since we need to trust the app server for
261 * authentication
262 *
263 * @param username
264 * @param password
265 * @param context
266 * @return
267 * @throws XWikiException
268 */
269 public XWikiUser checkAuth(String username, String password,
270 String rememberme, XWikiContext context) throws XWikiException {
271 String user = getRemoteUser(context);
272 if ((user == null) || user.equals("")) {
273 return super.checkAuth(username, password, rememberme, context);
274 }
275 return checkAuth(context);
276 }
277
278 private String getRemoteUser(XWikiContext context) {
279 String userName = context.getRequest().getHttpServletRequest()
280 .getRemoteUser();
281 if (userName != null) {
282 // only take the front of the username@domain
283 String[] elements = userName.split("@", 2);
284 userName = elements[0];
285 }
286 return userName;
287 }
288
289 public Principal authenticate(String login, XWikiContext context) throws XWikiException
290 {
291 if (LOG.isTraceEnabled()) {
292 LOG.trace("Starting LDAP authentication");
293 }
294
295 /*
296 * TODO: Put the next 4 following "if" in common with XWikiAuthService to ensure coherence This method was
297 * returning null on failure so I preserved that behaviour, while adding the exact error messages to the context
298 * given as argument. However, the right way to do this would probably be to throw XWikiException-s.
299 */
300
301 if (login == null) {
302 // If we can't find the username field then we are probably on the login screen
303
304 if (LOG.isDebugEnabled()) {
305 LOG.debug("The provided user is null."
306 + " We don't try to authenticate, it probably means the user is in non logged mode.");
307 }
308
309 return null;
310 }
311
312 // Check for empty usernames
313 if (login.equals("")) {
314 context.put("message", "nousername");
315
316 if (LOG.isDebugEnabled()) {
317 LOG.debug("LDAP authentication failed: login empty");
318 }
319
320 return null;
321 }
322
323 // If we have the context then we are using direct mode
324 // then we should specify the database
325 // This is needed for virtual mode to work
326 Principal principal = null;
327
328 // Try authentication against ldap
329 principal = ldapAuthenticate(login, "", context);
330
331 if (LOG.isDebugEnabled()) {
332 if (principal != null) {
333 LOG.debug("LDAP authentication succeed with principal [" + principal.getName() + "]");
334 } else {
335 LOG.debug("LDAP authentication failed for user [" + login + "]");
336 }
337 }
338
339 return principal;
340 }
341 }
342 {{/code}}
343
344 = Security =
345
346
347 Starting with {{code}}XWiki 11.6RC1{{/code}} we provide some authentication strategies that are triggered if a user fails several time in a row to login.
348 You can configure those strategies and when they should be triggered in the Administration > Authentication page.
349
350 {{gallery}}
351 image:authentication-security-administration.png
352 {{/gallery}}
353
354
355 For more information see the [[Authencation Security Module documentation>>extensions:Extension.Authentication Security Module]].

Get Connected