简体   繁体   English

使用 Broadleaf 进行 Spring 社交登录

[英]Spring Social Login with Broadleaf

I am looking to provide the Facebook and Gmail login on Broadleaf application for which i am referring the below mentioned link我希望在 Broadleaf 应用程序上提供 Facebook 和 Gmail 登录信息,我指的是下面提到的链接

https://www.broadleafcommerce.com/blog/why-your-ecommerce-site-should-integrate-with-spring-social https://www.broadleafcommerce.com/blog/why-your-ecommerce-site-should-integrate-with-spring-social

however the link is quite older, can anyone please help me to send a link or pointers to do Spring Social login with Broadleaf version 5.2但是链接很旧,任何人都可以帮我发送一个链接或指针来使用 Broadleaf 5.2 版进行 Spring Social 登录

Thanks in advance提前致谢

I have not actually implemented this, but I think I can provide some pointers.我还没有真正实现这一点,但我想我可以提供一些指导。 The steps below are taken from the blog post.以下步骤取自博客文章。 In general, the blog post is still correct, but declaring beans has moved from XML to Java since that post was written.总的来说,这篇博文仍然是正确的,但自那篇博文撰写以来,声明 bean 已经从 XML 转移到了 Java。

1) Add the Spring Social dependencies to your root POM 1) 将 Spring Social 依赖项添加到您的根 POM

Follow the blog post.关注博文。

You may want to update to the newest version of Spring Social (1.1.6 as of Jan 2020).您可能希望更新到最新版本的 Spring Social(截至 2020 年 1 月为 1.1.6)。 Consult the Spring Social Documentation for updated dependencies.有关更新的依赖项,请参阅Spring 社交文档 Specifically, you would need to add an additional dependency from what the blog post listed:具体来说,您需要从博客文章列出的内容中添加额外的依赖项:

<dependency>
    <groupId>org.springframework.social</groupId>
    <artifactId>spring-social-core</artifactId>
    <version>1.1.6.RELEASE</version>
</dependency>

The latest spring-social-facebook is 1.1.1 and the latest spring-social-twitter is 1.1.2.最新的 spring-social-facebook 是 1.1.1,最新的 spring-social-twitter 是 1.1.2。

2) Create a new applicationContext-social.xml 2)新建一个applicationContext-social.xml

This is the step with the biggest changes.这是变化最大的一步。 Broadleaf 5.2 supports declaring beans using Spring's @Configuration annotation on classes. Broadleaf 5.2 支持在类上使用 Spring 的 @Configuration 注解来声明 bean。 This means that the beans defined in XML from the blog post can be defined in Java in a @Configuration class for Broadleaf 5.2.这意味着博客文章中用 XML 定义的 bean 可以在 Broadleaf 5.2 的 @Configuration 类中用 Java 定义。

The bean definitions for applicationContext-social.xml could be added to SiteConfig.java (or to aa new configuration class that gets component scanned from SiteConfig), and the bean definition for applicationContext-servlet.xml would go in SiteServletConfig. applicationContext-social.xml 的 bean 定义可以添加到 SiteConfig.java(或添加到从 SiteConfig 扫描组件的新配置类),applicationContext-servlet.xml 的 bean 定义将进入 SiteServletConfig。

Here is an example of the first bean listed in the blog post as Java configuration:这是博客文章中作为 Java 配置列出的第一个 bean 的示例:

@Value("${facebook.clientId}")
private String facebookClientId;

@Value("${facebook.clientSecret}")
private String facebookClientSecret;

@Value("${twitter.consumerKey}")
private String twitterConsumerKey;

@Value("${twitter.consumerSecret}")
private String twitterConsumerSecret;

@Bean
public ConnectionFactoryRegistry connectionFactoryLocator() {
    FacebookConnectionFactory facebookConnectionFactory = new FacebookConnectionFactory(facebookClientId, facebookClientSecret);
    TwitterConnectionFactory twitterConnectionFactory = new TwitterConnectionFactory(twitterConsumerKey, twitterConsumerSecret);

    ConnectionFactoryRegistry connectionFactoryRegistry = new ConnectionFactoryRegistry();
    connectionFactoryRegistry.setConnectionFactories(Arrays.asList(facebookConnectionFactory, twitterConnectionFactory));
    return connectionFactoryRegistry;
}

The entry for applicationContext-security.xml would go in SiteSecurityConfig, but it will need to be updated to comply with the new standards of Spring Security Java configuration. applicationContext-security.xml 的条目将进入 SiteSecurityConfig,但需要更新以符合 Spring Security Java 配置的新标准。 The configuration snippet from the blog post <sec:intercept-url pattern="/signin/**" requires-channel="https" /> simply requires that URLs under /signin are served over https.博客文章<sec:intercept-url pattern="/signin/**" requires-channel="https" />的配置片段只要求 /signin 下的 URL 通过 https 提供。 Serving the entire site over https has become standard since the blog post was written in 2012, so this step may not be necessary if your site is already doing that.自 2012 年撰写博客文章以来,通过 https 为整个站点提供服务已成为标准,因此如果您的站点已经这样做,则此步骤可能没有必要。 Looking at our reference Heat Clinic application, its SiteSecurityConfig.java is already configured to serve all URLs over https.查看我们的参考 Heat Clinic 应用程序,其 SiteSecurityConfig.java 已配置为通过 https 提供所有 URL。

If you do need to add an entry, in SiteSecurityConfig.java, find the method configure(HttpSecurity http) and add this to the configuration:如果确实需要添加条目,请在 SiteSecurityConfig.java 中找到方法configure(HttpSecurity http)并将其添加到配置中:

.requiresChannel()
    .antMatchers("/signin/**")
    .requiresSecure()

You can also add the String /signin/** to an existing requiresChannel antMatcher if it exists.您还可以将字符串/signin/** signin /signin/**添加到现有的requiresChannel antMatcher(如果存在)。

3) Modify your Broadleaf Runtime Properties 3) 修改您的 Broadleaf 运行时属性

Same as blog post与博客文章相同

4) Add your new applicationContext-social.xml to web.xml 4) 将您的新 applicationContext-social.xml 添加到 web.xml

This step is not necessary when using component scanning.使用组件扫描时不需要此步骤。 I doubt you are using a web.xml file with Broadleaf 5.2.我怀疑您使用的是 Broadleaf 5.2 的 web.xml 文件。

5) Change your RegisterController to extend BroadleafSocialRegisterController 5) 更改您的 RegisterController 以扩展 BroadleafSocialRegisterController

Same as blog post.与博客文章相同。 You can see the framework controller at org.broadleafcommerce.core.web.controller.account.BroadleafSocialRegisterController你可以在org.broadleafcommerce.core.web.controller.account.BroadleafSocialRegisterController看到框架控制器

6) Finally, add the sign in buttons to your login page 6) 最后,将登录按钮添加到您的登录页面

Same as blog post.与博客文章相同。 Adapt to your site's HTML.适应您网站的 HTML。

I hope this helps.我希望这有帮助。 Feel free to ask any follow up questions.随时提出任何后续问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM