/* Copyright 2004 Acegi Technology Pty Limited
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.acegisecurity.providers.rcp;

import org.acegisecurity.Authentication;
import org.acegisecurity.AuthenticationException;
import org.acegisecurity.GrantedAuthority;
import org.acegisecurity.providers.AuthenticationProvider;
import org.acegisecurity.providers.UsernamePasswordAuthenticationToken;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import org.springframework.beans.factory.InitializingBean;
import org.springframework.util.Assert;


/**
 * Client-side object which queries a  {@link RemoteAuthenticationManager} to
 * validate an authentication request.
 * 
 * <p>
 * A new <code>Authentication</code> object is created by this class comprising
 * the request <code>Authentication</code> object's <code>principal</code>,
 * <code>credentials</code> and the <code>GrantedAuthority</code>[]s returned
 * by the <code>RemoteAuthenticationManager</code>.
 * </p>
 * 
 * <p>
 * The <code>RemoteAuthenticationManager</code> should not require any special
 * username or password setting on the remoting client proxy factory to
 * execute the call. Instead the entire authentication request must be
 * encapsulated solely within the <code>Authentication</code> request object.
 * In practical terms this means the <code>RemoteAuthenticationManager</code>
 * will <b>not</b> be protected by BASIC or any other HTTP-level
 * authentication.
 * </p>
 * 
 * <p>
 * If authentication fails, a <code>RemoteAuthenticationException</code> will
 * be thrown. This exception should be caught and displayed to the user,
 * enabling them to retry with alternative credentials etc.
 * </p>
 *
 * @author Ben Alex
 * @version $Id$
 */
public class RemoteAuthenticationProvider implements AuthenticationProvider,
    InitializingBean {

    //~ Instance fields ========================================================

    private RemoteAuthenticationManager remoteAuthenticationManager;

    //~ Methods ================================================================

    public void setRemoteAuthenticationManager(
        RemoteAuthenticationManager remoteAuthenticationManager) {
        this.remoteAuthenticationManager = remoteAuthenticationManager;
    }

    public RemoteAuthenticationManager getRemoteAuthenticationManager() {
        return remoteAuthenticationManager;
    }

    public void afterPropertiesSet() throws Exception {
        Assert.notNull(this.remoteAuthenticationManager, "remoteAuthenticationManager is mandatory");
    }

    public Authentication authenticate(Authentication authentication)
        throws AuthenticationException {
        String username = authentication.getPrincipal().toString();
        String password = authentication.getCredentials().toString();
        GrantedAuthority[] authorities = remoteAuthenticationManager
            .attemptAuthentication(username, password);

        return new UsernamePasswordAuthenticationToken(username, password,
            authorities);
    }

    public boolean supports(Class authentication) {
        return (UsernamePasswordAuthenticationToken.class.isAssignableFrom(authentication));
    }
}

@@ -10,16 +10,28 @@
 ght 2004
+, 2005, 2006
  Acegi T
@@ -791,16 +791,17 @@
 hority;%0A
+%0A
 import o
@@ -928,94 +928,8 @@
 n;%0A%0A
-import org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0A%0A
 impo
@@ -983,16 +983,17 @@
 ngBean;%0A
+%0A
 import o
@@ -2307,17 +2307,16 @@
 gBean %7B%0A
-%0A
     //~ 
@@ -2545,327 +2545,8 @@
 ==%0A%0A
-    public void setRemoteAuthenticationManager(%0A        RemoteAuthenticationManager remoteAuthenticationManager) %7B%0A        this.remoteAuthenticationManager = remoteAuthenticationManager;%0A    %7D%0A%0A    public RemoteAuthenticationManager getRemoteAuthenticationManager() %7B%0A        return remoteAuthenticationManager;%0A    %7D%0A%0A
     
@@ -2653,16 +2653,28 @@
 Manager,
+%0A           
  %22remote
@@ -3193,32 +3193,351 @@
 rities);%0A    %7D%0A%0A
+    public RemoteAuthenticationManager getRemoteAuthenticationManager() %7B%0A        return remoteAuthenticationManager;%0A    %7D%0A%0A    public void setRemoteAuthenticationManager(%0A        RemoteAuthenticationManager remoteAuthenticationManager) %7B%0A        this.remoteAuthenticationManager = remoteAuthenticationManager;%0A    %7D%0A%0A
     public boole

Remove unused imports.