/*
 * Copyright (c) 2002-2005 the original author or authors.
 * 
 * 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.springframework.richclient.security;

import net.sf.acegisecurity.Authentication;
import net.sf.acegisecurity.AuthenticationException;
import net.sf.acegisecurity.AuthenticationManager;
import net.sf.acegisecurity.BadCredentialsException;
import net.sf.acegisecurity.GrantedAuthority;
import net.sf.acegisecurity.GrantedAuthorityImpl;
import net.sf.acegisecurity.LockedException;
import net.sf.acegisecurity.providers.TestingAuthenticationToken;

/**
 * Test implementation giving us control over the authentication results.
 * 
 * @author Larry Streepy
 */
public class TestAuthenticationManager implements AuthenticationManager {

    /** Test role */
    public static final String ROLE_EXPECTED = "ROLE_EXPECTED";
    
    /** Token to use to force a successful authentication. */
    public static final Authentication VALID_USER1 = new TestingAuthenticationToken( "USER1", "FOO",
        new GrantedAuthority[] { new GrantedAuthorityImpl( ROLE_EXPECTED ) } );

    /** Token to use to force a successful authentication. */
    public static final Authentication VALID_USER2 = new TestingAuthenticationToken( "USER2", "FOO", null );

    /** Token to use to force a failed (bad credentials) authentication. */
    public static final Authentication BAD_CREDENTIALS = new TestingAuthenticationToken( "FAIL", "FOO", null );

    /** Token to use to force a LOCKED authentication exception. */
    public static final Authentication LOCKED = new TestingAuthenticationToken( "LOCKED", "FOO", null );

    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        if( authentication == VALID_USER1 || authentication == VALID_USER2 ) {
            return authentication;
        } else if( authentication == BAD_CREDENTIALS ) {
            throw new BadCredentialsException( "Bad credentials" );
        } else if( authentication == LOCKED ) {
            throw new LockedException( "Account is locked" );
        }
        return null;
    }

}

@@ -2138,31 +2138,102 @@
     
-public Authentication a
+/**%0A     * Construct a token with the given id, password, and role%0A     */%0A    public static A
 uthe
@@ -2242,10 +2242,16 @@
 icat
+ion mak
 e
-(
 Auth
@@ -2264,186 +2264,355 @@
 tion
- authentication) throws AuthenticationException %7B%0A        if( authentication == VALID_USER1 %7C%7C authentication == VALID_USER2 ) %7B
+( String user, String password, String role ) %7B%0A        return new TestingAuthenticationToken( user, password,%0A            new GrantedAuthority%5B%5D %7B new GrantedAuthorityImpl( role ) %7D );%0A    %7D%0A%0A    /**%0A     * Authenticate a token
 %0A     
+*/%0A
     
-   return authentication;%0A        %7D else
+public Authentication authenticate(Authentication authentication) throws AuthenticationException %7B%0A       
  if(
@@ -2857,19 +2857,29 @@
 urn 
-null
+authentication
 ;%0A    %7D%0A
 %0A%7D%0A
@@ -2875,11 +2875,10 @@
 ;%0A    %7D%0A
-%0A
 %7D%0A

Add makeAuthenticationToken and update authentication to only throw an error on the two named "bad" tokens.