简体   繁体   English

如何从运行jnlp的URL获取?

[英]How to get URL from which jnlp was run?

For my Java Web Start app I want to restrict that it can be run only from the specified domain. 对于我的Java Web Start应用程序,我想限制它只能在指定的域中运行。 How can I get URL from which my app was run? 如何获取运行我的应用程序的URL? I tried this way: 我这样尝试:

final BasicService bs = (BasicService) ServiceManager.lookup("javax.jnlp.BasicService");
final URL codeBase = bs.getCodeBase();

It works fine and shows me the origin but only when the codebase parameter in my jnlp file is empty. 仅当我的jnlp文件中的codebase参数为空时,它才能正常工作并显示源。 When it is set, then it shows the url for the codebase, which is wrong (when I host libs on other server) because I want the url from where my jnlp was run. 设置后,它将显示代码库的URL,这是错误的(当我在其他服务器上托管库时),因为我想要从运行jnlp的URL。 For example I run my jnlp from "www.jnlpdomain.com", but the codebase is "www.libdomain.com" - in this case I would like to know the first url. 例如,我从“ www.jnlpdomain.com”运行我的jnlp,但是代码库是“ www.libdomain.com”-在这种情况下,我想知道第一个URL。 When I check java console logs I can see following: 当我检查Java控制台日志时,可以看到以下内容:

JNLP Ref (absolute): www.jnlpdomain.com/my_jnlp_file.jnlp
.... (some few lines)
=====CODEBASE=====: www.libdomain.com (this line is printed by me with the bs.getCodeBase())

So I can see that the host name is printed correctly in the first line in logs, starting with: 因此,我可以看到主机名已正确打印在日志的第一行中,开头为:

JNLP Ref (absolute): ....

How can I get this in my app, so I can validate the domain? 如何在我的应用程序中获取此信息,以便验证域?

Look at JAR File Manifest Attributes for Security: Codebase Attribute : 查看安全性的JAR文件清单属性:代码库属性

The Codebase attribute is used to restrict the code base of the JAR file to specific domains. Codebase属性用于将JAR文件的代码库限制为特定域。 Use this attribute to prevent someone from re-deploying your application on another website for malicious purposes. 使用此属性可防止某人出于恶意目的在其他网站上重新部署您的应用程序

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

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