I have a Spring MVC application which uses Spring Social Facebook to enable Facebook login. This is working fine on my local machine, but it currently doesn't work in my staging environment. My problem is that I cannot figure out what goes wrong. When I try to login, I am redirected to Facebook to authorize the application. This part works fine. But when I give authorize the app, all that happens is that I am redirected back to http://example.com/signin?error=provider#_=_
, which gives a 404 Not Found
error.
This is not terrible useful for debugging the source of the error, and looking through my Tomcat log files, I cannot find any information that could help me find the error. No stack traces, error messages or the like. I have enabled log4j in my project, but I do not see any logs from Spring Social. Actually I am not sure how to configure logging for Spring Social, but I tried the following in my log4j2.xml file:
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="DEBUG">
<Appenders>
<Console name="Console" target="SYSTEM_OUT">
<PatternLayout pattern="%d{HH:mm:ss.SSS} [%t] %-5level %logger{36} - %msg%n"/>
</Console>
</Appenders>
<Loggers>
<Logger name="com.example" level="trace">
<AppenderRef ref="Console" />
</Logger>
<Logger name="org.springframework.social" level="all">
<AppenderRef ref="Console" />
</Logger>
<Logger name="org.springframework.social.facebook" level="all">
<AppenderRef ref="Console" />
</Logger>
<Logger name="org.springframework.social.security" level="all">
<AppenderRef ref="Console" />
</Logger>
<Root level="error">
<AppenderRef ref="Console" />
</Root>
</Loggers>
</Configuration>
However, I do not see any Spring Social logs in my console. Logging works fine if I write to it in my application like below, so logging should be working OK.
@Controller
public class IndexController {
private static Logger logger = LogManager.getLogger(IndexController.class);
@RequestMapping("/")
public String home() {
logger.debug("Hello there from logger!");
return "home";
}
}
How do I configure logging for Spring Social? I found a few examples that configure log4j the way I do (e.g. one used for Spring Social tests), but otherwise nothing. I suppose the library supports this, because otherwise I don't know how to debug errors. Or is there any other way that I can find out what is triggering the error?
Below is my Spring Social configuration, even though I don't think it matters in this case.
@Configuration
public class SocialConfig {
@Autowired
private DataSource dataSource;
@Autowired
private TextEncryptor textEncryptor;
@Autowired
private AccountService accountService;
@Autowired
private AccountRepository accountRepository;
@Value("${facebook.app.id}")
private String facebookAppId;
@Value("${facebook.app.secret}")
private String facebookAppSecret;
@Bean
public ProviderSignInController providerSignInController() {
ProviderSignInController controller = new ProviderSignInController(this.connectionFactoryLocator(), this.usersConnectionRepository(), new SpringSecuritySignInAdapter(this.accountRepository));
controller.addSignInInterceptor(new RedirectToPreviousPageInterceptor(controller));
return controller;
}
@Bean
public ConnectionFactoryRegistry connectionFactoryLocator() {
ConnectionFactoryRegistry connectionFactoryRegistry = new ConnectionFactoryRegistry();
List<ConnectionFactory<?>> connectionFactories = new ArrayList<ConnectionFactory<?>>();
connectionFactories.add(this.facebookConnectionFactory());
connectionFactoryRegistry.setConnectionFactories(connectionFactories);
return connectionFactoryRegistry;
}
@Bean
public FacebookConnectionFactory facebookConnectionFactory() {
FacebookConnectionFactory connectionFactory = new FacebookConnectionFactory(this.facebookAppId, this.facebookAppSecret);
connectionFactory.setScope("email");
return connectionFactory;
}
@Bean
public JdbcUsersConnectionRepository usersConnectionRepository() {
JdbcUsersConnectionRepository repository = new JdbcUsersConnectionRepository(this.dataSource, this.connectionFactoryLocator(), this.textEncryptor);
repository.setConnectionSignUp(this.accountService);
return repository;
}
}
Thank you very much in advance.