-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Feature/issue 1323 inetutils support #4600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
import java.net.UnknownHostException; | ||
import java.util.LinkedHashMap; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
import org.springframework.boot.actuate.autoconfigure.endpoint.web.WebEndpointProperties; | ||
import org.springframework.boot.actuate.autoconfigure.web.server.ManagementServerProperties; | ||
|
@@ -45,6 +46,8 @@ | |
*/ | ||
public class DefaultApplicationFactory implements ApplicationFactory { | ||
|
||
// Removed InetUtils dependency; using standard Java APIs for host resolution. | ||
|
||
private final InstanceProperties instance; | ||
|
||
private final ServerProperties server; | ||
|
@@ -57,6 +60,8 @@ public class DefaultApplicationFactory implements ApplicationFactory { | |
|
||
private final MetadataContributor metadataContributor; | ||
|
||
private final Optional<?> inetUtils; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not one of the contributors of this project but just a client of it, but I must say that this |
||
|
||
@Nullable | ||
private Integer localServerPort; | ||
|
||
|
@@ -72,6 +77,19 @@ public DefaultApplicationFactory(InstanceProperties instance, ManagementServerPr | |
this.pathMappedEndpoints = pathMappedEndpoints; | ||
this.webEndpoint = webEndpoint; | ||
this.metadataContributor = metadataContributor; | ||
this.inetUtils = Optional.empty(); | ||
} | ||
|
||
public DefaultApplicationFactory(InstanceProperties instance, ManagementServerProperties management, | ||
ServerProperties server, PathMappedEndpoints pathMappedEndpoints, WebEndpointProperties webEndpoint, | ||
MetadataContributor metadataContributor, Optional<?> inetUtils) { | ||
this.instance = instance; | ||
this.management = management; | ||
this.server = server; | ||
this.pathMappedEndpoints = pathMappedEndpoints; | ||
this.webEndpoint = webEndpoint; | ||
this.metadataContributor = metadataContributor; | ||
this.inetUtils = (inetUtils != null) ? inetUtils : Optional.empty(); | ||
} | ||
|
||
@Override | ||
|
@@ -192,11 +210,31 @@ protected String getManagementHost() { | |
} | ||
|
||
protected InetAddress getLocalHost() { | ||
// Try using Spring Cloud Commons InetUtils if available (optional dependency) | ||
if (this.inetUtils != null && this.inetUtils.isPresent()) { | ||
Object utils = this.inetUtils.get(); | ||
try { | ||
java.lang.reflect.Method m = utils.getClass().getMethod("findFirstNonLoopbackHostInfo"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this may easily break in case of native compilation. @erikpetzold your thoughts? |
||
Object host = m.invoke(utils); | ||
if (host instanceof String && StringUtils.hasText((String) host)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It can probably be simplified with pattern matching for |
||
try { | ||
return InetAddress.getByName((String) host); | ||
} | ||
catch (UnknownHostException ex) { | ||
// fall through to default | ||
} | ||
} | ||
} | ||
catch (Exception ex) { | ||
// ignore and fall back | ||
} | ||
} | ||
|
||
try { | ||
return InetAddress.getLocalHost(); | ||
} | ||
catch (UnknownHostException ex) { | ||
throw new IllegalArgumentException(ex.getMessage(), ex); | ||
throw new IllegalStateException("Cannot determine local host address", ex); | ||
} | ||
} | ||
|
||
|
@@ -236,11 +274,14 @@ protected String getHost(InetAddress address) { | |
return address.getHostAddress(); | ||
} | ||
|
||
return switch (this.instance.getServiceHostType()) { | ||
case IP -> address.getHostAddress(); | ||
case HOST_NAME -> address.getHostName(); | ||
default -> address.getCanonicalHostName(); | ||
}; | ||
switch (this.instance.getServiceHostType()) { | ||
case IP: | ||
return address.getHostAddress(); | ||
case HOST_NAME: | ||
return address.getHostName(); | ||
default: | ||
return address.getCanonicalHostName(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why did you change the syntax here? |
||
} | ||
|
||
@EventListener | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think all these oauth2 sample files do not belong here |
||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||
http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<groupId>de.codecentric</groupId> | ||
<artifactId>spring-boot-admin-samples</artifactId> | ||
<version>${revision}</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>spring-boot-admin-sample-oauth2-client</artifactId> | ||
<name>Spring Boot Admin OAuth2 Client Sample</name> | ||
<description>Sample monitored app configured as OAuth2 Resource Server</description> | ||
<packaging>jar</packaging> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>de.codecentric</groupId> | ||
<artifactId>spring-boot-admin-starter-client</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-oauth2-resource-server</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-actuator</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-web</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-starter-test</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.springframework.boot</groupId> | ||
<artifactId>spring-boot-maven-plugin</artifactId> | ||
<configuration> | ||
<mainClass>de.codecentric.boot.admin.sample.client.OAuth2ClientApplication</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright 2014-2023 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 de.codecentric.boot.admin.sample.client; | ||
|
||
import org.springframework.boot.SpringApplication; | ||
import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
import org.springframework.boot.context.metrics.buffering.BufferingApplicationStartup; | ||
|
||
@SpringBootApplication | ||
public class OAuth2ClientApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication app = new SpringApplication(OAuth2ClientApplication.class); | ||
app.setApplicationStartup(new BufferingApplicationStartup(1500)); | ||
app.run(args); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
/* | ||
* Copyright 2014-2023 the original author or authors. | ||
* | ||
* Licensed 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 | ||
* | ||
* https://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 de.codecentric.boot.admin.sample.client; | ||
|
||
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 OAuth2ResourceServerConfig { | ||
|
||
@Bean | ||
SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { | ||
http.authorizeHttpRequests( | ||
(auth) -> auth.requestMatchers("/actuator/**").authenticated().anyRequest().permitAll()) | ||
.oauth2ResourceServer((oauth2) -> oauth2.jwt((jwt) -> { | ||
})); | ||
return http.build(); | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
spring: | ||
application: | ||
name: spring-boot-admin-sample-oauth2-client | ||
|
||
security: | ||
oauth2: | ||
resourceserver: | ||
jwt: | ||
issuer-uri: https://YOUR_ISSUER_URL | ||
|
||
management: | ||
endpoints: | ||
web: | ||
exposure: | ||
include: "*" | ||
|
||
spring: | ||
boot: | ||
admin: | ||
client: | ||
url: http://localhost:8080 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
there was no InetUtils dependency removed here, please remove the comment