繁体   English   中英

如何从自己的AppEngine网络服务调用安全页面?

[英]How do I call a secured page from my own AppEngine web-service?

要发送HTML电子邮件,我想调用我自己的应用程序的其他URL,以方便使用JSP呈现电子邮件内容。

为了对我自己的应用程序执行HTTP调用,我首先尝试使用“ http:// localhost / emailreport ”作为URL,但是由于DNS错误而失败。 接下来,我尝试了外部URL:

String appid = ApiProxy.getCurrentEnvironment().getAttributes()
   .get("com.google.appengine.runtime.default_version_hostname").toString();
appid = appid.substring(0, appid.indexOf('.'));
URL url = new URL("http://" + appid + ".appspot.com/emailreport");

这有效,但仅适用于web.xml中没有安全性约束的页面。 但是,我的电子邮件报告需要保护。

任何想法如何检索该页面? 我需要使用服务帐户密钥吗? 有没有简单的把戏?

添加:
我想通过将其添加到web.xml中来保护页面:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>SecureName</web-resource-name>
        <url-pattern>/mytask</url-pattern>
    </web-resource-collection>
    <auth-constraint>
        <role-name>admin</role-name>
    </auth-constraint>
</security-constraint>

我通过使用以下解决方法解决了它:

调用方创建一个秘密令牌并将其存储在MemCache中,并将标头添加到请求中。

端点读取该标头并将其与MemCache中的值进行比较。 如果匹配,则处理请求,否则返回401。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM