// Path: src/main/java/com/thoughtworks/go/strongauth/config/Config.java
// @Configuration
// public class Config {
// 
//     private static final String CALL_FROM_SERVER_GET_CONFIGURATION = "go.plugin-settings.get-configuration";
//     private static final String CALL_FROM_SERVER_AUTHENTICATE_USER = "go.authentication.authenticate-user";
//     private static final String CALL_FROM_SERVER_PLUGIN_CONFIGURATION = "go.authentication.plugin-configuration";
//     private static final String CALL_FROM_SERVER_GET_VIEW = "go.plugin-settings.get-view";
//     private static final String CALL_FROM_SERVER_VALIDATE_CONFIGURATION = "go.plugin-settings.validate-configuration";
// 
//     @Bean
//     Handlers handlers(final AuthenticationHandler authenticationHandler) {
//         return new Handlers(
//                 ImmutableMap.of(
//                         CALL_FROM_SERVER_GET_CONFIGURATION, PluginSettingsHandler.getConfiguration(),
//                         CALL_FROM_SERVER_GET_VIEW, PluginSettingsHandler.getView(),
//                         CALL_FROM_SERVER_VALIDATE_CONFIGURATION, PluginSettingsHandler.validateConfiguration(),
//                         CALL_FROM_SERVER_PLUGIN_CONFIGURATION, new PluginConfigurationHandler(),
//                         CALL_FROM_SERVER_AUTHENTICATE_USER, authenticationHandler
// //            CALL_FROM_SERVER_SEARCH_USER, new SearchUserHandler(),
// //            CALL_FROM_SERVER_INDEX, new PluginIndexRequestHandler(accessorWrapper, goPluginIdentifier)
//                 )
//         );
//     }
// 
//     @Bean
//     AuthenticationHandler authenticationHandler(final Authenticator authenticator) {
//         return new AuthenticationHandler(
//                 new GoAuthenticationRequestDecoder(),
//                 authenticator,
//                 new GoUserEncoder()
//         );
//     }
// 
//     @Bean
//     Authenticator authenticator(
//             final PrincipalDetailSource principalDetailSource) {
//         return new Authenticator(principalDetailSource, hashProviders());
//     }
// 
//     @Bean
//     List<? extends HashProvider> hashProviders() {
//         return ImmutableList.of(
//                 new PBESpecHashProvider(),
//                 new BCryptProvider()
//         );
//     }
// 
//     @Bean
//     ComponentFactory componentFactory(final Handlers handlers) {
//         return new ComponentFactory(handlers);
//     }
// 
//     @Bean
//     PrincipalDetailSource principalSource(final InputStreamSource inputStreamSource) {
//         return new ConfigurableUserPrincipalDetailSource(inputStreamSource);
//     }
// 
//     @Bean
//     ConfigurationMonitor configurationMonitor(final GoAPI goAPI) {
//         return new ConfigurationMonitor(goAPI);
//     }
// 
//     @Bean
//     InputStreamSource inputStreamSource(final ConfigurationMonitor configurationMonitor) {
//         return new ConfigFileMonitor(configurationMonitor);
//     }
// 
//     @Bean
//     GoAPI goAPI(@SuppressWarnings("SpringJavaAutowiringInspection") final GoPluginIdentifier goPluginIdentifier,
//                 @SuppressWarnings("SpringJavaAutowiringInspection") final GoApplicationAccessor goApplicationAccessor,
//                 final PluginConfigurationDecoder pluginConfigurationDecoder
// 
//     ) {
//         return new GoAPI(goPluginIdentifier, goApplicationAccessor, pluginConfigurationDecoder);
//     }
// 
//     @Bean
//     PluginConfigurationDecoder pluginConfigurationDecoder() {
//         return new PluginConfigurationDecoder();
//     }
// 
// }
// 
// Path: src/main/java/com/thoughtworks/go/strongauth/handlers/Handlers.java
// public class Handlers {
// 
//     private final Map<String, Handler> handlers;
// 
//     public Handlers(final Map<String, Handler> handlers) {
//         this.handlers = handlers;
//     }
// 
//     public Handler get(String requestName) {
//         if (handlers.containsKey(requestName)) {
//             return handlers.get(requestName);
//         }
//         throw new RuntimeException(format("Handler for request of type: %s is not implemented", requestName));
//     }
// }


import com.thoughtworks.go.plugin.api.GoApplicationAccessor;
import com.thoughtworks.go.plugin.api.GoPluginIdentifier;
import com.thoughtworks.go.strongauth.config.Config;
import com.thoughtworks.go.strongauth.handlers.Handlers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
package com.thoughtworks.go.strongauth;


public class ComponentFactory {

    private final Handlers handlers;

    @Autowired
    public ComponentFactory(Handlers handlers) {
        this.handlers = handlers;
    }

    public static ComponentFactory create(GoApplicationAccessor goApplicationAccessor, GoPluginIdentifier goPluginIdentifier) {
        try {
            AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
            ctx.setClassLoader(ComponentFactory.class.getClassLoader());
// Path: src/main/java/com/thoughtworks/go/strongauth/config/Config.java
// @Configuration
// public class Config {
// 
//     private static final String CALL_FROM_SERVER_GET_CONFIGURATION = "go.plugin-settings.get-configuration";
//     private static final String CALL_FROM_SERVER_AUTHENTICATE_USER = "go.authentication.authenticate-user";
//     private static final String CALL_FROM_SERVER_PLUGIN_CONFIGURATION = "go.authentication.plugin-configuration";
//     private static final String CALL_FROM_SERVER_GET_VIEW = "go.plugin-settings.get-view";
//     private static final String CALL_FROM_SERVER_VALIDATE_CONFIGURATION = "go.plugin-settings.validate-configuration";
// 
//     @Bean
//     Handlers handlers(final AuthenticationHandler authenticationHandler) {
//         return new Handlers(
//                 ImmutableMap.of(
//                         CALL_FROM_SERVER_GET_CONFIGURATION, PluginSettingsHandler.getConfiguration(),
//                         CALL_FROM_SERVER_GET_VIEW, PluginSettingsHandler.getView(),
//                         CALL_FROM_SERVER_VALIDATE_CONFIGURATION, PluginSettingsHandler.validateConfiguration(),
//                         CALL_FROM_SERVER_PLUGIN_CONFIGURATION, new PluginConfigurationHandler(),
//                         CALL_FROM_SERVER_AUTHENTICATE_USER, authenticationHandler
// //            CALL_FROM_SERVER_SEARCH_USER, new SearchUserHandler(),
// //            CALL_FROM_SERVER_INDEX, new PluginIndexRequestHandler(accessorWrapper, goPluginIdentifier)
//                 )
//         );
//     }
// 
//     @Bean
//     AuthenticationHandler authenticationHandler(final Authenticator authenticator) {
//         return new AuthenticationHandler(
//                 new GoAuthenticationRequestDecoder(),
//                 authenticator,
//                 new GoUserEncoder()
//         );
//     }
// 
//     @Bean
//     Authenticator authenticator(
//             final PrincipalDetailSource principalDetailSource) {
//         return new Authenticator(principalDetailSource, hashProviders());
//     }
// 
//     @Bean
//     List<? extends HashProvider> hashProviders() {
//         return ImmutableList.of(
//                 new PBESpecHashProvider(),
//                 new BCryptProvider()
//         );
//     }
// 
//     @Bean
//     ComponentFactory componentFactory(final Handlers handlers) {
//         return new ComponentFactory(handlers);
//     }
// 
//     @Bean
//     PrincipalDetailSource principalSource(final InputStreamSource inputStreamSource) {
//         return new ConfigurableUserPrincipalDetailSource(inputStreamSource);
//     }
// 
//     @Bean
//     ConfigurationMonitor configurationMonitor(final GoAPI goAPI) {
//         return new ConfigurationMonitor(goAPI);
//     }
// 
//     @Bean
//     InputStreamSource inputStreamSource(final ConfigurationMonitor configurationMonitor) {
//         return new ConfigFileMonitor(configurationMonitor);
//     }
// 
//     @Bean
//     GoAPI goAPI(@SuppressWarnings("SpringJavaAutowiringInspection") final GoPluginIdentifier goPluginIdentifier,
//                 @SuppressWarnings("SpringJavaAutowiringInspection") final GoApplicationAccessor goApplicationAccessor,
//                 final PluginConfigurationDecoder pluginConfigurationDecoder
// 
//     ) {
//         return new GoAPI(goPluginIdentifier, goApplicationAccessor, pluginConfigurationDecoder);
//     }
// 
//     @Bean
//     PluginConfigurationDecoder pluginConfigurationDecoder() {
//         return new PluginConfigurationDecoder();
//     }
// 
// }
// 
// Path: src/main/java/com/thoughtworks/go/strongauth/handlers/Handlers.java
// public class Handlers {
// 
//     private final Map<String, Handler> handlers;
// 
//     public Handlers(final Map<String, Handler> handlers) {
//         this.handlers = handlers;
//     }
// 
//     public Handler get(String requestName) {
//         if (handlers.containsKey(requestName)) {
//             return handlers.get(requestName);
//         }
//         throw new RuntimeException(format("Handler for request of type: %s is not implemented", requestName));
//     }
// }


// Path: src/main/java/com/thoughtworks/go/strongauth/ComponentFactory.java
import com.thoughtworks.go.plugin.api.GoApplicationAccessor;
import com.thoughtworks.go.plugin.api.GoPluginIdentifier;
import com.thoughtworks.go.strongauth.config.Config;
import com.thoughtworks.go.strongauth.handlers.Handlers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

package com.thoughtworks.go.strongauth;


public class ComponentFactory {

    private final Handlers handlers;

    @Autowired
    public ComponentFactory(Handlers handlers) {
        this.handlers = handlers;
    }

    public static ComponentFactory create(GoApplicationAccessor goApplicationAccessor, GoPluginIdentifier goPluginIdentifier) {
        try {
            AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
            ctx.setClassLoader(ComponentFactory.class.getClassLoader());
            ctx.register(Config.class);