如何强制Spring MVC控制器将SSL与Spring安全性结合使用?
我在为Spring MVC REST资源强制使用SSL时遇到问题。我不需要身份验证,因为它是通过HTTP头中传递的安全令牌来处理的,我只需要禁止使用HTTP。由于我已经在项目的其他部分使用了Spring安全性,我宁愿继续使用它,而不是在web服务器中配置SSL。当我试图连接到一个资源时,我得到了“错误:140770FC:SSL例程:SSL23\u GET\u SERVER\u HELLO:unknown protocol”,我认为这意味着服务器试图不通过SSL进行响应 web.xml 我还尝试在安全配置中使用端口重定向,如如何强制Spring MVC控制器将SSL与Spring安全性结合使用?,spring,spring-mvc,ssl,spring-security,jetty,Spring,Spring Mvc,Ssl,Spring Security,Jetty,我在为Spring MVC REST资源强制使用SSL时遇到问题。我不需要身份验证,因为它是通过HTTP头中传递的安全令牌来处理的,我只需要禁止使用HTTP。由于我已经在项目的其他部分使用了Spring安全性,我宁愿继续使用它,而不是在web服务器中配置SSL。当我试图连接到一个资源时,我得到了“错误:140770FC:SSL例程:SSL23\u GET\u SERVER\u HELLO:unknown protocol”,我认为这意味着服务器试图不通过SSL进行响应 web.xml 我还尝试在
<security:http auto-config="true" use-expressions="true">/
<security:intercept-url pattern="/**" requires-channel="https" security="none"/>
<security:port-mappings>
<security:port-mapping http="8080" https="8443" />
</security:port-mappings>
</security:http>
/
并将Jetty绑定到8443,但没有任何帮助。每次我试图通过https连接到/mongoose/policies资源时,我都会得到curl:(35)错误:140770FC:SSL例程:SSL23\u GET\u SERVER\u HELLO:unknown protocol
也许我的问题与Spring MVC使用的servlet的IsSecurity属性有关,是否设置为false 您是否在Jetty中正确设置了SSL?我认为您需要澄清您正在发出什么请求(curl命令)以及输出是什么。使用“curl-v”。这听起来不像是与Spring配置问题有关的东西。你是对的。Jetty没有正确配置。我一修好它,一切都开始工作了。很高兴你让它工作了。我建议你删除你的问题,因为这只会分散其他搜索Spring相关问题的人的注意力。我不同意删除这个问题,它可能会对其他获得相同问题的人有用,如果碰巧有类似的原因。我建议@MrkK添加他自己的答案,并将其标记为已回答。
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:security="http://www.springframework.org/schema/security"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-3.2.xsd
http://www.springframework.org/schema/security
http://www.springframework.org/schema/security/spring-security-3.1.xsd">
<security:http auto-config="true" use-expressions="true">
<security:intercept-url pattern="/**" requires-channel="https" />
</security:http>
<security:authentication-manager>
</security:authentication-manager>
</beans>
@Controller
@RequestMapping("/mongoose")
public class HarmonyRestController {
private final Logger logger = LoggerFactory.getLogger(getClass());
public HarmonyRestController() {
}
@RequestMapping(value = "policies", method = RequestMethod.GET, produces = "application/json")
public
@ResponseBody
String requestPolicies() {
return "test...";
}
}
<security:http auto-config="true" use-expressions="true">/
<security:intercept-url pattern="/**" requires-channel="https" security="none"/>
<security:port-mappings>
<security:port-mapping http="8080" https="8443" />
</security:port-mappings>
</security:http>