001/* 002 * The contents of this file are subject to the terms of the Common Development and 003 * Distribution License (the License). You may not use this file except in compliance with the 004 * License. 005 * 006 * You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the 007 * specific language governing permission and limitations under the License. 008 * 009 * When distributing Covered Software, include this CDDL Header Notice in each file and include 010 * the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL 011 * Header, with the fields enclosed by brackets [] replaced by your own identifying 012 * information: "Portions copyright [year] [name of copyright owner]". 013 * 014 * Copyright 2015 ForgeRock AS. 015 */ 016 017package org.forgerock.http.apache; 018 019import java.util.Collections; 020import java.util.LinkedList; 021import java.util.Map; 022import java.util.Queue; 023 024import org.apache.http.Header; 025import org.apache.http.HttpHost; 026import org.apache.http.HttpResponse; 027import org.apache.http.auth.AuthOption; 028import org.apache.http.auth.AuthScheme; 029import org.apache.http.auth.MalformedChallengeException; 030import org.apache.http.client.AuthenticationStrategy; 031import org.apache.http.protocol.HttpContext; 032 033/** 034 * An authentication strategy that never performs authentication. 035 */ 036public final class NoAuthenticationStrategy implements AuthenticationStrategy { 037 038 /** 039 * An {@link AuthenticationStrategy} singleton instance that never performs authentication. 040 */ 041 public static final AuthenticationStrategy INSTANCE = new NoAuthenticationStrategy(); 042 043 /** 044 * Singleton only. 045 */ 046 private NoAuthenticationStrategy() { } 047 048 @Override 049 public void authFailed(final HttpHost host, final AuthScheme authScheme, final HttpContext context) { 050 // Nothing to do. 051 } 052 053 @Override 054 public void authSucceeded(final HttpHost host, final AuthScheme authScheme, final HttpContext context) { 055 // Nothing to do. 056 } 057 058 @Override 059 public Map<String, Header> getChallenges(final HttpHost host, final HttpResponse response, 060 final HttpContext context) throws MalformedChallengeException { 061 return Collections.emptyMap(); 062 } 063 064 @Override 065 public boolean isAuthenticationRequested(final HttpHost host, final HttpResponse response, 066 final HttpContext context) { 067 return false; 068 } 069 070 @Override 071 public Queue<AuthOption> select(final Map<String, Header> challenges, final HttpHost host, 072 final HttpResponse response, final HttpContext context) throws MalformedChallengeException { 073 return new LinkedList<>(); 074 } 075}