Source code: org/acegisecurity/providers/rcp/RemoteAuthenticationManagerImpl.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.providers.rcp;
17
18 import org.acegisecurity.AuthenticationException;
19 import org.acegisecurity.AuthenticationManager;
20 import org.acegisecurity.GrantedAuthority;
21 import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;
22
23 import org.springframework.beans.factory.InitializingBean;
24 import org.springframework.util.Assert;
25
26
27 /**
28 * Server-side processor of a remote authentication request.
29 *
30 * <P>
31 * This bean requires no security interceptor to protect it. Instead, the bean
32 * uses the configured <code>AuthenticationManager</code> to resolve an
33 * authentication request.
34 * </p>
35 *
36 * @author Ben Alex
37 * @version $Id: RemoteAuthenticationManagerImpl.java,v 1.3 2005/11/17 00:55:51 benalex Exp $
38 */
39 public class RemoteAuthenticationManagerImpl
40 implements RemoteAuthenticationManager, InitializingBean {
41 //~ Instance fields ========================================================
42
43 private AuthenticationManager authenticationManager;
44
45 //~ Methods ================================================================
46
47 public void setAuthenticationManager(
48 AuthenticationManager authenticationManager) {
49 this.authenticationManager = authenticationManager;
50 }
51
52 public AuthenticationManager getAuthenticationManager() {
53 return authenticationManager;
54 }
55
56 public void afterPropertiesSet() throws Exception {
57 Assert.notNull(this.authenticationManager, "authenticationManager is required");
58 }
59
60 public GrantedAuthority[] attemptAuthentication(String username,
61 String password) throws RemoteAuthenticationException {
62 UsernamePasswordAuthenticationToken request = new UsernamePasswordAuthenticationToken(username,
63 password);
64
65 try {
66 return authenticationManager.authenticate(request).getAuthorities();
67 } catch (AuthenticationException authEx) {
68 throw new RemoteAuthenticationException(authEx.getMessage());
69 }
70 }
71 }