Skip to content

Commit 662a5b0

Browse files
authored
Upgrade Spring Boot demo to 3.5.12 and Java 17 (#734)
## Summary - Upgrade Spring Boot from 2.6.4 to 3.5.12 and Java from 1.8 to 17 - Migrate from `javax` to `jakarta` namespace for Spring Boot 3.x compatibility - Update SDK usage for 0.103.0: explicit OIDC endpoint discovery, required scopes, and `CreateCustomAppIntegration` request object - Override transitive jackson-bom version to fix known CVE - Remove unused `ObjectMapper` bean and `jackson-datatype-jsr310` dependency ## Test plan - [x] Built and ran the example locally against an AWS staging workspace - [x] Verified full OAuth U2M flow: app registration, consent, token exchange, and cluster listing - [x] Ran Trivy scan confirming zero vulnerabilities in the example - [x] Ran `mvn spotless:check` confirming formatting compliance This pull request was AI-assisted by Isaac.
1 parent 10a8848 commit 662a5b0

4 files changed

Lines changed: 20 additions & 30 deletions

File tree

examples/spring-boot-oauth-u2m-demo/pom.xml

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<parent>
55
<groupId>org.springframework.boot</groupId>
66
<artifactId>spring-boot-starter-parent</artifactId>
7-
<version>2.6.4</version>
7+
<version>3.5.12</version>
88
<relativePath></relativePath>
99
</parent>
1010

@@ -17,8 +17,11 @@
1717

1818
<properties>
1919
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
20-
<maven.compiler.source>1.8</maven.compiler.source>
21-
<maven.compiler.target>1.8</maven.compiler.target>
20+
<maven.compiler.source>17</maven.compiler.source>
21+
<maven.compiler.target>17</maven.compiler.target>
22+
<!-- Override transitive dependency version to fix known CVE.
23+
This can likely be removed when upgrading to a newer Spring Boot version. -->
24+
<jackson-bom.version>2.21.2</jackson-bom.version>
2225
</properties>
2326

2427
<dependencies>
@@ -39,9 +42,5 @@
3942
<artifactId>databricks-sdk-java</artifactId>
4043
<version>0.103.0</version>
4144
</dependency>
42-
<dependency>
43-
<groupId>com.fasterxml.jackson.datatype</groupId>
44-
<artifactId>jackson-datatype-jsr310</artifactId>
45-
</dependency>
4645
</dependencies>
4746
</project>

examples/spring-boot-oauth-u2m-demo/src/main/java/com/databricks/sdk/App.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
import com.databricks.sdk.core.commons.CommonsHttpClient;
44
import com.databricks.sdk.core.http.HttpClient;
5-
import com.fasterxml.jackson.databind.ObjectMapper;
6-
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
75
import org.springframework.boot.SpringApplication;
86
import org.springframework.boot.autoconfigure.SpringBootApplication;
97
import org.springframework.context.annotation.Bean;
@@ -23,13 +21,6 @@ public HttpClient getHttpClient() {
2321
return new CommonsHttpClient.Builder().withTimeoutSeconds(30).build();
2422
}
2523

26-
@Bean
27-
public ObjectMapper getObjectMapper() {
28-
ObjectMapper m = new ObjectMapper();
29-
m.registerModule(new JavaTimeModule());
30-
return m;
31-
}
32-
3324
@Bean
3425
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
3526
http.authorizeHttpRequests((requests) -> requests

examples/spring-boot-oauth-u2m-demo/src/main/java/com/databricks/sdk/RootController.java

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,12 @@
44
import com.databricks.sdk.core.http.HttpClient;
55
import com.databricks.sdk.core.oauth.Consent;
66
import com.databricks.sdk.core.oauth.OAuthClient;
7+
import com.databricks.sdk.core.oauth.OpenIDConnectEndpoints;
78
import com.databricks.sdk.core.oauth.SessionCredentials;
89
import com.databricks.sdk.service.compute.ClusterDetails;
910
import com.databricks.sdk.service.compute.ListClustersRequest;
11+
import com.databricks.sdk.service.oauth2.CreateCustomAppIntegration;
1012
import com.databricks.sdk.service.oauth2.CreateCustomAppIntegrationOutput;
11-
import com.fasterxml.jackson.core.JsonProcessingException;
12-
import com.fasterxml.jackson.databind.ObjectMapper;
1313
import org.springframework.beans.factory.annotation.Autowired;
1414
import org.springframework.beans.factory.annotation.Value;
1515
import org.springframework.stereotype.Controller;
@@ -18,7 +18,7 @@
1818
import org.springframework.web.bind.annotation.PostMapping;
1919
import org.springframework.web.bind.annotation.RequestParam;
2020

21-
import javax.servlet.http.HttpSession;
21+
import jakarta.servlet.http.HttpSession;
2222
import java.io.IOException;
2323
import java.net.MalformedURLException;
2424
import java.util.ArrayList;
@@ -31,9 +31,6 @@ public class RootController {
3131
@Autowired
3232
private HttpClient hc;
3333

34-
@Autowired
35-
private ObjectMapper mapper;
36-
3734
// Initialized by initializeApp(). This should be initialized in a more Spring-friendly way.
3835
private OAuthClient client;
3936
// Initialized by callback(). This should be initialized in a more Spring-friendly way.
@@ -47,16 +44,13 @@ private String getRedirectUrl() {
4744
}
4845

4946
@GetMapping("/")
50-
public String index(HttpSession session, Model model) throws JsonProcessingException {
47+
public String index(HttpSession session, Model model) {
5148
if (client != null) {
5249
model.addAttribute("clientId", client.getClientId());
5350
model.addAttribute("clientSecret", client.getClientSecret());
5451
model.addAttribute("hostname", client.getHost());
5552
}
56-
SessionCredentials sessionCreds = (SessionCredentials) session.getAttribute("sessionCreds");
57-
if (sessionCreds != null) {
58-
model.addAttribute("sessionCreds", mapper.writeValueAsString(sessionCreds.getToken()));
59-
}
53+
model.addAttribute("authenticated", session.getAttribute("sessionCreds") != null);
6054
return "index";
6155
}
6256

@@ -70,12 +64,16 @@ public String initializeApp(
7064
@RequestParam(name="client_id") String clientId,
7165
@RequestParam(name="client_secret") String clientSecret,
7266
@RequestParam(name="hostname") String hostname) throws IOException {
67+
DatabricksConfig config = new DatabricksConfig().setHost(hostname).setHttpClient(hc).resolve();
68+
OpenIDConnectEndpoints oidcEndpoints = config.getDatabricksOidcEndpoints();
7369
client = new OAuthClient.Builder()
7470
.withClientId(clientId)
7571
.withClientSecret(clientSecret)
7672
.withHost(hostname)
7773
.withRedirectUrl(getRedirectUrl())
7874
.withHttpClient(hc)
75+
.withOpenIDConnectEndpoints(oidcEndpoints)
76+
.withScopes(List.of("all-apis", "offline_access"))
7977
.build();
8078
return "redirect:/";
8179
}
@@ -104,13 +102,15 @@ public String makeNewApp(
104102
.setHttpClient(hc);
105103
AccountClient account = new AccountClient(c);
106104
CreateCustomAppIntegrationOutput result = account.customAppIntegration().create(
107-
"java-sdk-demo", Collections.singletonList(getRedirectUrl()));
105+
new CreateCustomAppIntegration()
106+
.setName("java-sdk-demo")
107+
.setRedirectUrls(Collections.singletonList(getRedirectUrl())));
108108

109109
return initializeApp(result.getClientId(), result.getClientSecret(), hostname);
110110
}
111111

112112
@GetMapping("/authenticate")
113-
public String authenticate(HttpSession session, Model model) throws MalformedURLException, JsonProcessingException {
113+
public String authenticate(HttpSession session, Model model) throws MalformedURLException {
114114
if (client == null) {
115115
model.addAttribute("authError", "Client is not yet initialized. Please login first.");
116116
return index(session, model);

examples/spring-boot-oauth-u2m-demo/src/main/resources/templates/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ <h1>Consent</h1>
1515
<div th:if="${authError != null}">
1616
<span th:text="${authError}"></span>
1717
</div>
18-
<p>session credentials: <span th:text="${sessionCreds}">Not authenticated</span></p>
18+
<p>status: <span th:if="${authenticated}">Authenticated</span><span th:unless="${authenticated}">Not authenticated</span></p>
1919
<h1>APIs</h1>
2020
<a href="/list-clusters">List clusters</a>
2121
</body>

0 commit comments

Comments
 (0)