// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/CredentialsProviderFactory.java
// public class CredentialsProviderFactory {
// 
//     private TaxiiServiceSettings settings;
//     private ProxySettings proxySettings;
// 
//     public CredentialsProviderFactory(TaxiiServiceSettings settings, ProxySettings proxySettings) {
//         this.settings = settings;
//         this.proxySettings = proxySettings;
//     }
// 
//     private void addProxyCredentials(CredentialsProvider credsProvider) {
//         if (proxySettings.getUrl() == null) {
//             return ;
//         }
//         if (proxySettings.getAuthenticationType() == null) {
//             throw new IllegalStateException("Both proxy url and proxy authentication type have to be specified.");
//         }
// 
//         ProxyAuthenticationType authType = proxySettings.getAuthenticationType();
// 
//         URL proxyUrl = proxySettings.getUrl();
//         HttpHost proxyHost = new HttpHost(
//                 proxyUrl.getHost(),
//                 proxyUrl.getPort(),
//                 proxyUrl.getProtocol());
// 
//         Credentials credentials;
//         switch(authType) {
//             case NONE:
//                 break;
// 
//             case BASIC:
//                 credentials = new UsernamePasswordCredentials(proxySettings.getUsername(), proxySettings.getPassword());
//                 credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), credentials);
//                 break;
// 
//             case NTLM:
//                 credentials = new NTCredentials(
//                         proxySettings.getUsername(),
//                         proxySettings.getPassword(),
//                         proxySettings.getWorkstation(),
//                         proxySettings.getDomain());
//                 credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), credentials);
//                 break;
// 
//             default:
//                 throw new IllegalStateException("Unsupported authentication type: " + authType);
//         }
//     }
// 
//     private void addTaxiiCredentials(CredentialsProvider credsProvider) {
//         URL url = settings.getPollEndpoint();
//         HttpHost targetHost = new HttpHost(
//                 url.getHost(),
//                 url.getPort(),
//                 url.getProtocol());
//         credsProvider.setCredentials(
//                 new AuthScope(targetHost.getHostName(), targetHost.getPort()),
//                 new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword()));
//     }
// 
//     public CredentialsProvider build() {
//         // Create credentials provider for BASIC auth
//         CredentialsProvider credsProvider = new BasicCredentialsProvider();
//         addProxyCredentials(credsProvider);
//         addTaxiiCredentials(credsProvider);
//         return credsProvider;
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/ProxyAuthenticationType.java
// public enum ProxyAuthenticationType {
//     NONE,
//     BASIC,
//     NTLM
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/ProxySettings.java
// @ConfigurationProperties(prefix="proxy")
// @Data
// public class ProxySettings {
// 
//     private URL url;
// 
//     private ProxyAuthenticationType authenticationType;
// 
//     private String domain;
// 
//     private String username;
// 
//     private String password;
// 
//     private String workstation;
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettings.java
// @ConfigurationProperties(prefix="taxii-service")
// @Data
// @Validated
// public class TaxiiServiceSettings {
// 
//     private static final Charset UTF8 = Charset.forName("UTF-8");
// 
//     @NotNull
//     private URL pollEndpoint;
// 
//     @NotNull
//     private String username;
// 
//     @NotNull
//     private String password;
// 
//     private List<String> feeds;
// 
//     private File feedNamesFile;
// 
//     private File statusFile = new File("taxii-status.xml");
// 
//     @PostConstruct
//     public void loadFeedNames() throws IOException {
//         Preconditions.checkState(
//             feeds != null ^ feedNamesFile != null,
//             "taxii-service.feeds or taxii-service.feedNamesFile must be set");
//         if (feedNamesFile != null) {
//             feeds = Files.readLines(feedNamesFile, UTF8);
//         }
//     }
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettingsFactory.java
// public class TaxiiServiceSettingsFactory {
// 
//     public static TaxiiServiceSettings createDefaults() {
//         try {
//             TaxiiServiceSettings connSettings = new TaxiiServiceSettings();
//             connSettings.setPollEndpoint(new URL("http://localhost:8080/service"));
//             connSettings.setUsername("user");
//             connSettings.setPassword("pass");
//             return connSettings;
//         } catch (MalformedURLException e) {
//             throw new RuntimeException(e);
//         }
//     }
// }


import static junit.framework.TestCase.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNull;
import com.cisco.cta.taxii.adapter.httpclient.CredentialsProviderFactory;
import com.cisco.cta.taxii.adapter.httpclient.ProxyAuthenticationType;
import com.cisco.cta.taxii.adapter.settings.ProxySettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettingsFactory;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.client.CredentialsProvider;
import org.junit.Before;
import org.junit.Test;
import java.net.MalformedURLException;
import java.net.URL;
/*
   Copyright 2015 Cisco Systems

   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 com.cisco.cta.taxii.adapter.httpclient;





public class CredentialsProviderFactoryTest {

    private TaxiiServiceSettings taxiiSettings;

    @Before
    public void setUp() throws Exception {
// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/CredentialsProviderFactory.java
// public class CredentialsProviderFactory {
// 
//     private TaxiiServiceSettings settings;
//     private ProxySettings proxySettings;
// 
//     public CredentialsProviderFactory(TaxiiServiceSettings settings, ProxySettings proxySettings) {
//         this.settings = settings;
//         this.proxySettings = proxySettings;
//     }
// 
//     private void addProxyCredentials(CredentialsProvider credsProvider) {
//         if (proxySettings.getUrl() == null) {
//             return ;
//         }
//         if (proxySettings.getAuthenticationType() == null) {
//             throw new IllegalStateException("Both proxy url and proxy authentication type have to be specified.");
//         }
// 
//         ProxyAuthenticationType authType = proxySettings.getAuthenticationType();
// 
//         URL proxyUrl = proxySettings.getUrl();
//         HttpHost proxyHost = new HttpHost(
//                 proxyUrl.getHost(),
//                 proxyUrl.getPort(),
//                 proxyUrl.getProtocol());
// 
//         Credentials credentials;
//         switch(authType) {
//             case NONE:
//                 break;
// 
//             case BASIC:
//                 credentials = new UsernamePasswordCredentials(proxySettings.getUsername(), proxySettings.getPassword());
//                 credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), credentials);
//                 break;
// 
//             case NTLM:
//                 credentials = new NTCredentials(
//                         proxySettings.getUsername(),
//                         proxySettings.getPassword(),
//                         proxySettings.getWorkstation(),
//                         proxySettings.getDomain());
//                 credsProvider.setCredentials(new AuthScope(proxyHost.getHostName(), proxyHost.getPort()), credentials);
//                 break;
// 
//             default:
//                 throw new IllegalStateException("Unsupported authentication type: " + authType);
//         }
//     }
// 
//     private void addTaxiiCredentials(CredentialsProvider credsProvider) {
//         URL url = settings.getPollEndpoint();
//         HttpHost targetHost = new HttpHost(
//                 url.getHost(),
//                 url.getPort(),
//                 url.getProtocol());
//         credsProvider.setCredentials(
//                 new AuthScope(targetHost.getHostName(), targetHost.getPort()),
//                 new UsernamePasswordCredentials(settings.getUsername(), settings.getPassword()));
//     }
// 
//     public CredentialsProvider build() {
//         // Create credentials provider for BASIC auth
//         CredentialsProvider credsProvider = new BasicCredentialsProvider();
//         addProxyCredentials(credsProvider);
//         addTaxiiCredentials(credsProvider);
//         return credsProvider;
//     }
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/httpclient/ProxyAuthenticationType.java
// public enum ProxyAuthenticationType {
//     NONE,
//     BASIC,
//     NTLM
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/ProxySettings.java
// @ConfigurationProperties(prefix="proxy")
// @Data
// public class ProxySettings {
// 
//     private URL url;
// 
//     private ProxyAuthenticationType authenticationType;
// 
//     private String domain;
// 
//     private String username;
// 
//     private String password;
// 
//     private String workstation;
// 
// }
// 
// Path: src/main/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettings.java
// @ConfigurationProperties(prefix="taxii-service")
// @Data
// @Validated
// public class TaxiiServiceSettings {
// 
//     private static final Charset UTF8 = Charset.forName("UTF-8");
// 
//     @NotNull
//     private URL pollEndpoint;
// 
//     @NotNull
//     private String username;
// 
//     @NotNull
//     private String password;
// 
//     private List<String> feeds;
// 
//     private File feedNamesFile;
// 
//     private File statusFile = new File("taxii-status.xml");
// 
//     @PostConstruct
//     public void loadFeedNames() throws IOException {
//         Preconditions.checkState(
//             feeds != null ^ feedNamesFile != null,
//             "taxii-service.feeds or taxii-service.feedNamesFile must be set");
//         if (feedNamesFile != null) {
//             feeds = Files.readLines(feedNamesFile, UTF8);
//         }
//     }
// }
// 
// Path: src/test/java/com/cisco/cta/taxii/adapter/settings/TaxiiServiceSettingsFactory.java
// public class TaxiiServiceSettingsFactory {
// 
//     public static TaxiiServiceSettings createDefaults() {
//         try {
//             TaxiiServiceSettings connSettings = new TaxiiServiceSettings();
//             connSettings.setPollEndpoint(new URL("http://localhost:8080/service"));
//             connSettings.setUsername("user");
//             connSettings.setPassword("pass");
//             return connSettings;
//         } catch (MalformedURLException e) {
//             throw new RuntimeException(e);
//         }
//     }
// }


// Path: src/test/java/com/cisco/cta/taxii/adapter/httpclient/CredentialsProviderFactoryTest.java
import static junit.framework.TestCase.assertNotNull;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
import static org.junit.Assert.assertNull;
import com.cisco.cta.taxii.adapter.httpclient.CredentialsProviderFactory;
import com.cisco.cta.taxii.adapter.httpclient.ProxyAuthenticationType;
import com.cisco.cta.taxii.adapter.settings.ProxySettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettings;
import com.cisco.cta.taxii.adapter.settings.TaxiiServiceSettingsFactory;
import org.apache.http.auth.AuthScope;
import org.apache.http.auth.Credentials;
import org.apache.http.client.CredentialsProvider;
import org.junit.Before;
import org.junit.Test;
import java.net.MalformedURLException;
import java.net.URL;

/*
   Copyright 2015 Cisco Systems

   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 com.cisco.cta.taxii.adapter.httpclient;





public class CredentialsProviderFactoryTest {

    private TaxiiServiceSettings taxiiSettings;

    @Before
    public void setUp() throws Exception {
        taxiiSettings = TaxiiServiceSettingsFactory.createDefaults();