弹簧启动 - 仅安全的执行器端点

pie*_*ier 3 security spring-boot spring-boot-actuator

我使用Spring启动(1.3.0)与泽西岛(POM依赖关系:spring-boot-starter-jersey,spring-boot-starter-actuator,spring-boot-starter-web,spring-boot-starter-security).

我有一个Jersey端点(见下文),这非常简单:

@Component
@Path("/helloworld")
public class HelloWorldResource {

    @GET
    public String home() {
        return "Hello World !";
    }
}
Run Code Online (Sandbox Code Playgroud)

我通过为Spring MVC url(server.servlet-path=/system)设置特定路径来启用Spring Boot Actuator ,如Spring Boot指南中所述.
由于spring-boot-starter-security,Actuator端点通过基本身份验证得到保护.

我的问题是,这/helloworld也是安全的,但我想让它不安全.

我怎样才能做到这一点 ?

谢谢 !

Der*_*ick 5

您必须在yaml/properties文件中配置设置,如下所示 -

server:
  port: 8080
  context-path: /MyApplication

security:
   user:
       name: admin
       password: secret
   basic:
       enabled: false

management:
   context-path: /actuator
   security:
             enabled: true
Run Code Online (Sandbox Code Playgroud)

因此,对于您的应用程序,安全性已禁用,但已为执行器端点启用.确保您没有在管理安全性下配置用户名/密码,否则它将无法正常工作.

  • 从Spring 1.5.4开始,您不需要在.yml中设置任何特定的`context-path`.我可以设置`security.basic.enabled = false`和`management.security.enabled = true`,它就像一个魅力. (2认同)