View Javadoc

1   /*
2    * Joey and its relative products are published under the terms
3    * of the Apache Software License.
4    */
5   /*
6    * Created on 2004/01/12
7    */
8   package org.asyrinx.joey.user.impl;
9   
10  import org.apache.commons.lang.exception.NestableRuntimeException;
11  import org.asyrinx.brownie.core.lang.ClassUtils;
12  import org.asyrinx.joey.user.ApplicationUser;
13  import org.asyrinx.joey.user.UserCertifier;
14  
15  /***
16   * @author akima
17   */
18  public class SimpleLoginManager {
19  
20      /***
21       *  
22       */
23      public SimpleLoginManager(UserCertifier certifier) {
24          super();
25          this.certifier = certifier;
26      }
27  
28      /***
29       *  
30       */
31      public SimpleLoginManager(String certifierClassName) {
32          this(newCertifier(certifierClassName));
33      }
34  
35      protected final UserCertifier certifier;
36  
37      private static UserCertifier newCertifier(String certifierClassName) {
38          try {
39              return (UserCertifier) ClassUtils.newObject(certifierClassName, UserCertifier.class);
40          } catch (InstantiationException e) {
41              throw new NestableRuntimeException(e);
42          }
43      }
44  
45      public ApplicationUser tryLogin(String userId, String password) {
46          if (certifier == null)
47              return null;
48          return certifier.canLogin(userId, password);
49      }
50  
51  }