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.userdetails.UserDetails;
19: import org.acegisecurity.userdetails.UserDetailsService;
20: import org.acegisecurity.userdetails.UsernameNotFoundException;
21: import org.jamwiki.WikiBase;
22: import org.springframework.dao.DataAccessException;
23:
24: /**
25: * Loads user data from JAMWiki database.
26: *
27: * @author Rainer Schmitz
28: * @version $Id: $
29: * @since 28.11.2006
30: */
31: public class JAMWikiDaoImpl implements UserDetailsService {
32:
33: /*
34: * (non-Javadoc)
35: *
36: * @see org.acegisecurity.userdetails.UserDetailsService#loadUserByUsername(java.lang.String)
37: */
38: public UserDetails loadUserByUsername(String username)
39: throws UsernameNotFoundException, DataAccessException {
40: UserDetails loadedUser;
41: try {
42: loadedUser = new WikiUserAuth(WikiBase.getDataHandler()
43: .lookupWikiUser(username, null));
44: } catch (Exception e) {
45: // FIXME - for now throw an exception that Acegi can handle, but
46: // this should be handled with the Acegi ExceptionTranslationFilter
47: // throw new DataAccessResourceFailureException(e.getMessage(), e);
48: throw new UsernameNotFoundException(
49: "Failure retrieving user information for "
50: + username, e);
51: }
52: if (loadedUser == null) {
53: throw new UsernameNotFoundException("User with name '"
54: + username + "' not found in JAMWiki database.");
55: }
56: return loadedUser;
57: }
58: }
|