Question

I'm new to grails and wondering whether there is a way to add a third party servlet in a grails application?

I'm trying to use Waffle with grails. I was successfully able to use Waffle in an MVC app using spring security as described here: https://github.com/dblock/waffle/blob/master/Docs/spring/SpringSecurityAuthenticationProvider.md

In my MVC app I was able to add beans like this for authentication:

<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>
Was it helpful?

Solution

You have to add filters mapping to web.xml

install web.xml using grails command

> grails install-templates

Than edit web.xml file (inside src/templates )

and add the mapping as stated by the documentation you showed us.

Then add beans definition to grails resources

/conf/spring/resources.groogy

Translating xml bean definition to grails spring groovy DSL can be a little difficult. If you have any problem refear to the guide about grails and spring or ask here.

OTHER TIPS

I have just been struggling with this for a few days and ended up with doing the following in a plain Grails 2.4.4 project:

grails create-app
grails install-templates

Then modification of 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"
....

}

I then created context.xml below ..\META-INF with the following content:

<?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>

And then added the following to the ..\templates\web.xml file:

<display-name>/@grails.project.key@</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>
....
....

To verify that it actually worked, I added a line to index.gsp

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

I tested this under Tomcat 7.0.57 and had to add some jars to the Tomcat lib to get i to work. I added 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. Still wonder why this is actually necessary when the same jars are also added to BuildConfig.groovy.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top