保护尝试
网址
http://[GAE app URL]/_ah/sessioncleanup?clear
从GAE数据存储中清除100个过期的会话(看起来似乎如此)。
我想保护此网址,以便可以使用cron.xml
中的条目从应用内部调用
<cronentries>
[...]
<cron>
<url>/_ah/sessioncleanup?clear</url>
<description>Clean 100 expired sessions up</description>
<schedule>[Schedule]</schedule>
</cron>
</cronentries>
但不是仅仅遵循上面给出的表单的URL的任何用户。
所以我将以下代码添加到web.xml
:
<web-app>
[...]
<security-constraint>
<web-resource-collection>
<web-resource-name>session-clean-up</web-resource-name>
<url-pattern>/_ah/sessioncleanup</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
</web-app>
我省略了将以下内容添加到web.xml
,因为会话清理是在没有它的情况下使用手动URL调用进行的:
<web-app>
[...]
<servlet>
<servlet-name>_ah_sessioncleanup</servlet-name>
<servlet-class>com.google.apphosting.utils.servlet.SessionCleanupServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>_ah_sessioncleanup</servlet-name>
<url-pattern>/_ah/sessioncleanup</url;-pattern>
</servlet-mapping>
</web-app>
结果
可悲的是,在将此代码部署到生产环境中之后,我发现上面的<security-constraint>
添加到
http://[GAE app URL]/_ah/sessioncleanup?clear
或
http://[GAE app URL]/_ah/sessioncleanup
背景资料
我将上面的代码基于GAE issue 10047 (Request to document or publish code for SessionCleanupServlet)中引用的Google员工发布。
我的问题
有谁知道如何解决我的问题?
答案 0 :(得分:0)
我建议您看到此链接security constraint wiki。 :)
答案 1 :(得分:0)
通过将web.xml
附加到网址格式来调整/*
中的条目会导致成功。相关的web.xml
条目变为:
<web-app>
[...]
<security-constraint>
<web-resource-collection>
<web-resource-name>session-clean-up</web-resource-name>
<url-pattern>/_ah/sessioncleanup/[asterisk]</url-pattern>
</web-resource-collection>
<auth-constraint>
<role-name>admin</role-name>
</auth-constraint>
</security-constraint>
</web-app>