01: /**
02: * Licensed under the GNU LESSER GENERAL PUBLIC LICENSE, version 2.1, dated February 1999.
03: *
04: * This program is free software; you can redistribute it and/or modify
05: * it under the terms of the latest version of the GNU Lesser General
06: * Public License as published by the Free Software Foundation;
07: *
08: * This program is distributed in the hope that it will be useful,
09: * but WITHOUT ANY WARRANTY; without even the implied warranty of
10: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11: * GNU Lesser General Public License for more details.
12: *
13: * You should have received a copy of the GNU Lesser General Public License
14: * along with this program (LICENSE.txt); if not, write to the Free Software
15: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
16: */package org.jamwiki.authentication;
17:
18: import org.acegisecurity.AuthenticationException;
19: import org.acegisecurity.AuthenticationServiceException;
20: import org.acegisecurity.BadCredentialsException;
21: import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
22: import org.acegisecurity.providers.dao.DaoAuthenticationProvider;
23: import org.acegisecurity.userdetails.UserDetails;
24: import org.jamwiki.WikiBase;
25:
26: /**
27: * AuthenticationProvider to use with JAMWiki database.
28: *
29: * Extends DaoAuthenticationProvider to use JAMWiki password authentication.
30: * It's not possible to use {@link org.acegisecurity.providers.dao.DaoAuthenticationProvider}
31: * with a {@link org.acegisecurity.providers.encoding.PasswordEncoder} because
32: * JAMWiki stores passwords encoded and not only hashed.
33: *
34: * @author Rainer Schmitz
35: * @version $Id: $
36: * @since 28.11.2006
37: */
38: public class JAMWikiDaoAuthenticationProvider extends
39: DaoAuthenticationProvider {
40:
41: /**
42: *
43: */
44: protected void additionalAuthenticationChecks(
45: UserDetails userDetails,
46: UsernamePasswordAuthenticationToken authentication)
47: throws AuthenticationException {
48: try {
49: if (!WikiBase.getUserHandler().authenticate(
50: userDetails.getUsername(),
51: authentication.getCredentials().toString())) {
52: throw new BadCredentialsException(
53: messages
54: .getMessage(
55: "AbstractUserDetailsAuthenticationProvider.badCredentials",
56: "Bad credentials"),
57: isIncludeDetailsObject() ? userDetails : null);
58: }
59: } catch (Exception e) {
60: throw new AuthenticationServiceException(e.getMessage(), e);
61: }
62: }
63:
64: }
|