【问题标题】:Grails 3 - Security without pluginsGrails 3 - 没有插件的安全性
【发布时间】:2018-09-19 04:47:26
【问题描述】:

我正在一个 Grails 3.x 应用程序上使用 SAML 实现 Spring Security,而不使用插件。

我已经添加了必要的罐子如下:

     compile group: 'ca.juliusdavies', name: 'not-yet-commons-ssl', version: '0.3.17'
     compile 'org.opensaml:opensaml:2.6.0'
     compile 'org.opensaml:openws:1.4.1'
     compile 'org.opensaml:xmltooling:1.3.1'
     compile group: 'org.springframework.security', name: 'spring-security-core', version: '3.2.5.RELEASE'
     compile group: 'org.springframework.security', name: 'spring-security-config', version: '3.2.5.RELEASE'
     compile group: 'org.springframework.security.extensions', name: 'spring-security-saml2-core', version: '1.0.5.BUILD-SNAPSHOT'

我的 securitycontext.xml 文件集成在 resources.groovy 中。

beans = {
        importBeans('classpath:security/springSecuritySamlBeans.xml')
}

我需要在我的 web.xml 中添加以下安全过滤器,但在 Grails 3 中这是不可能的。谁能建议需要在哪里添加这些安全过滤器以及如何添加它们。

<filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

根据我的阅读,这些过滤器需要在 resources.groovy 中定义,但我不确定这是如何完成的。

【问题讨论】:

标签: spring grails spring-security


【解决方案1】:

在我看来,这听起来仍然很麻烦。与其进行这项工作并且您不清楚发生了什么,不如将您的用户注册工作流程委托给第三方服务,例如 Firebase。

使用拦截器来编写。

【讨论】:

  • “在我看来,这听起来仍然很麻烦。” - 我不明白那个评论。问题与不知道如何在 Grails 3 中注册 servlet 过滤器有关,解决方案是在 resources.groovy 中添加一条语句。这似乎并不麻烦,并且是记录在案的关于如何在 Grails 3 中注册 servlet 过滤器的最佳实践。
  • 如果问题是关于管理注册工作流程的最佳实践是什么,这里给出的答案会更合适。它仍然不是我会同意的答案,但它至少是对这个问题的有效答案。照原样,这并不能回答所提出的问题。
【解决方案2】:

我需要在我的 web.xml 中添加以下安全过滤器,但在 Grails 3 这是不可能的。

您可能不需要将它们添加到web.xml。您可能只需要将它们应用到您的应用程序中。在 Grails 3 中实现这一点的一种方法是使用 FilterRegistrationBean。有关几个示例,请参阅https://github.com/grails/grails-core/blob/6b30c22ac9a3758bde53844f807ea781ca7e3c9d/grails-plugin-controllers/src/main/groovy/org/grails/plugins/web/controllers/ControllersGrailsPlugin.groovy#L93-L112。您可能想在您应用的resources.groovy 中执行类似的操作。

【讨论】:

    猜你喜欢
    • 2016-07-15
    • 2015-05-30
    • 2017-10-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-26
    • 2017-01-01
    • 2011-04-16
    相关资源
    最近更新 更多