// Path: src/main/java/de/otto/edison/jobtrigger/security/AuthProvider.java
// public interface AuthProvider {
// 
//     void setAuthHeader(BoundRequestBuilder requestBuilder);
// }
// 
// Path: src/main/java/de/otto/edison/jobtrigger/security/BasicAuthCredentials.java
// @Component
// @EnableConfigurationProperties(JobTriggerProperties.class)
// public class BasicAuthCredentials {
// 
//     private static final String VAULT_PREFIX = "VAULT ";
//     public static String AUTHORIZATION_HEADER = "Authorization";
// 
//     private static final String BASIC_PREFIX = "Basic ";
// 
//     private final String basicAuthUser;
//     private final String basicAuthPasswd;
// 
//     @Autowired
//     public BasicAuthCredentials(final JobTriggerProperties jobTriggerProperties, final VaultOperations vaultOperations) {
//         basicAuthUser = jobTriggerProperties.getSecurity().getBasicAuthUser();
//         String passwd = jobTriggerProperties.getSecurity().getBasicAuthPasswd();
// 
//         if(passwd != null && passwd.startsWith(VAULT_PREFIX)) {
//             String vaultPath = passwd.substring(VAULT_PREFIX.length());
//             basicAuthPasswd = vaultOperations.read(vaultPath).getData().get("value").toString();
//         } else {
//             basicAuthPasswd = passwd;
//         }
//     }
// 
//     public Optional<String> base64Encoded() {
//         if (basicAuthUser == null || basicAuthPasswd == null) {
//             return Optional.empty();
//         } else {
//             final String credentials = basicAuthUser + ":" + basicAuthPasswd;
//             return Optional.of(BASIC_PREFIX + Base64.getEncoder().encodeToString(credentials.getBytes()));
//         }
//     }
// }
// 
// Path: src/main/java/de/otto/edison/jobtrigger/security/BasicAuthHeaderProvider.java
// public class BasicAuthHeaderProvider implements AuthProvider {
// 
//     private final BasicAuthCredentials basicAuthCredentials;
// 
//     public BasicAuthHeaderProvider(BasicAuthCredentials basicAuthCredentials) {
//         this.basicAuthCredentials = basicAuthCredentials;
//     }
// 
//     @Override
//     public void setAuthHeader(BoundRequestBuilder requestBuilder) {
//         basicAuthCredentials.base64Encoded().ifPresent(encodedCredentials ->
//                 requestBuilder.setHeader(AUTHORIZATION_HEADER, encodedCredentials)
//         );
// 
//     }
// }


import de.otto.edison.jobtrigger.security.AuthProvider;
import de.otto.edison.jobtrigger.security.BasicAuthCredentials;
import de.otto.edison.jobtrigger.security.BasicAuthHeaderProvider;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.DefaultAsyncHttpClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;
package de.otto.edison.jobtrigger.configuration;


/**
 * @author Guido Steinacker
 * @since 05.09.15
 */
@Configuration
@EnableAsync
@EnableScheduling
@EnableConfigurationProperties(JobTriggerProperties.class)
public class JobTriggerConfiguration {

    @Bean
// Path: src/main/java/de/otto/edison/jobtrigger/security/AuthProvider.java
// public interface AuthProvider {
// 
//     void setAuthHeader(BoundRequestBuilder requestBuilder);
// }
// 
// Path: src/main/java/de/otto/edison/jobtrigger/security/BasicAuthCredentials.java
// @Component
// @EnableConfigurationProperties(JobTriggerProperties.class)
// public class BasicAuthCredentials {
// 
//     private static final String VAULT_PREFIX = "VAULT ";
//     public static String AUTHORIZATION_HEADER = "Authorization";
// 
//     private static final String BASIC_PREFIX = "Basic ";
// 
//     private final String basicAuthUser;
//     private final String basicAuthPasswd;
// 
//     @Autowired
//     public BasicAuthCredentials(final JobTriggerProperties jobTriggerProperties, final VaultOperations vaultOperations) {
//         basicAuthUser = jobTriggerProperties.getSecurity().getBasicAuthUser();
//         String passwd = jobTriggerProperties.getSecurity().getBasicAuthPasswd();
// 
//         if(passwd != null && passwd.startsWith(VAULT_PREFIX)) {
//             String vaultPath = passwd.substring(VAULT_PREFIX.length());
//             basicAuthPasswd = vaultOperations.read(vaultPath).getData().get("value").toString();
//         } else {
//             basicAuthPasswd = passwd;
//         }
//     }
// 
//     public Optional<String> base64Encoded() {
//         if (basicAuthUser == null || basicAuthPasswd == null) {
//             return Optional.empty();
//         } else {
//             final String credentials = basicAuthUser + ":" + basicAuthPasswd;
//             return Optional.of(BASIC_PREFIX + Base64.getEncoder().encodeToString(credentials.getBytes()));
//         }
//     }
// }
// 
// Path: src/main/java/de/otto/edison/jobtrigger/security/BasicAuthHeaderProvider.java
// public class BasicAuthHeaderProvider implements AuthProvider {
// 
//     private final BasicAuthCredentials basicAuthCredentials;
// 
//     public BasicAuthHeaderProvider(BasicAuthCredentials basicAuthCredentials) {
//         this.basicAuthCredentials = basicAuthCredentials;
//     }
// 
//     @Override
//     public void setAuthHeader(BoundRequestBuilder requestBuilder) {
//         basicAuthCredentials.base64Encoded().ifPresent(encodedCredentials ->
//                 requestBuilder.setHeader(AUTHORIZATION_HEADER, encodedCredentials)
//         );
// 
//     }
// }


// Path: src/main/java/de/otto/edison/jobtrigger/configuration/JobTriggerConfiguration.java
import de.otto.edison.jobtrigger.security.AuthProvider;
import de.otto.edison.jobtrigger.security.BasicAuthCredentials;
import de.otto.edison.jobtrigger.security.BasicAuthHeaderProvider;
import org.asynchttpclient.AsyncHttpClient;
import org.asynchttpclient.DefaultAsyncHttpClient;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableAsync;
import org.springframework.scheduling.annotation.EnableScheduling;

package de.otto.edison.jobtrigger.configuration;


/**
 * @author Guido Steinacker
 * @since 05.09.15
 */
@Configuration
@EnableAsync
@EnableScheduling
@EnableConfigurationProperties(JobTriggerProperties.class)
public class JobTriggerConfiguration {

    @Bean
    public AsyncHttpClient asyncHttpClient() {