添加到Spring启动应用程序的额外未知端点

时间:2017-09-25 10:47:51

标签: spring spring-boot endpoints

我正在创建一个spring boot应用程序。我正在添加几个端点。在该过程中,一些端点是安全的,而一些端点则不安全。

安装应用程序后,我会得到一些额外的端点,提供甚至没有暴露的应用程序信息。

实施例: 一些暴露的端点是

@RestController
@RequestMapping("/category/v1")
public class ControllerClass {
     @RequestMapping(value="/pillars", method=RequestMethod.GET)
     public String pillarGetMethod() {
       //method
     }

     @RequestMapping(value="/frameworks", method=RequestMethod.GET)
     public String frameworkGetMethod() {
       //method
     }
}

现在我们期待

  • /类别/ V1 /柱子
  • /类别/ V1 /框架

应该暴露。

但是那个

  • /柱子
  • /框架

也会因响应而曝光

{
  "_embedded" : {
    "pillars" : [ {

    } ]
  },
  "_links" : {
    "self" : {
      "href" : "http://<ip>/pillars{?page,size,sort}",
      "templated" : true
    },
    "profile" : {
      "href" : "http://<ip>/profile/pillars"
    },
    "search" : {
      "href" : "http://<ip>/pillars/search"
    }
  },
  "page" : {
    "size" : 20,
    "totalElements" : 5,
    "totalPages" : 1,
    "number" : 0
  }
}

我需要帮助理解输出以及如何阻止它暴露出来。

1 个答案:

答案 0 :(得分:1)

我的猜测是你定义的东西:

public class PillarRepository extends CrudRepository<Pillar, String> { ... }

public class FrameworkPillarRepository extends CrudRepository<Pillar, String> { ... }

如果是这样,Spring Boot / Spring Data Rest会自动公开底层资源,除非您使用@RepositoryRestResource(exported = false)注释存储库。

如果您只想重现自动GET行为,但使用自定义路径,请使用path选项。