diff --git a/linkis-spring-cloud-services/linkis-service-discovery/linkis-eureka/pom.xml b/linkis-spring-cloud-services/linkis-service-discovery/linkis-eureka/pom.xml index 4bfa76e589f..33254add420 100644 --- a/linkis-spring-cloud-services/linkis-service-discovery/linkis-eureka/pom.xml +++ b/linkis-spring-cloud-services/linkis-service-discovery/linkis-eureka/pom.xml @@ -89,6 +89,16 @@ micrometer-registry-prometheus compile + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-logging + + + diff --git a/linkis-spring-cloud-services/linkis-service-discovery/linkis-eureka/src/main/java/org/apache/linkis/eureka/EurekaSecurityConfig.java b/linkis-spring-cloud-services/linkis-service-discovery/linkis-eureka/src/main/java/org/apache/linkis/eureka/EurekaSecurityConfig.java new file mode 100644 index 00000000000..d296d921a55 --- /dev/null +++ b/linkis-spring-cloud-services/linkis-service-discovery/linkis-eureka/src/main/java/org/apache/linkis/eureka/EurekaSecurityConfig.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.linkis.eureka; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration +public class EurekaSecurityConfig { + + private static final Logger logger = LoggerFactory.getLogger(EurekaSecurityConfig.class); + + @Value("${linkis.eureka.auth.enable:false}") + private boolean enableAuth; + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http.csrf().disable(); + if (!enableAuth) { + logger.info("Eureka auth is disabled, all requests are permitted"); + http.authorizeRequests().anyRequest().permitAll(); + } else { + logger.info("Eureka auth is enabled, Spring Security will handle authentication"); + } + return http.build(); + } +}