有没有办法在grails应用程序中添加第三方servlet?

问题描述:

我是grails新手,想知道是否有方法在grails应用程序中添加第三方servlet?有没有办法在grails应用程序中添加第三方servlet?

我正尝试在grails中使用Waffle。我能够成功利用春季安全使用华夫在MVC应用程序如下所述:https://github.com/dblock/waffle/blob/master/Docs/spring/SpringSecurityAuthenticationProvider.md

在我的MVC应用程序,我能够加豆这样的认证:

<bean id="waffleNegotiateSecurityFilter" class="waffle.spring.NegotiateSecurityFilter"> 
    <property name="provider" ref="waffleSecurityFilterProviderCollection"/> 
    <property name="allowGuestLogin" value="false"/> 
    <property name="principalFormat" value="fqn"/> 
    <property name="roleFormat" value="both"/> 
</bean> 
+0

您是否尝试过使用DSL向您的grails-app/conf/spring/resources.groovy添加bean声明? – Gregg 2013-02-22 01:43:13

+0

以下提供的链接,您不需要添加任何额外的过滤器。只需配置Spring Security,可以使用标准的Spring Security插件 – 2013-02-22 05:11:10

+0

@IgorArtamonov今天下午我将尝试这种方法。我会回报。谢谢 – Omnipresent 2013-02-22 14:56:35

你必须添加过滤器映射到web.xml

使用Grails命令

> grails install-templates 

比编辑web.xml文件(内侧的src /模板)安装的web.xml

并添加您向我们显示的文档所述的映射。

然后加豆定义Grails的资源

/conf/spring/resources.groogy 

XML转换bean定义到Grails的春天常规DSL可能会有点困难。如果您有任何问题,请参阅指南about grails and spring或在此处询问。

+1

您可以在grails-app/conf/spring/resources.xml中按原样使用XML bean配置,您不必将其转换为groovy。 – 2013-02-22 09:41:48

+0

你是对的伊恩......但groovy是如此的美丽:) – 2013-02-22 09:51:33

我刚才已与此挣扎了几天,结束了做以下的普通的Grails 2.4.4项目:

grails create-app 
grails install-templates 

然后修改BuildConfig.groovy

dependencies { 
... 
compile "com.google.guava:guava:18.0" 
compile "com.github.dblock.waffle:waffle-jna:1.7.3" 
compile "net.java.dev.jna:jna:4.1.0" 
compile "net.java.dev.jna:jna-platform:4.1.0" 
compile "org.slf4j:slf4j-api:1.7.9" 
.... 

}

我然后创建的context.xml下面 .. \ META-INF具有以下内容:

<?xml version='1.0' encoding='utf-8'?> 
<!DOCTYPE Context> 
<Context> 
    <Valve className="waffle.apache.NegotiateAuthenticator" principalFormat="fqn" roleFormat="both" protocols="Negotiate,NTLM" /> 
    <Realm className="waffle.apache.WindowsRealm" /> 
</Context> 

,然后添加以下到.. \模板\的web.xml文件

<display-name>/@[email protected]</display-name> 
<security-constraint> 
    <display-name>Waffle Security Constraint</display-name> 
    <web-resource-collection> 
     <web-resource-name>Protected Area</web-resource-name> 
     <url-pattern>/</url-pattern> 
     <http-method>DELETE</http-method> 
     <http-method>GET</http-method> 
     <http-method>POST</http-method> 
     <http-method>PUT</http-method> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>Everyone</role-name> 
    </auth-constraint> 
</security-constraint> 
<security-role> 
    <role-name>Everyone</role-name> 
</security-role> 
.... 
.... 

为了验证其实际工作,我添加一行index.gsp中

<p>You are logged in as remote user <b>${request.getRemoteUser()}</b> in session <b>${session.getId()}</b>.</p> 

我测试这个Tomcat的7.0.57下,不得不添加一些罐子TH e Tomcat lib让我工作。我加了slf4j-api-1.7.9.jar,guava-18.0.jar,jna-platform-4.1.0.jar,jna-4.1.0.jar,waffle-tomcat7-1.7.3.jar,waffle-jna -1.7.3.jar。仍然想知道为什么在将相同的罐子添加到BuildConfig.groovy时实际上有必要这样做。