Tomcat:如何在Java中获取安全端口号? [英] Tomcat: how to get the secure port number in Java?

查看:175
本文介绍了Tomcat:如何在Java中获取安全端口号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在我的一个不安全页面中嵌入指向我的应用程序的安全页面的链接。
安全的tomcat端口在server.xml文件中配置。在某些部署中它是443,8443等等。
所以我需要的是从tomcat配置中读取安全端口以在链接中使用它的方法。这可能吗?

I'd like to embed a link to a secure page of my application in one of my unsecure pages. The secure tomcat port is configured in the server.xml file. In some deployments it's 443, 8443 etc. So what I need is a way to read the secure port from tomcat configuration to use it in the link. Is that possible?

或者,只需访问server.xml配置(从请求的上下文中)并自己解析它以找出端口号是也可以接受,但不太理想。

Alternatively, simply getting access to the server.xml configuration (from within the context of the request) and parsing it myself to figure out the port number is also acceptable, but less desired.

我意识到可能有几个连接器和几个安全连接器,所以我将把它留给我的程序逻辑来决定选择哪一个。问题是 - 我如何获得这些信息?

I realize there could be several connectors, and several secure ones, so I'll leave it to my program's logic to decide which one to choose. Problem is - how do I get that info?

谢谢!

推荐答案

我很确定没有API。您可以通过web.xml中的servlet environ参数对其进行配置。显而易见的缺点是,您现在有2个位置配置了SSL端口号。

I'm pretty sure there's no API for that. You could probably keep it configurable via a servlet environ parameter in web.xml. The obvious drawback is you now have 2 places the SSL port number is configured.

另一种方法是在web.xml中配置安全性,例如

Another approach is to configure security in web.xml iirc something like

 <security-constraint>
    <web-resource-collection> 
        <web-resource-name>MyLoginPage</web-resource-name>
        <url-pattern>/login</url-pattern> 
        <http-method>GET</http-method> 
        <http-method>POST</http-method> 
    </web-resource-collection> 
    <user-data-constraint> 
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
     </user-data-constraint> 
 </security-constraint>

您可以使用指向登录页面的普通链接,tomcat应该自动向ssl连接器发送redicts ,无论配置为哪个端口。

You can just use normal links to the login page, and tomcat should automatically send redicts to the ssl connector, whichever port that is configure to.

这篇关于Tomcat:如何在Java中获取安全端口号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆