1
2
3
4
5
6
7
8
9
10
11
12
13
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
42
43 private AuthenticationManager authenticationManager;
44
45
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 }