我在配置 spring boot 时遇到了很大的问题。在我的应用程序中,我使用 XSRF-TOKEN 进行授权。
http.httpBasic().and()
.formLogin().loginPage("/login").and()
.authorizeRequests()
.antMatchers(
"/index_orange.html",
"/index.html",
"/databases.html",
"/crm.html",
"/price.html",
"/var/www/download"
)
.permitAll()
.antMatchers("/admin/**").hasRole("ADMIN")
.antMatchers("/user/**").hasRole("USER")
.anyRequest().authenticated().and()
.requiresChannel()
.csrf().ignoringAntMatchers("/registerform","/newpassblue","/getPaymentNotification")
.csrfTokenRepository(csrfTokenRepository()).and()
.addFilterBefore(csrfHeaderFilter(), SessionManagementFilter.class);
授权效果很好,但我如何添加 SSL (HTTPS)?
我读到,我必须使用 .requiresChannel() ,但此连接会导致编译错误。
我的全局用户详细信息:
@Autowired
public void globalUserDetails(AuthenticationManagerBuilder auth) throws Exception {
auth
.jdbcAuthentication()
.dataSource(securityDataSource)
.usersByUsernameQuery(USER_BY_EMAILS)
.authoritiesByUsernameQuery(AUTHORIZATION_BY_EMAILS)
.passwordEncoder(new ShaPasswordEncoder(512));
}
我的属性文件:
server:
port: 8083
ssl:
enabled: true
key-alias: tomcat
key-store: keystore.p12
key-store-password: "*****"
logging:
path: /var/log/gateway2
level:
org.springframework.security: INFO
security:
sessions: ALWAYS
zuul:
routes:
front:
url: http://192.168.14.73:8080/ui-web
backend:
url: http://192.168.14.63:8180/idbms-web
backend2:
url: http://192.168.14.50:8080/itdjg-mcalendar-ui
crm:
url: http://192.168.14.73:8080/ui-web/crm
bazy-danych:
url: http://192.168.14.73:8080/ui-web
spring:
mvc:
view:
prefix: /WEB-INF/jsp/
suffix: .jsp
最佳答案
在 requiresChannel() 之后添加 and()。但是我认为您需要使用 ssl 启动您的 spring boot 应用程序。
构建一个 keystore.jks 并使用以下参数运行应用程序或将它们添加到 application.properties。
--server.port=443 --server.ssl.key-store=classpath:keystore.jks --server.ssl.key-store-password=<password> --server.ssl.key-password=<password>
关于java - spring boot XSRF-TOKEN如何添加ssl(https),配置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44022848/