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