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;
17:
18: /**
19: * An abstract implementation of the {@link AuthenticationManager}.
20: *
21: * @author Wesley Hall
22: * @version $Id: AbstractAuthenticationManager.java 2350 2007-12-07 16:20:31Z luke_t $
23: */
24: public abstract class AbstractAuthenticationManager implements
25: AuthenticationManager {
26: //~ Methods ========================================================================================================
27:
28: /**
29: * <p>An implementation of the <code>authenticate</code> method that calls the abstract method
30: * <code>doAuthenticatation</code> to do its work.</p>
31: * <p>If doAuthenticate throws an <code>AuthenticationException</code> then the exception is populated
32: * with the failed <code>Authentication</code> object that failed.</p>
33: *
34: * @param authRequest the authentication request object
35: *
36: * @return a fully authenticated object including credentials
37: *
38: * @throws AuthenticationException if authentication fails
39: */
40: public final Authentication authenticate(Authentication authRequest)
41: throws AuthenticationException {
42: try {
43: return doAuthentication(authRequest);
44: } catch (AuthenticationException e) {
45: e.setAuthentication(authRequest);
46: throw e;
47: }
48: }
49:
50: /**
51: * <p>Concrete implementations of this class override this method to provide the authentication service.</p>
52: * <p>The contract for this method is documented in the {@link
53: * AuthenticationManager#authenticate(Authentication)}.</p>
54: *
55: * @param authentication the authentication request object
56: *
57: * @return a fully authenticated object including credentials
58: *
59: * @throws AuthenticationException if authentication fails
60: */
61: protected abstract Authentication doAuthentication(
62: Authentication authentication)
63: throws AuthenticationException;
64: }
|