2016-08-18 49 views
0
启用HTTPS

我发现这一点:如何只在春季

<security:http auto-config="true"> 
    <security:form-login .../> 
    <security:logout .../> 

    <security:intercept-url pattern="/reports" access="ROLE_ADMIN" requires-channel="https"/> 
    <security:intercept-url pattern="/login" access="IS_AUTHENTICATED_ANONYMOUSLY" requires-channel="https"/> 
    <security:intercept-url pattern="/**" access="ROLE_USER" requires-channel="https"/> 
</security:http> 

从我的理解,我们必须把这个在web.xml,但我们没有使用web.xml中,我们使用的是Java配置。我怎样才能做到这一点?有什么我可以添加在application.properties?

+0

这应该指向正确的方向:http://stackoverflow.com/questions/26800200/spring-security-javaconfig-configure-required-channels-secure-insecure-any – bphilipnyc

回答

0

你所显示的是一个弹簧安全文件。 Spring安全性可以使用XML文件(如您所展示的)来配置,也可以通过Java配置来配置(请参阅:http://docs.spring.io/spring-security/site/docs/current/reference/html/jc.html)。

但是,您的问题是:我可以只启用HTTPS。

您也可以通过其他方式做到这一点。 例如,在Tomcat中,可以通过配置server.xml(http://www.itworld.com/article/2769041/development/how-to-configure-tomcat-to-always-require-https.htmlhttps://tomcat.apache.org/tomcat-7.0-doc/ssl-howto.html)来完成此操作。

其他JavaEE服务器也有类似的方法。

你也可以在你的web.xml(或Java基于Web的配置)使用SecurityConstraint所以它定义机密或整体像(XML片段,但你可以通过基于Java的配置做):

<user-data-constraint> 
    <transport-guarantee>CONFIDENTIAL</transport-guarantee> 
</user-data-constraint>