Skip to content

Commit 8248f37

Browse files
committed
support eureka auth
1 parent 6285de3 commit 8248f37

File tree

2 files changed

+66
-0
lines changed

2 files changed

+66
-0
lines changed

linkis-spring-cloud-services/linkis-service-discovery/linkis-eureka/pom.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,17 @@
7676
<artifactId>jersey-apache-client4</artifactId>
7777
</dependency>
7878

79+
<dependency>
80+
<groupId>org.springframework.boot</groupId>
81+
<artifactId>spring-boot-starter-security</artifactId>
82+
<exclusions>
83+
<exclusion>
84+
<groupId>org.springframework.boot</groupId>
85+
<artifactId>spring-boot-starter-logging</artifactId>
86+
</exclusion>
87+
</exclusions>
88+
</dependency>
89+
7990
</dependencies>
8091
<build>
8192
<plugins>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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

Comments
 (0)