| Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||||||
| RemoteAuthenticationProvider |
|
| 1.0;1 |
| 1 | /* Copyright 2004, 2005, 2006 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.Authentication; |
|
| 19 | import org.acegisecurity.AuthenticationException; |
|
| 20 | import org.acegisecurity.GrantedAuthority; |
|
| 21 | ||
| 22 | import org.acegisecurity.providers.AuthenticationProvider; |
|
| 23 | import org.acegisecurity.providers.UsernamePasswordAuthenticationToken; |
|
| 24 | ||
| 25 | import org.springframework.beans.factory.InitializingBean; |
|
| 26 | ||
| 27 | import org.springframework.util.Assert; |
|
| 28 | ||
| 29 | ||
| 30 | /** |
|
| 31 | * Client-side object which queries a {@link RemoteAuthenticationManager} to validate an authentication request.<p>A |
|
| 32 | * new <code>Authentication</code> object is created by this class comprising the request <code>Authentication</code> |
|
| 33 | * object's <code>principal</code>, <code>credentials</code> and the <code>GrantedAuthority</code>[]s returned by the |
|
| 34 | * <code>RemoteAuthenticationManager</code>.</p> |
|
| 35 | * <p>The <code>RemoteAuthenticationManager</code> should not require any special username or password setting on |
|
| 36 | * the remoting client proxy factory to execute the call. Instead the entire authentication request must be |
|
| 37 | * encapsulated solely within the <code>Authentication</code> request object. In practical terms this means the |
|
| 38 | * <code>RemoteAuthenticationManager</code> will <b>not</b> be protected by BASIC or any other HTTP-level |
|
| 39 | * authentication.</p> |
|
| 40 | * <p>If authentication fails, a <code>RemoteAuthenticationException</code> will be thrown. This exception should |
|
| 41 | * be caught and displayed to the user, enabling them to retry with alternative credentials etc.</p> |
|
| 42 | * |
|
| 43 | * @author Ben Alex |
|
| 44 | * @version $Id: RemoteAuthenticationProvider.java 1948 2007-08-25 00:15:30Z benalex $ |
|
| 45 | */ |
|
| 46 | 5 | public class RemoteAuthenticationProvider implements AuthenticationProvider, InitializingBean { |
| 47 | //~ Instance fields ================================================================================================ |
|
| 48 | ||
| 49 | private RemoteAuthenticationManager remoteAuthenticationManager; |
|
| 50 | ||
| 51 | //~ Methods ======================================================================================================== |
|
| 52 | ||
| 53 | public void afterPropertiesSet() throws Exception { |
|
| 54 | 2 | Assert.notNull(this.remoteAuthenticationManager, "remoteAuthenticationManager is mandatory"); |
| 55 | 1 | } |
| 56 | ||
| 57 | public Authentication authenticate(Authentication authentication) |
|
| 58 | throws AuthenticationException { |
|
| 59 | 2 | String username = authentication.getPrincipal().toString(); |
| 60 | 2 | String password = authentication.getCredentials().toString(); |
| 61 | 2 | GrantedAuthority[] authorities = remoteAuthenticationManager.attemptAuthentication(username, password); |
| 62 | ||
| 63 | 1 | return new UsernamePasswordAuthenticationToken(username, password, authorities); |
| 64 | } |
|
| 65 | ||
| 66 | public RemoteAuthenticationManager getRemoteAuthenticationManager() { |
|
| 67 | 1 | return remoteAuthenticationManager; |
| 68 | } |
|
| 69 | ||
| 70 | public void setRemoteAuthenticationManager(RemoteAuthenticationManager remoteAuthenticationManager) { |
|
| 71 | 4 | this.remoteAuthenticationManager = remoteAuthenticationManager; |
| 72 | 4 | } |
| 73 | ||
| 74 | public boolean supports(Class authentication) { |
|
| 75 | 2 | return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication)); |
| 76 | } |
|
| 77 | } |