在另一个插件中覆盖插件GSP和控制器 [英] Overwrite a plugin GSP and Controller within another Plugin

查看:127
本文介绍了在另一个插件中覆盖插件GSP和控制器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的项目中有一个相当复杂的grails插件依赖关系结构,我有问题覆盖安全插件中的类。



我的结构有点像这样:

  Web App 
| _审计插件
| _ Spring安全核心插件
| _安全包装插件
| _审计插件
| _ Spring安全核心插件

它的原因是审计在一些具有安全包装的应用程序之间共享,有些则不包含,这就是为什么它需要安全核心(它至少需要获得当前主体的能力)。

类似地,包装器在多个web应用程序之间共享,因此我们把它在一个插件中。我的问题出现在将Spring-Security-Core升级到版本2之后。



我的包装有一个customer auth.gsp和LoginController.groovy。在旧版本的安全性中,这很好,因为插件对这些插件进行了模板化,并使它们在安装插件的源代码中可用。然而,现在这些文件是插件内部的,尽管我知道你可以在主应用程序中覆盖它们,但是当试图在另一个插件中覆盖它们时,我会遇到一些奇怪的现象结果。

登录页面的Spring-Security-Core版本总是会覆盖我的自定义登录页面。我无法让我的优先。第二个问题是Spring-Security-Core插件中的LoginController.groovy有时优先于包装器中的LoginController.groovy。关于哪一个将被使用,在构建之间似乎几乎是随机的。



是否有任何正确的方法可以确保我的视图和控制器优先?

解决方案

OK玩弄事物我发现了一个似乎适用于我的解决方案:



首先,我无法改变插件的加载顺序,因为安全包装器对Spring bean做了很多工作,并且必须在核心插件之后加载才能使用。因此,在( DefaultSecurityConfig.groovy )我注意到你可以设置下列属性:

  grails.plugin。 springsecurity.failureHandler.defaultFailureUrl ='/ login / authfail? login_error = 1'
grails.plugin.springsecurity.failureHandler.ajaxAuthFailUrl ='/ login / authfail?ajax = true'
grails.plugin.springsecurity.auth.loginFormUrl ='/ login / auth'

因此,我创建了一个自定义控制器和登录页面,它们与核心插件中使用的名称不同,将这些属性更改为指向我的位置。

为了覆盖这个,在包装器的UrlMappings(名为:SecWrapperUrlMappings)中,我将映射从/ login / **映射到/seclogin/**.



确保这些新位置未被锁定,以便人们可以访问它们,并且似乎可以正常工作。我现在可靠的知道,无论他们加载在我的登录页面和登录控制器的订单。


I have a fairly complicated grails plugin dependency structure within my project and I am having problems overriding classes from the security plugin.

My structure is a little something like this:

Web App
 |_ Audit Plugin
     |_ Spring Security Core Plugin
 |_ Security Wrapper Plugin
     |_ Audit Plugin
     |_ Spring Security Core Plugin

The reason it is like this is audit is shared between some apps which have the security wrapper, and some what don't, which is why it pulls in Security-Core (it needs at least the ability to get the current principal).

Similarly the wrapper is shared between multiple web apps therefore we put it in a plugin. My problem comes after upgrading Spring-Security-Core to version 2.

My wrapper has a customer auth.gsp and LoginController.groovy. In the older version of security this was fine, as the plugin templated those and made them available in the source of the installing plugin.

However now these files are internal to the plugin, and although I know you can override them within the main app, when trying to override them within another plugin I get some bizarre results.

The Spring-Security-Core version of the login page always overrides my custom login page. I cannot get mine to take precedence.

The second problem is that the LoginController.groovy from the Spring-Security-Core plugin sometimes takes precedence over my one from the wrapper. It seems almost random between builds as to which one will be in use.

Is there any correct way to go about making sure my views and controllers take precedence?

解决方案

OK playing around with things I found a solution that seems to work for me:

Firstly I couldn't change the order in which the plugins load because the security wrapper does a lot with spring beans and it has to load after the core plugin for this to work. So after a bit of digging in the (DefaultSecurityConfig.groovy) I noticed that you can set the following properties:

grails.plugin.springsecurity.failureHandler.defaultFailureUrl = '/login/authfail?   login_error=1'
grails.plugin.springsecurity.failureHandler.ajaxAuthFailUrl = '/login/authfail?ajax=true'
grails.plugin.springsecurity.auth.loginFormUrl = '/login/auth'

So I created a custom controller and login page which have a different name to the ones use in the core plugin and changed these properties to point to my locations.

To neaten this up, in the UrlMappings for the wrapper (named: SecWrapperUrlMappings) I put a mapping from /login/** to /seclogin/**.

Make sure that these new locations aren't locked down so that people can access them and that seems to work well. I now reliable know, whichever order they load in my login page and login controller are used.

这篇关于在另一个插件中覆盖插件GSP和控制器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆