我已经为此苦苦挣扎了几天,最终在一个普通的 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"
....
}
然后我在 ..\META-INF 下创建了context.xml ,内容如下:
<?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>
然后将以下内容添加到..\templates\web.xml文件中:
<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>
....
....
为了验证它是否确实有效,我在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 下对此进行了测试,并且必须向 Tomcat 库添加一些 jar 才能让我工作。我添加了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。仍然想知道为什么当同样的 jars 也被添加到 BuildConfig.groovy 时这实际上是必要的。