SocialSignOnAutoConfiguration.java 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. * Copyright [2020] [MaxKey of copyright http://www.maxkey.top]
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. package org.maxkey.autoconfigure;
  17. import java.io.IOException;
  18. import org.maxkey.authn.support.socialsignon.service.JdbcSocialsAssociateService;
  19. import org.maxkey.authn.support.socialsignon.service.SocialSignOnProviderService;
  20. import org.maxkey.entity.SocialsProvider;
  21. import org.slf4j.Logger;
  22. import org.slf4j.LoggerFactory;
  23. import org.springframework.beans.factory.InitializingBean;
  24. import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
  25. import org.springframework.context.annotation.Bean;
  26. import org.springframework.context.annotation.ComponentScan;
  27. import org.springframework.context.annotation.Configuration;
  28. import org.springframework.jdbc.core.JdbcTemplate;
  29. @Configuration
  30. @ComponentScan(basePackages = {
  31. "org.maxkey.authn.support.socialsignon"
  32. })
  33. public class SocialSignOnAutoConfiguration implements InitializingBean {
  34. private static final Logger _logger = LoggerFactory.getLogger(SocialSignOnAutoConfiguration.class);
  35. @Bean(name = "socialSignOnProviderService")
  36. @ConditionalOnClass(SocialsProvider.class)
  37. public SocialSignOnProviderService socialSignOnProviderService(
  38. JdbcTemplate jdbcTemplate) throws IOException {
  39. SocialSignOnProviderService socialSignOnProviderService = new SocialSignOnProviderService(jdbcTemplate);
  40. //load Socials Providers from database
  41. socialSignOnProviderService.loadSocialsProviders();
  42. _logger.debug("SocialSignOnProviderService inited.");
  43. return socialSignOnProviderService;
  44. }
  45. @Bean(name = "socialsAssociateService")
  46. public JdbcSocialsAssociateService socialsAssociateService(
  47. JdbcTemplate jdbcTemplate) {
  48. JdbcSocialsAssociateService socialsAssociateService = new JdbcSocialsAssociateService(jdbcTemplate);
  49. _logger.debug("JdbcSocialsAssociateService inited.");
  50. return socialsAssociateService;
  51. }
  52. @Override
  53. public void afterPropertiesSet() throws Exception {
  54. }
  55. }