Hide last authors
Ecaterina Moraru (Valica) 94.4 1 {{box cssClass="floatinginfobox" title="**Contents**"}}
Silvia Macovei 34.2 2 {{toc/}}
Ecaterina Moraru (Valica) 94.4 3 {{/box}}
Silvia Macovei 34.1 4
Ecaterina Moraru (Valica) 94.4 5 XWiki supports several different authentication mechanisms for authenticating users.
6
Silvia Macovei 34.1 7 {{info}}
Manuel Smeria 64.2 8 XWiki currently allows only one method of authentication to be enabled at a time. This will probably be improved in the future.
Silvia Macovei 34.1 9 {{/info}}
Vincent Massol 1.1 10
Vincent Massol 72.1 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
Silvia Macovei 34.2 13 = Form Authentication =
Vincent Massol 1.1 14
Sorin Burjan 38.2 15 Form authentication is the default way to get authenticated within a Wiki. It requires a user and a password.
Vincent Massol 1.1 16
Vincent Massol 46.1 17 = Basic Authentication =
18
Manuel Smeria 64.2 19 XWiki supports [[basic access authentication>>http://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:
Vincent Massol 46.1 20
21 {{code}}
22 http://username:password@mywiki.xwiki.com/xwiki/bin/view/Main/WebHome?basicauth=1
23 {{/code}}
24
25 {{warning}}
Manuel Smeria 64.2 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##.
Vincent Massol 46.1 27 {{/warning}}
28
Vincent Massol 70.1 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
Thomas Mortagne 79.1 35 {{code language="properties"}}
Vincent Massol 70.1 36 xwiki.authentication.authclass=com.xpn.xwiki.user.impl.xwiki.AppServerTrustedAuthServiceImpl
37 {{/code}}
38
Thomas Mortagne 79.1 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
Vincent Massol 62.1 45 = Social Login =
Valdis Vitolins 58.1 46
Manuel Smeria 64.2 47 See the [[Social Login Application>>extensions:Extension.Social Login Application]].
Valdis Vitolins 58.1 48
Alex Cotiugă 102.1 49 = Active Directory =
Thomas Mortagne 87.1 50
Thomas Mortagne 97.1 51 If you're looking to connect XWiki to an Active Directory server, you currently have 2 options:
Vincent Massol 95.1 52
Thomas Mortagne 97.1 53 * Using the manual and generic approach using the [[LDAP Authenticator extension>>extensions:Extension.LDAP.Authenticator]]
Vincent Massol 96.1 54 * 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.
55
Thomas Mortagne 98.2 56 = LDAP =
Vincent Massol 96.1 57
Thomas Mortagne 100.1 58 See the [[LDAP Authenticator extension>>extensions:Extension.LDAP.Authenticator]].
Thomas Mortagne 98.1 59
60 The deprecated LDAP core authenticator (for XWiki < 7.4) can be found on [[OldLDAPAuthenticator]].
61
Silvia Macovei 34.2 62 = Custom Authentication =
Vincent Massol 1.1 63
64 This allows plugging to any existing authentication mechanism such as SiteMinder, etc. To configure a custom authentication do the following:
65
Sergiu Dumitriu 47.2 66 1. Implement the {{scm path="xwiki-platform-core/xwiki-platform-oldcore/src/main/java/com/xpn/xwiki/user/api/XWikiAuthService.java"}}XWikiAuthService{{/scm}} interface.
Silvia Macovei 34.1 67 1. Edit the //WEB-INF/xwiki.cfg// file and add a //xwiki.authentication.authclass// property pointing to your class. For example:
68
Thomas Mortagne 56.1 69 {{code language="properties"}}
Vincent Massol 1.1 70 xwiki.authentication.authclass = com.acme.MyCustomAuthenticationService
Silvia Macovei 34.1 71 {{/code}}
Vincent Massol 1.1 72
Thomas Mortagne 78.1 73 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]].
Thomas Mortagne 56.1 74
Silvia Macovei 34.1 75 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/]].
Vincent Massol 27.2 76
Thomas Mortagne 89.1 77 Note that it's also possible to customize the right management system, see [[extensions:Extension.Security Module]] for more details.
Silvia Macovei 34.1 78
Silvia Macovei 34.2 79 == Custom Authentication using a Groovy script in a wiki page ==
Vincent Massol 28.1 80
81 Start by specifying you want to use the Groovy Authenticator:
82
Thomas Mortagne 57.1 83 {{code language="properties"}}
Vincent Massol 28.1 84 xwiki.authentication.authclass = com.xpn.xwiki.user.impl.xwiki.GroovyAuthServiceImpl
Silvia Macovei 34.1 85 {{/code}}
Vincent Massol 28.1 86
87 Then add another configuration parameter to specify in which wiki page the authenticator is:
88
Thomas Mortagne 57.1 89 {{code language="properties"}}
Vincent Massol 28.1 90 xwiki.authentication.groovy.pagename = MySpace.MyPage
Silvia Macovei 34.1 91 {{/code}}
Vincent Massol 28.1 92
Manuel Smeria 64.2 93 Then put some Groovy code in a wiki page that returns a XWikiAuthService object.
Vincent Massol 28.1 94
Thomas Mortagne 37.1 95 = Authentication parameters =
ShawnLauzon 1.14 96
97 You can set each of these parameters by setting:
98
Silvia Macovei 34.1 99 {{code}}
Vincent Massol 89.2 100 xwiki.authentication.<param_name>=<param_value>
Silvia Macovei 34.1 101 {{/code}}
ShawnLauzon 1.14 102
Silvia Macovei 34.1 103 |=Name|=Optional|=Allowed values|=Default value|=Description
104 |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.
105 |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.
106 |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
107 |cookielife|Yes|Number|14|Number of days cookies take to expire
108 |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//
109 |default_page|Yes|String|/bin/view/ Main/WebHome|Page to redirect to if xredirect parameter is not set
110 |encryptionalgorithm|Yes|?|?|Set the Encryption Algorithm used to encrypt and decrypt cookies
111 |encryptionmode|Yes|?|?|Set the Encryption Mode used to encrypt and decrypt cookies
112 |encryptionpadding|Yes|?|?|Set the Encryption Padding used to encrypt and decrypt cookies
113 |errorpage|Yes|String|/bin/loginerror/ XWiki/XWikiLogin|Page to redirect to if there is an error logging in
114 |loginpage|Yes|String|/bin/login/ XWiki/XWikiLogin|Page to redirect to when not logged in
Caleb James DeLisle 35.1 115 |loginsubmitpage|Yes|String|/loginsubmit/ XWiki/XWikiLogin|The URL where the username and password are posted to when logging in.
Silvia Macovei 34.1 116 |logoutpage|Yes|String|/bin/logout/ XWiki/XWikiLogout|Page to redirect to after logged out
117 |realmname|Yes|String|XWiki|Sets the realm name
118 |protection|Yes|all, validation, encryption, none|all|Protection level for the "remember me" cookie functionality
Thomas Mortagne 101.1 119 |unauthorized_code|Yes|Number|403|The HTTP status code to return when the login has failed.
Silvia Macovei 34.1 120 |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.
ShawnLauzon 1.16 121
Silvia Macovei 34.1 122 1. Only required if protection = encryption or all (default)
123 1. Only required if protection = validation or all (default)
ShawnLauzon 1.17 124
Silvia Macovei 34.2 125 = Kerberos SSO Authentication =
Jasper Siepkes 21.1 126
Silvia Macovei 34.1 127 {{warning}}
Thomas Mortagne 94.1 128 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!
Silvia Macovei 34.1 129 {{/warning}}
130
Manuel Smeria 64.2 131 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.
jmcettrick 1.18 132
Jasper Siepkes 20.1 133 First of all you need to create a principal and keytab for the webserver:
Silvia Macovei 34.1 134
135 {{code}}
Jasper Siepkes 20.1 136 # kadmin
137 kadmin> addprinc -randkey HTTP/wiki.example.com
138 kadmin> ktadd -k /etc/apache2/ssl/wiki.keytab HTTP/wiki.example.com
139 kadmin> quit
Silvia Macovei 34.1 140 {{/code}}
Thomas Mortagne 10.1 141
Jasper Siepkes 20.1 142 Make sure the keytab has the right permissions and ownership:
Silvia Macovei 34.1 143
144 {{code}}
Jasper Siepkes 20.1 145 chown www-data:www-data /etc/apache2/ssl/wiki.keytab
146 chmod 400 /etc/apache2/ssl/wiki.keytab
Silvia Macovei 34.1 147 {{/code}}
Thomas Mortagne 11.1 148
Manuel Smeria 64.2 149 Install **mod_auth_kerb** in your linux installation. On Debian or Ubuntu this would be achieved by running:
Silvia Macovei 34.1 150
151 {{code}}
Jasper Siepkes 20.1 152 aptitude install libapache2-mod-auth-kerb
Silvia Macovei 34.1 153 {{/code}}
154
Jasper Siepkes 20.1 155 Of course the installation procedure varies per Linux distribution.
156
157 If your xwiki installation is mounted in Apache HTTPD under /xwiki, add the following to the virtual host configuration:
Silvia Macovei 34.1 158
159 {{code}}
Jasper Siepkes 20.1 160 <Location /xwiki/>
161 AuthType Kerberos
162 AuthName "Kerberos Login"
163 KrbAuthRealms EXAMPLE.COM
164 Krb5Keytab "/etc/apache2/ssl/wiki.keytab"
165 KrbMethodK5Passwd off
166 KrbMethodNegotiate on
167 KrbSaveCredentials on
168 require valid-user
169 </Location>
Silvia Macovei 34.1 170 {{/code}}
Jasper Siepkes 20.1 171
Manuel Smeria 64.2 172 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):
Silvia Macovei 34.1 173
174 {{code}}
Jasper Siepkes 20.1 175 <Connector port="8009" address="127.0.0.1" enableLookups="false" tomcatAuthentication="false" redirectPort="8443" protocol="AJP/1.3" />
Silvia Macovei 34.1 176 {{/code}}
Jasper Siepkes 20.1 177
Manuel Smeria 64.2 178 Place the **authkerb.jar** jar in the ##WEB-INF/lib## directory of XWiki in Apache Tomcat.
Jasper Siepkes 20.1 179
Manuel Smeria 64.2 180 Have Xwiki use the authentication module by changing the "xwiki.authentication.authclass" property in the ##WEB-INF/lib/xwiki.cfg## file.
Silvia Macovei 34.1 181
182 {{code}}
Jasper Siepkes 20.1 183 xwiki.authentication.authclass=com.xpn.xwiki.user.impl.xwiki.AppServerTrustedKerberosAuthServiceImpl
Silvia Macovei 34.1 184 {{/code}}
Jasper Siepkes 20.1 185
Manuel Smeria 64.2 186 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.
Jasper Siepkes 20.1 187
Manuel Smeria 64.2 188 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.
jek 29.1 189
Silvia Macovei 34.2 190 The configuration of ldap:
jek 29.1 191
Silvia Macovei 34.1 192 {{code}}
jek 29.1 193 xwiki.authentication.authclass=com.wiki.sso.SSOLdapAuthenicationImpl
194 xwiki.authentication.ldap=1
195 xwiki.authentication.ldap.server=<ad-server>
196 xwiki.authentication.ldap.port=389
197 xwiki.authentication.ldap.base_DN=<OU=Users,...............>
198 #use a fixed user to attach to the ldap database,
199 #the password is not provided with the SSOLdapAuthenicationImpl
200 xwiki.authentication.ldap.bind_DN=<domain>\\<user>
201 xwiki.authentication.ldap.bind_pass=<password>
202 #Microsoft AD configuration
203 xwiki.authentication.ldap.UID_attr=sAMAccountName
204 xwiki.authentication.ldap.fields_mapping=name=sAMAccountName,last_name=sn,first_name=givenName,fullname=displayName,mail=mail,ldap_dn=dn
205 xwiki.authentication.ldap.group_memberfields=member,uniqueMember
206 #LDAP group mapping
207 xwiki.authentication.ldap.group_mapping=XWiki.XWikiAdminGroup=CN=WIKI_Admin,............|\
208 XWiki.XWikiAllGroup=CN=WIKI_User,...........
Silvia Macovei 34.1 209 {{/code}}
jek 29.1 210
Manuel Smeria 64.2 211 The java code:
Silvia Macovei 34.1 212
213 {{code}}
jek 29.1 214 package com.wiki.sso;
215
216
217 import org.apache.commons.logging.Log;
218 import org.apache.commons.logging.LogFactory;
219
220 import com.xpn.xwiki.XWikiContext;
221 import com.xpn.xwiki.XWikiException;
222 import com.xpn.xwiki.user.api.XWikiUser;
223 import com.xpn.xwiki.user.impl.LDAP.XWikiLDAPAuthServiceImpl;
224
225 import java.security.Principal;
226
227 public class SSOLdapAuthenicationImpl extends XWikiLDAPAuthServiceImpl {
228 /**
229 * Logging tool.
230 */
231 private static final Log LOG = LogFactory.getLog(SSOLdapAuthenicationImpl.class);
232
233
Sorin Burjan 64.3 234 public XWikiUser checkAuth(XWikiContext context) throws XWikiException {
235 String user = getRemoteUser(context);
236 if ((user != null) || !user.equals("")) {
237 if (LOG.isInfoEnabled())
238 LOG.info("Launching create user for " + user);
239 if ( authenticate(user, context) != null ) {
240 if (LOG.isInfoEnabled())
241 LOG.info("Create user done for " + user);
242 user = "XWiki." + user;
243 context.setUser(user);
244 System.out.println("User is set to:" + user);
245 return new XWikiUser(user);
246 } else {
247 LOG.error( "User " + user + " can't be authenticated against ldap" );
248 }
249 }
250 return super.checkAuth(context);
251 }
jek 29.1 252
Sorin Burjan 64.3 253 /**
254 * We cannot authenticate locally since we need to trust the app server for
255 * authentication
256 *
257 * @param username
258 * @param password
259 * @param context
260 * @return
261 * @throws XWikiException
262 */
263 public XWikiUser checkAuth(String username, String password,
264 String rememberme, XWikiContext context) throws XWikiException {
265 String user = getRemoteUser(context);
266 if ((user == null) || user.equals("")) {
267 return super.checkAuth(username, password, rememberme, context);
268 }
269 return checkAuth(context);
270 }
jek 29.1 271
Sorin Burjan 64.3 272 private String getRemoteUser(XWikiContext context) {
273 String userName = context.getRequest().getHttpServletRequest()
274 .getRemoteUser();
275 if (userName != null) {
276 // only take the front of the username@domain
277 String[] elements = userName.split("@", 2);
278 userName = elements[0];
279 }
280 return userName;
281 }
jek 29.1 282
283 public Principal authenticate(String login, XWikiContext context) throws XWikiException
284 {
285 if (LOG.isTraceEnabled()) {
286 LOG.trace("Starting LDAP authentication");
287 }
288
289 /*
290 * TODO: Put the next 4 following "if" in common with XWikiAuthService to ensure coherence This method was
291 * returning null on failure so I preserved that behaviour, while adding the exact error messages to the context
292 * given as argument. However, the right way to do this would probably be to throw XWikiException-s.
293 */
294
295 if (login == null) {
296 // If we can't find the username field then we are probably on the login screen
297
298 if (LOG.isDebugEnabled()) {
299 LOG.debug("The provided user is null."
300 + " We don't try to authenticate, it probably means the user is in non logged mode.");
301 }
302
303 return null;
304 }
305
306 // Check for empty usernames
307 if (login.equals("")) {
308 context.put("message", "nousername");
309
310 if (LOG.isDebugEnabled()) {
311 LOG.debug("LDAP authentication failed: login empty");
312 }
313
314 return null;
315 }
316
317 // If we have the context then we are using direct mode
318 // then we should specify the database
319 // This is needed for virtual mode to work
320 Principal principal = null;
321
322 // Try authentication against ldap
323 principal = ldapAuthenticate(login, "", context);
324
325 if (LOG.isDebugEnabled()) {
326 if (principal != null) {
327 LOG.debug("LDAP authentication succeed with principal [" + principal.getName() + "]");
328 } else {
329 LOG.debug("LDAP authentication failed for user [" + login + "]");
330 }
331 }
332
333 return principal;
334 }
335 }
Silvia Macovei 34.1 336 {{/code}}
Simon Urli 103.1 337
338 = Security =
339
340 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.
341 You can configure those strategies and when they should be triggered in the Administration > Authentication page.
342
343 {{gallery}}
344 image:authentication-security-administration.png
345 {{/gallery}}
346 For more information see the [[Authencation Security Module documentation>>extensions:Extension.Authentication Security Module]].

Get Connected