01: /**
02: * @author <a href="mailto:novotny@gridsphere.org">Jason Novotny</a>
03: * @version $Id: PasswordAuthModule.java 6407 2008-01-16 15:20:21Z wehrens $
04: */package org.gridsphere.services.core.security.auth.modules.impl;
05:
06: import org.apache.commons.logging.Log;
07: import org.apache.commons.logging.LogFactory;
08: import org.gridsphere.portlet.service.spi.PortletServiceFactory;
09: import org.gridsphere.services.core.security.auth.AuthenticationException;
10: import org.gridsphere.services.core.security.auth.modules.LoginAuthModule;
11: import org.gridsphere.services.core.security.auth.modules.impl.descriptor.AuthModuleDefinition;
12: import org.gridsphere.services.core.security.password.InvalidPasswordException;
13: import org.gridsphere.services.core.security.password.PasswordManagerService;
14: import org.gridsphere.services.core.user.User;
15:
16: public class PasswordAuthModule extends BaseAuthModule implements
17: LoginAuthModule {
18:
19: private PasswordManagerService passwordManager = null;
20:
21: private Log log = LogFactory.getLog(PasswordAuthModule.class);
22:
23: public PasswordAuthModule(AuthModuleDefinition moduleDef) {
24:
25: super (moduleDef);
26:
27: // Get instance of password manager service
28: try {
29: this .passwordManager = (PasswordManagerService) PortletServiceFactory
30: .createPortletService(PasswordManagerService.class,
31: true);
32: } catch (Exception e) {
33: log
34: .error(
35: "Unable to get instance of password manager service!",
36: e);
37: }
38: }
39:
40: public void checkAuthentication(User user, String password)
41: throws AuthenticationException {
42: log.debug("Entering authenticate");
43: // Check that password is not null
44: if (password == null) {
45: log.debug("Password is not provided.");
46: throw new AuthenticationException("key1");
47: }
48: // Check that password maps to the given user
49: try {
50: this .passwordManager.validateSuppliedPassword(user,
51: password);
52: } catch (InvalidPasswordException e) {
53: log.debug("Incorrect password provided.");
54: throw new AuthenticationException("key2");
55: }
56: }
57:
58: }
|