View Javadoc

1   /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
2    *
3    * Licensed under the Apache License, Version 2.0 (the "License");
4    * you may not use this file except in compliance with the License.
5    * You may obtain a copy of the License at
6    *
7    *     http://www.apache.org/licenses/LICENSE-2.0
8    *
9    * Unless required by applicable law or agreed to in writing, software
10   * distributed under the License is distributed on an "AS IS" BASIS,
11   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12   * See the License for the specific language governing permissions and
13   * limitations under the License.
14   */
15  
16  package org.acegisecurity.ui;
17  
18  import org.springframework.util.Assert;
19  import org.springframework.util.ReflectionUtils;
20  
21  import java.lang.reflect.Constructor;
22  import java.lang.reflect.InvocationTargetException;
23  
24  import javax.servlet.http.HttpServletRequest;
25  
26  
27  /**
28   * Base implementation of {@link AuthenticationDetailsSource}.<P>By default will create an instance of
29   * <code>WebAuthenticationDetails</code>. Any object that accepts a <code>HttpServletRequest</code> as its sole
30   * constructor can be used instead of this default.</p>
31   *
32   * @author Ben Alex
33   * @version $Id: AuthenticationDetailsSourceImpl.java 1496 2006-05-23 13:38:33Z benalex $
34   */
35  public class AuthenticationDetailsSourceImpl implements AuthenticationDetailsSource {
36      //~ Instance fields ================================================================================================
37  
38      private Class clazz = WebAuthenticationDetails.class;
39  
40      //~ Methods ========================================================================================================
41  
42      public Object buildDetails(HttpServletRequest request) {
43          try {
44              Constructor constructor = clazz.getConstructor(new Class[] {HttpServletRequest.class});
45  
46              return constructor.newInstance(new Object[] {request});
47          } catch (NoSuchMethodException ex) {
48              ReflectionUtils.handleReflectionException(ex);
49          } catch (InvocationTargetException ex) {
50              ReflectionUtils.handleReflectionException(ex);
51          } catch (InstantiationException ex) {
52              ReflectionUtils.handleReflectionException(ex);
53          } catch (IllegalAccessException ex) {
54              ReflectionUtils.handleReflectionException(ex);
55          }
56  
57          return null;
58      }
59  
60      public void setClazz(Class clazz) {
61          Assert.notNull(clazz, "Class required");
62          this.clazz = clazz;
63      }
64  }