简体   繁体   English

Grails:Spring Security插件对简单安全性是否功能强大

[英]Grails: Is the Spring Security Plugin Too Powerful for Simple Security

We have several Grails applications that use a shared plugin that among other things provides them with basic security. 我们有几个使用共享插件的Grails应用程序,这些插件除其他功能外还为它们提供基本的安全性。 We're going to be adding other types of authentication in the future so the idea of using the Spring Security plugin has come up. 将来我们将添加其他类型的身份验证,因此提出了使用Spring Security插件的想法。 However, I'm wondering if it's too powerful for our fairly basic needs. 但是,我想知道它对于我们的基本需求是否太强大了。

Currently we use Grails filters that run before any URL is accessed and perform security checks. 当前,我们使用Grails过滤器,该过滤器在访问任何URL之前运行并执行安全检查。 The initial authentication is handled by looking for a specific encrypted POST variable or cookie (being send from another closed source application) and after decrypting it, verifying the details in our database. 通过查找特定的加密POST变量或cookie(从另一个封闭的源应用程序发送)并解密后,验证数据库中的详细信息,来处理初始身份验证。 If everything checks out we consider the user logged in (and also have their numeric user ID from the encrypted data). 如果一切顺利,我们将认为该用户已登录(并从加密数据中获取了其数字用户ID)。 All of the users have the same access, except for a small handful that have greater access. 除了少数具有较大访问权限的用户外,所有用户都具有相同的访问权限。 These are defined in a table that contains their numerical ID. 这些在包含其数字ID的表中定义。

However, we're hoping to add the ability to log directly into these Grails applications by using Active Directory credentials, credentials provided by the closed sourced system's LDAP server, and in the not too distance future via a CAS server. 但是,我们希望通过使用Active Directory凭据,封闭源系统的LDAP服务器提供的凭据以及在不久的将来通过CAS服务器添加直接登录这些Grails应用程序的功能。

My initial approach was to look for libraries that allow the shared plugin to interface with these various systems and do simple authentication against them. 我最初的方法是寻找允许共享插件与这些各种系统连接并对其进行简单身份验证的库。 However, I noticed that Spring Security seems to have plugins for all these various types of authentication, which would speed up development. 但是,我注意到Spring Security似乎具有用于所有这些各种身份验证类型的插件,这将加快开发速度。 However, the module itself seems fairly complex and geared towards much more advanced setups which means we might spend a lot of time just setting up Spring Security in order to save time with their LDAP, CAS, etc. plugins. 但是,该模块本身似乎相当复杂,并且适用于更高级的设置,这意味着我们可能会花费大量时间来设置Spring Security,以节省使用LDAP,CAS等插件的时间。

Any thoughts/comments/etc. 任何想法/评论/等。 are highly appreciated. 非常感谢。

Also, if we were to use the Spring Security plugin, could someone please comment and let me know if the following kind of setup is possible ... 另外,如果我们要使用Spring Security插件,请有人发表评论并让我知道是否可以进行以下设置...

We'd like to avoid having to create database tables for the various applications for authentication purposes. 我们希望避免出于身份验证目的而为各种应用程序创建数据库表。 We basically would like to tell Spring Security that if a user passed authentication, they are authenticated. 我们基本上想告诉Spring Security,如果用户通过了身份验证,那么他们将被身份验证。 There are no roles, no groups, nothing fancy (except for the few applications that will have one extra role/group that provides a user with extra permissions ... for these applications a database table will obviously be needed). 没有角色,没有组,没有幻想(除了少数几个具有一个额外角色/组的应用程序可以为用户提供额外的权限……对于这些应用程序,显然需要数据库表)。

We'd also like to default to always requiring security for everything and add extra code only to suppress this to allow non authenticated access. 我们还希望默认情况下始终对所有内容都要求安全,并添加额外的代码只是为了禁止这种行为以允许未经身份验证的访问。 The idea behind this is that in case a developer forgets to add the Spring Security markup code to a controller or action it will already default to always needing authentication. 这背后的想法是,如果开发人员忘记将Spring Security标记代码添加到控制器或操作中,它将默认已经始终需要验证。

Also we'd still need to keep the original methods of authentication via en encrypted POST variable send from another application or an encrypted cookies. 同样,我们仍然需要通过从另一个应用程序发送的加密的POST变量或加密的cookie来保留原始身份验证方法。 Is it possible to build this into Spring Security? 是否可以将其内置到Spring Security中?

And lastly can the Spring Security plugin store a numeric user ID retrieved after authentication to identify the user instead storing the actual username that was used during the authentication? 最后,Spring Security插件可以存储身份验证后检索到的数字用户ID来标识用户,而不是存储身份验证期间使用的实际用户名吗?

Well, you have quite a lot of questions there within your post. 好吧,您的帖子中有很多问题。 I will do my best to answer the ones I can recall. 我将尽我所能回答那些我想起的问题。

Firstly, Spring Security is complex. 首先,Spring Security非常复杂。 That's because real security is hard. 那是因为真正的安全性很难。 However, Spring Security and to some extent the Grails plugin are both very configurable and customizable. 但是,Spring Security和Grails插件在某种程度上都是非常可配置和可定制的。 This will work to your advantage, once you get through the high learning curve. 一旦您掌握了较高的学习技巧,这将对您有利。

You will likely save yourself a lot of headaches and in the end time and effort by investing in Spring Security now, since your requirements are growing and becoming more complex. 由于您的需求不断增长并且变得越来越复杂,因此您现在就投资于Spring Security可能会为您省去很多麻烦,并最终节省时间和精力。

I would recommend reading the Spring Security documentation , the Spring Security Grails documentation and as many SO posts tagged with spring-security as you can. 我建议您阅读Spring Security文档Spring Security Grails文档以及尽可能多的带有spring-security标签的SO帖子。 It also wouldn't be a bad idea to invest in a few well written books covering Spring Security. 投资一些涵盖Spring Security的写得很好的书也不是一个坏主意。

Those are my high level thoughts/comments. 这些是我的高级想法/意见。

As far as what is possible with Spring security (your other questions). 尽可能地利用Spring安全性(您的其他问题)。

  1. Yes, you can setup Spring Security to not use any type of database tables. 是的,您可以将Spring Security设置为不使用任何类型的数据库表。
  2. You can write your won security authentication filter that does your custom authentication via params/etc. 您可以编写可通过params / etc进行自定义身份验证的安全认证过滤器。
  3. By default everything is locked down in the latest Grails Spring Security plugin, and if you use the interceptUrlMap you need only alter which URLs have no security or differing security than the default of IS_AUTHENTICATED_FULLY . 默认情况下,所有内容都在最新的Grails Spring Security插件中被锁定,并且如果您使用interceptUrlMap ,则只需更改哪些URL没有安全性或与默认IS_AUTHENTICATED_FULLY不同的安全性即可。
  4. Using a custom UserDetailsService and UserDetails you can use a numeric ID or any other details you want within your principal . 使用自定义的UserDetailsServiceUserDetails ,可以在principal使用数字ID或任何其他详细信息。

To summarize, with the right effort and understanding of Spring Security you can make it address your needs. 总之,通过正确的努力和对Spring Security的理解,您可以使其满足您的需求。 However, it's not a short and quick process and will require a lot of reading. 但是,这不是一个简短而快速的过程,需要大量阅读。

Well Springs Security is one of the best security plugins available nowadays. Well Springs Security是当今可用的最佳安全插件之一。 This is highly customizable and congigurable. 这是高度可定制和可配置的。

By default every url is locked in spring security. 默认情况下,每个URL都处于spring安全性中。 But you can set all url's unlocked by adding a configuration in config.groovy 但是您可以通过在config.groovy中添加配置来设置所有未锁定的url

grails.plugin.springsecurity.controllerAnnotations.staticRules = ['/**' : ['permitAll']]

the above will make all your url's accessible without logging in. No you can put restrictions on all the url's explicityle on controller level. 以上将使您无需登录即可访问所有url。不,您可以在控制器级别对所有url的显式类型进行限制。

  1. You need not have any Roles table in database, you can use an Enum insted if you have only Admin and User roles. 数据库中不需要任何角色表,如果只有管理员和用户角色,则可以使用枚举。
  2. You can even configure your sprigsecurity to use any column of the database to authenticate the user, be it a numeric or string type. 您甚至可以将sprigsecurity配置为使用数据库的任何列对用户进行身份验证,无论是数字类型还是字符串类型。 All you need to do is override the UserDetailsService and UserDetails service class. 您需要做的就是重写UserDetailsS​​ervice和UserDetails服务类。 BY this all your custom settings gets overriden over the original configurations. 这样,您所有的自定义设置都将覆盖原始配置。

Also we'd still need to keep the original methods of authentication via en encrypted POST variable send from another application or an encrypted cookies. 同样,我们仍然需要通过从另一个应用程序发送的加密的POST变量或加密的cookie来保留原始身份验证方法。 Is it possible to build this into Spring Security? 是否可以将其内置到Spring Security中?

for this also their is good support in springsecurity. 为此,他们也是springsecurity的良好支持。 you can have your authentication done at external sources and get it configured with sprinfsecurity. 您可以在外部来源进行身份验证,并使用sprinfsecurity对其进行配置。

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

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