1 package de.juplo.facebook.errors;
4 import org.slf4j.Logger;
5 import org.slf4j.LoggerFactory;
6 import org.springframework.beans.BeansException;
7 import org.springframework.beans.factory.config.BeanPostProcessor;
8 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
9 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
10 import org.springframework.boot.autoconfigure.security.oauth2.OAuth2AutoConfiguration;
11 import org.springframework.boot.autoconfigure.web.WebMvcAutoConfiguration;
12 import org.springframework.context.annotation.Bean;
13 import org.springframework.context.annotation.Configuration;
14 import org.springframework.security.oauth2.client.OAuth2RestTemplate;
15 import org.springframework.security.oauth2.client.http.OAuth2ErrorHandler;
19 * Automatic configuration for Srping-Security-OAuth2
24 @ConditionalOnClass(value = OAuth2RestTemplate.class)
26 WebMvcAutoConfiguration.class,
27 OAuth2AutoConfiguration.class
29 public class FacebookErrorsOAuth2AutoConfiguration
31 private static final Logger LOG =
32 LoggerFactory.getLogger(FacebookErrorsOAuth2AutoConfiguration.class);
35 static public BeanPostProcessor errorHandlerInjectorOAuth2()
37 LOG.info("Configuring OAuth2GraphApiErrorHandler for handling error-messages");
39 return new BeanPostProcessor()
42 public Object postProcessBeforeInitialization(
49 if (bean instanceof OAuth2RestTemplate)
51 LOG.debug("Injecting OAuth2GraphApiErrorHandler in {}", bean);
52 OAuth2RestTemplate template = (OAuth2RestTemplate) bean;
53 template.setErrorHandler(
54 new OAuth2GraphApiErrorHandler(
55 (OAuth2ErrorHandler)template.getErrorHandler()
64 public Object postProcessAfterInitialization(