简体   繁体   English

Grails 3和Spring Security Plugin

[英]Grails 3 and Spring Security Plugin

I've just recently started working with Grails, and I'd like to test out the Spring Security Plugin. 我刚刚开始使用Grails,我想测试Spring Security Plugin。 I'm using Grails v3.0.0RC2, and I'm finding it difficult to come across accurate documentation for it with a lot of things. 我正在使用Grails v3.0.0RC2,我发现很难找到很多准确的文档。

I'm looking at the Grails page for the Spring Security Plugin, located at http://grails.org/plugin/spring-security-core , and it tells me to add the following to grails-app/conf/BuildConfig 我正在查看位于http://grails.org/plugin/spring-security-core的Spring Security插件的Grails页面,它告诉我将以下内容添加到grails-app / conf / BuildConfig

plugins {
  …
  compile ':spring-security-core:2.0-RC4'
  …
}

Now, Grails 3 has done away with the BuildConfig, and moved over to using Gradle. 现在,Grails 3已经废除了BuildConfig,并转而使用Gradle。 So I figured I could just that compile line to my "dependencies" section in build.gradle and it would work, like so: 所以我想我可以将编译行编译到build.gradle中的“dependencies”部分,它会起作用,如下所示:

dependencies{
  ...
  compile:":spring-security-core:2.0-RC4"
}

However, that did not work. 但是,这没有用。 I get the error "Could not find :spring-security-core:2.0-RC4...". 我收到错误“找不到:spring-security-core:2.0-RC4 ......”。

Then I figured, 'Hey, it's a plugin, let me try prefacing it with "org.grails.plugins" like I see elsewhere in the build.gradle file: 然后我想,'嘿,这是一个插件,让我尝试用“org.grails.plugins”作为前缀,就像我在build.gradle文件中看到的那样:

dependencies{
  ...
  compile:"org.grails.plugins:spring-security-core:2.0-RC4"
}

And still no go. 但仍然没有去。

I have gotten it to compile by adding the dependency found on search.maven.org, like so: 我已经通过添加search.maven.org上的依赖项来编译它,如下所示:

dependencies{
  ...
  compile 'org.springframework.security:spring-security-core:4.0.0.RELEASE'
}

But I don't think thats the proper way to do, because Grails documentation says I should have access to the command 但我不认为这是正确的方法,因为Grails文档说我应该有权访问该命令

grails s2-quickstart

once the plugin is installed, which I do not when I do it using the Maven repo. 一旦安装了插件,我不会在使用Maven repo时执行此操作。

I'm sure there's a simple configuration error I'm making, as I'm very new to both Grails, Spring, and Gradle, so I appreciate any help that can be provided. 我确信我正在制作一个简单的配置错误,因为我对Grails,Spring和Gradle都很新,所以我感谢任何可以提供的帮助。

The Spring Secuirty core plugin for Grails is not Grails 3 compatible. Grails的Spring Secuirty核心插件不兼容Grails 3。 However, since Grails 3 is based on Spring Boot you can use the Spring Security Starter for Spring Boot instead. 但是,由于Grails 3基于Spring Boot,因此您可以使用Spring Security Starter进行Spring Boot

This has been discussed on the Grails developers mailing list and going forward many Grails plugins will not be moved to Grails 3 and instead will be replaced by pure Spring solutions. 这已经在Grails开发人员邮件列表中进行了讨论 ,并且许多Grails插件将不会被移动到Grails 3,而是将被纯Spring解决方案取代。

Update 更新

Since this question was originally asked there has been a Spring Security plugin created for Grails 3.x. 由于这个问题最初被问到,为Grails 3.x创建了一个Spring Security插件。 It can be found here: https://bintray.com/grails/plugins/spring-security-core/view 它可以在这里找到: https//bintray.com/grails/plugins/spring-security-core/view

“Spring Boot Starter for Spring Boot”是一个很好的起点,但是如果你想节省一些时间试图弄清楚如何让它与Grails一起使用,请查看这篇有用的博客文章

我写 @Jamie在他的回答中引用的博客文章 ,我添加了一篇新的博客文章,描述了如何使用Grails 2中的Spring-Security-Core插件中的Gorm域类。

dependencies {
     ...
     compile 'org.grails.plugins:spring-security-core:3.0.4'
     ...
}

This is what I used and it worked for me 这是我使用的,它对我有用

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

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