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