Skip to content

Commit 52aa85d

Browse files
authored
Merge pull request #4 from oktadeveloper/spring-security-5.1
Switch to Spring Security 5.1 and OIDC issuer support
2 parents 43f4c24 + ed82252 commit 52aa85d

8 files changed

Lines changed: 301 additions & 217 deletions

File tree

app/src/Home.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ class Home extends Component {
3535
if (port === ':3000') {
3636
port = ':8080';
3737
}
38-
window.location.href = '//' + window.location.hostname + port + '/login';
38+
window.location.href = '//' + window.location.hostname + port + '/private';
3939
}
4040

4141
logout() {

pom.xml

Lines changed: 30 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
<parent>
1515
<groupId>org.springframework.boot</groupId>
1616
<artifactId>spring-boot-starter-parent</artifactId>
17-
<version>2.0.3.RELEASE</version>
17+
<version>2.1.0.BUILD-SNAPSHOT</version>
1818
<relativePath/> <!-- lookup parent from repository -->
1919
</parent>
2020

@@ -25,6 +25,7 @@
2525
<frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>
2626
<node.version>v10.6.0</node.version>
2727
<yarn.version>v1.8.0</yarn.version>
28+
<spring-security.version>5.1.0.BUILD-SNAPSHOT</spring-security.version>
2829
</properties>
2930

3031
<dependencies>
@@ -41,9 +42,16 @@
4142
<artifactId>spring-boot-starter-security</artifactId>
4243
</dependency>
4344
<dependency>
44-
<groupId>org.springframework.security.oauth.boot</groupId>
45-
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
46-
<version>2.0.1.RELEASE</version>
45+
<groupId>org.springframework.security</groupId>
46+
<artifactId>spring-security-config</artifactId>
47+
</dependency>
48+
<dependency>
49+
<groupId>org.springframework.security</groupId>
50+
<artifactId>spring-security-oauth2-client</artifactId>
51+
</dependency>
52+
<dependency>
53+
<groupId>org.springframework.security</groupId>
54+
<artifactId>spring-security-oauth2-jose</artifactId>
4755
</dependency>
4856
<dependency>
4957
<groupId>com.h2database</groupId>
@@ -180,4 +188,22 @@
180188
</properties>
181189
</profile>
182190
</profiles>
191+
192+
<pluginRepositories>
193+
<pluginRepository>
194+
<id>spring-snapshots</id>
195+
<name>Spring Snapshots</name>
196+
<url>https://repo.spring.io/snapshot</url>
197+
<snapshots>
198+
<enabled>true</enabled>
199+
</snapshots>
200+
</pluginRepository>
201+
</pluginRepositories>
202+
<repositories>
203+
<repository>
204+
<id>spring-snapshots</id>
205+
<name>Spring Snapshot Repository</name>
206+
<url>http://repo.spring.io/snapshot</url>
207+
</repository>
208+
</repositories>
183209
</project>

spring-sec-issuer.patch

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
diff --git a/pom.xml b/pom.xml
2+
index 3b477f5..24ab1aa 100644
3+
--- a/pom.xml
4+
+++ b/pom.xml
5+
@@ -14,7 +14,7 @@
6+
<parent>
7+
<groupId>org.springframework.boot</groupId>
8+
<artifactId>spring-boot-starter-parent</artifactId>
9+
- <version>2.0.3.RELEASE</version>
10+
+ <version>2.0.4.BUILD-SNAPSHOT</version>
11+
<relativePath/> <!-- lookup parent from repository -->
12+
</parent>
13+
14+
@@ -25,6 +25,7 @@
15+
<frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>
16+
<node.version>v10.6.0</node.version>
17+
<yarn.version>v1.8.0</yarn.version>
18+
+ <spring-security.version>5.1.0.BUILD-SNAPSHOT</spring-security.version>
19+
</properties>
20+
21+
<dependencies>
22+
@@ -45,6 +46,18 @@
23+
<artifactId>spring-security-oauth2-autoconfigure</artifactId>
24+
<version>2.0.1.RELEASE</version>
25+
</dependency>
26+
+ <dependency>
27+
+ <groupId>org.springframework.security</groupId>
28+
+ <artifactId>spring-security-config</artifactId>
29+
+ </dependency>
30+
+ <dependency>
31+
+ <groupId>org.springframework.security</groupId>
32+
+ <artifactId>spring-security-oauth2-client</artifactId>
33+
+ </dependency>
34+
+ <dependency>
35+
+ <groupId>org.springframework.security</groupId>
36+
+ <artifactId>spring-security-oauth2-jose</artifactId>
37+
+ </dependency>
38+
<dependency>
39+
<groupId>com.h2database</groupId>
40+
<artifactId>h2</artifactId>
41+
@@ -175,4 +188,22 @@
42+
</properties>
43+
</profile>
44+
</profiles>
45+
+
46+
+ <pluginRepositories>
47+
+ <pluginRepository>
48+
+ <id>spring-snapshots</id>
49+
+ <name>Spring Snapshots</name>
50+
+ <url>https://repo.spring.io/snapshot</url>
51+
+ <snapshots>
52+
+ <enabled>true</enabled>
53+
+ </snapshots>
54+
+ </pluginRepository>
55+
+ </pluginRepositories>
56+
+ <repositories>
57+
+ <repository>
58+
+ <id>spring-snapshots</id>
59+
+ <name>Spring Snapshot Repository</name>
60+
+ <url>http://repo.spring.io/snapshot</url>
61+
+ </repository>
62+
+ </repositories>
63+
</project>
64+
diff --git a/src/main/java/com/okta/developer/jugtours/web/UserController.java b/src/main/java/com/okta/developer/jugtours/web/UserController.java
65+
index eee3fde..17c1464 100644
66+
--- a/src/main/java/com/okta/developer/jugtours/web/UserController.java
67+
+++ b/src/main/java/com/okta/developer/jugtours/web/UserController.java
68+
@@ -22,8 +22,8 @@ public class UserController {
69+
70+
private final UserInfoRestTemplateFactory templateFactory;
71+
72+
- @Value("${security.oauth2.client.access-token-uri}")
73+
- String accessTokenUri;
74+
+ @Value("${spring.security.oauth2.client.provider.okta.issuer}")
75+
+ String issuerUri;
76+
77+
public UserController(UserInfoRestTemplateFactory templateFactory) {
78+
this.templateFactory = templateFactory;
79+
@@ -62,8 +62,7 @@ public class UserController {
80+
OAuth2RestTemplate oauth2RestTemplate = this.templateFactory.getUserInfoRestTemplate();
81+
String idToken = (String) oauth2RestTemplate.getAccessToken().getAdditionalInformation().get("id_token");
82+
83+
- // logout URI can be derived from accessTokenUri
84+
- String logoutUrl = accessTokenUri.replace("token", "logout");
85+
+ String logoutUrl = issuerUri + "/v1/logout";
86+
87+
Map<String, String> logoutDetails = new HashMap<>();
88+
logoutDetails.put("logoutUrl", logoutUrl);
89+
diff --git a/src/main/resources/application.yml b/src/main/resources/application.yml
90+
index 18ddd91..e14e090 100644
91+
--- a/src/main/resources/application.yml
92+
+++ b/src/main/resources/application.yml
93+
@@ -1,13 +1,14 @@
94+
-security:
95+
- oauth2:
96+
- client:
97+
- access-token-uri: https://dev-158606.oktapreview.com/oauth2/default/v1/token
98+
- user-authorization-uri: https://dev-158606.oktapreview.com/oauth2/default/v1/authorize
99+
- client-id: 0oafqwenodi6cPzSC0h7
100+
- client-secret: FLuPvd9Gf87Wu17Q6CAAFqK6WaIlPDdcKwQ9XplM
101+
- scope: openid email profile
102+
- resource:
103+
- user-info-uri: https://dev-158606.oktapreview.com/oauth2/default/v1/userinfo
104+
spring:
105+
profiles:
106+
- active: @spring.profiles.active@
107+
\ No newline at end of file
108+
+ active: @spring.profiles.active@
109+
+ security:
110+
+ oauth2:
111+
+ client:
112+
+ registration:
113+
+ okta:
114+
+ client-id: 0oafqwenodi6cPzSC0h7
115+
+ client-secret: FLuPvd9Gf87Wu17Q6CAAFqK6WaIlPDdcKwQ9XplM
116+
+ scope: openid email profile
117+
+ provider:
118+
+ okta:
119+
+ issuer: https://dev-158606.oktapreview.com/oauth2/default
120+
\ No newline at end of file

src/main/java/com/okta/developer/jugtours/config/OAuth2AuthenticationSuccessHandler.java

Lines changed: 0 additions & 68 deletions
This file was deleted.

src/main/java/com/okta/developer/jugtours/config/OAuth2Configuration.java

Lines changed: 0 additions & 98 deletions
This file was deleted.

0 commit comments

Comments
 (0)