8080 直接设置成 ssl 端口,在 spring security 重定向的时候会强行转到 8443端口

https://github.com/spring-projects/spring-security/issues/8140

https://github.com/spring-projects/spring-boot/issues/6140

@fmarot Thank you for the feedback.

This is due to Spring Security's PortResolverImpl which attempts to work around a well know IE bug. From the javadoc:

    This class is capable of handling the IE bug which results in an incorrect URL being
    presented in the header subsequent to a redirect to a different scheme and port where
    the port is not a well-known number (ie 80 or 443). Handling involves detecting an
    incorrect response from ServletRequest.getServerPort() for the scheme (eg
    a HTTP request on 8443) and then determining the real server port (eg HTTP request is
    really on 8080). The map of valid ports is obtained from the configured
    PortMapper

If you want to use HTTP, the easiest solution is to select a port other than 8443 which is typically used for HTTPS and thus remapped to work around the IE bug.
 

https://github.com/spring-projects/spring-security/blob/4.1.0.RELEASE/web/src/main/java/org/springframework/security/web/PortResolverImpl.java

	public int getServerPort(ServletRequest request) {
		int serverPort = request.getServerPort();
		Integer portLookup = null;

		String scheme = request.getScheme().toLowerCase();

		if ("http".equals(scheme)) {
			portLookup = portMapper.lookupHttpPort(Integer.valueOf(serverPort));

		}
		else if ("https".equals(scheme)) {
			portLookup = portMapper.lookupHttpsPort(Integer.valueOf(serverPort));
		}

		if (portLookup != null) {
			// IE 6 bug
			serverPort = portLookup.intValue();
		}

		return serverPort;
	}

https://github.com/spring-projects/spring-security/blob/4.1.0.RELEASE/web/src/main/java/org/springframework/security/web/PortMapperImpl.java

	public PortMapperImpl() {
		this.httpsPortMappings = new HashMap<Integer, Integer>();
		this.httpsPortMappings.put(Integer.valueOf(80), Integer.valueOf(443));
		this.httpsPortMappings.put(Integer.valueOf(8080), Integer.valueOf(8443));
	}

解决办法就是自定义port-mapping,不要转换

	    <port-mappings>
	        <port-mapping http="8080" https="8080"/>
	    </port-mappings>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值