/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership. The ASF licenses this file
 * to you 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.apache.shindig.auth;

import org.apache.shindig.common.EasyMockTestCase;
import org.apache.shindig.common.servlet.HttpServletResponseRecorder;

import com.google.common.collect.ImmutableList;
import javax.servlet.FilterChain;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import static org.easymock.EasyMock.expect;
import org.junit.Before;
import org.junit.Test;

import javax.servlet.ServletException;

public class AuthenticationServletFilterTest extends EasyMockTestCase {
  private static final String TEST_AUTH_HEADER = "Test Authentication Header";

  private AuthenticationServletFilter filter;

  private HttpServletRequest request;
  private HttpServletResponse response;
  private HttpServletResponseRecorder recorder;
  private FilterChain chain;
  private AuthenticationHandler nullStHandler;

  @Before
  public void setup() {
    request = mock(HttpServletRequest.class);
    response  = mock(HttpServletResponse.class);
    recorder = new HttpServletResponseRecorder(response);
    chain = mock(FilterChain.class);
    filter = new AuthenticationServletFilter();
    nullStHandler = new NullSecurityTokenAuthenticationHandler();
  }

  @Test(expected = ServletException.class)
  public void testDoFilter_BadArgs() throws Exception {
    filter.doFilter(null, null, null);
  }

  @Test
  public void testNullSecurityToken() throws Exception {
    filter.setAuthenticationHandlers(ImmutableList.<AuthenticationHandler>of(nullStHandler));
    filter.doFilter(request, recorder, chain);
    assertEquals(TEST_AUTH_HEADER,
        recorder.getHeader(AuthenticationServletFilter.WWW_AUTHENTICATE_HEADER));
  }

  private static class NullSecurityTokenAuthenticationHandler implements AuthenticationHandler {
    @Override
    public String getName() {
      return "TestAuth";
    }

    @Override
    public SecurityToken getSecurityTokenFromRequest(HttpServletRequest request)
        throws InvalidAuthenticationException {
      return null;
    }

    @Override
    public String getWWWAuthenticateHeader(String realm) {
      return TEST_AUTH_HEADER;
    }
  }
}

@@ -2573,30 +2573,16 @@
 ndler %7B%0A
-    @Override%0A
     publ
@@ -2631,38 +2631,24 @@
 th%22;%0A    %7D%0A%0A
-    @Override%0A
     public S
@@ -2794,22 +2794,8 @@
  %7D%0A%0A
-    @Override%0A
     

Remove @Override annotations which trip up JDK 1.5 compilers.