01: /* Copyright 2004, 2005, 2006 Acegi Technology Pty Limited
02: *
03: * Licensed under the Apache License, Version 2.0 (the "License");
04: * you may not use this file except in compliance with the License.
05: * You may obtain a copy of the License at
06: *
07: * http://www.apache.org/licenses/LICENSE-2.0
08: *
09: * 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: * Base implementation of {@link AuthenticationDetailsSource}.<P>By default will create an instance of
28: * <code>WebAuthenticationDetails</code>. Any object that accepts a <code>HttpServletRequest</code> as its sole
29: * constructor can be used instead of this default.</p>
30: *
31: * @author Ben Alex
32: * @version $Id: AuthenticationDetailsSourceImpl.java 1496 2006-05-23 13:38:33Z benalex $
33: */
34: public class AuthenticationDetailsSourceImpl implements
35: 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
45: .getConstructor(new Class[] { HttpServletRequest.class });
46:
47: return constructor.newInstance(new Object[] { request });
48: } catch (NoSuchMethodException ex) {
49: ReflectionUtils.handleReflectionException(ex);
50: } catch (InvocationTargetException ex) {
51: ReflectionUtils.handleReflectionException(ex);
52: } catch (InstantiationException ex) {
53: ReflectionUtils.handleReflectionException(ex);
54: } catch (IllegalAccessException ex) {
55: ReflectionUtils.handleReflectionException(ex);
56: }
57:
58: return null;
59: }
60:
61: public void setClazz(Class clazz) {
62: Assert.notNull(clazz, "Class required");
63: this.clazz = clazz;
64: }
65: }
|