【发布时间】:2016-07-18 10:55:54
【问题描述】:
我在 heroku 上部署了一个 Spring Boot java 应用程序。我想确保我的注册端点只能通过 https 访问。到目前为止,我知道,heroku 使用负载均衡器,它将每个 https 连接重定向到带有特殊标头(X-forwarded-porto)的 http。 我正在使用
compile("org.springframework.boot:spring-boot-starter-security")
用于加密工具(散列密码)。我已将“security.basic.enable”属性设置为 false(实际上不知道在这种情况下是否重要。)。
已尝试设置这些设置:
tomcat:
remote_ip_header: x-forwarded-for
protocol_header: x-forwarded-proto
在我的 application.yml 中
问题是,我如何才能真正强制端点只能通过 https 链接使用?对于 http 它可以返回 404 或其他东西。我正在使用 gradle,它很难找到任何使用它的参考。尝试了一些在谷歌中找到的东西,但它没有用(或者我不知道如何正确实现它们......)。我仍然可以使用邮递员通过 http 访问我的端点。 现在它看起来像这样:
@Controller
@RequestMapping("/users")
public class AccountController {
@Autowired
private AccountRepository accountDao;
@RequestMapping(value = "/register", method = RequestMethod.POST, consumes = "application/json")
public ResponseEntity<Resource<Account>> createAccount(@RequestBody @Valid Account account) { ... }
【问题讨论】: