|
| 1 | +/* |
| 2 | + * Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 | + * contributor license agreements. See the NOTICE file distributed with |
| 4 | + * this work for additional information regarding copyright ownership. |
| 5 | + * The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 | + * (the "License"); you may not use this file except in compliance with |
| 7 | + * the License. You may obtain a copy of the License at |
| 8 | + * |
| 9 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | + * |
| 11 | + * Unless required by applicable law or agreed to in writing, software |
| 12 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + * See the License for the specific language governing permissions and |
| 15 | + * limitations under the License. |
| 16 | + */ |
| 17 | + |
| 18 | +package org.apache.linkis.eureka; |
| 19 | + |
| 20 | +import org.springframework.boot.context.properties.ConfigurationProperties; |
| 21 | +import org.springframework.security.config.annotation.web.builders.HttpSecurity; |
| 22 | +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; |
| 23 | +import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; |
| 24 | + |
| 25 | +import org.slf4j.Logger; |
| 26 | +import org.slf4j.LoggerFactory; |
| 27 | + |
| 28 | +@EnableWebSecurity |
| 29 | +@ConfigurationProperties("auth") |
| 30 | +public class EurekaSecurityConfig extends WebSecurityConfigurerAdapter { |
| 31 | + |
| 32 | + private static final Logger logger = LoggerFactory.getLogger(EurekaSecurityConfig.class); |
| 33 | + |
| 34 | + private Boolean enableAuth = false; |
| 35 | + |
| 36 | + public Boolean getEnableAuth() { |
| 37 | + return enableAuth; |
| 38 | + } |
| 39 | + |
| 40 | + public void setEnableAuth(Boolean enableAuth) { |
| 41 | + this.enableAuth = enableAuth; |
| 42 | + } |
| 43 | + |
| 44 | + @Override |
| 45 | + protected void configure(HttpSecurity http) throws Exception { |
| 46 | + http.csrf().disable(); |
| 47 | + if (!enableAuth) { |
| 48 | + logger.info("eureka off auth"); |
| 49 | + http.authorizeRequests().anyRequest().permitAll().and().logout().permitAll(); |
| 50 | + } else { |
| 51 | + logger.info("eureka spring security enable"); |
| 52 | + super.configure(http); |
| 53 | + } |
| 54 | + } |
| 55 | +} |
0 commit comments