Skip to content

Commit 39c61c8

Browse files
authored
Merge pull request #6 from oktadeveloper/spring-boot-2.1m1
Upgrade to Spring Boot 2.1 M1
2 parents 7897015 + 104650e commit 39c61c8

4 files changed

Lines changed: 12 additions & 105 deletions

File tree

pom.xml

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

2121
<properties>
2222
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2323
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2424
<java.version>1.8</java.version>
25-
<spring-security.version>5.1.0.BUILD-SNAPSHOT</spring-security.version>
2625
<frontend-maven-plugin.version>1.6</frontend-maven-plugin.version>
2726
<node.version>v10.6.0</node.version>
2827
<yarn.version>v1.8.0</yarn.version>
@@ -184,7 +183,7 @@
184183
<pluginRepository>
185184
<id>spring-snapshots</id>
186185
<name>Spring Snapshots</name>
187-
<url>https://repo.spring.io/snapshot</url>
186+
<url>https://repo.spring.io/libs-snapshot</url>
188187
<snapshots>
189188
<enabled>true</enabled>
190189
</snapshots>
@@ -194,7 +193,7 @@
194193
<repository>
195194
<id>spring-snapshots</id>
196195
<name>Spring Snapshots</name>
197-
<url>http://repo.spring.io/snapshot</url>
196+
<url>http://repo.spring.io/libs-snapshot</url>
198197
</repository>
199198
</repositories>
200199
</project>
Lines changed: 6 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -1,137 +1,45 @@
11
package com.okta.developer.jugtours.config;
22

3-
import org.slf4j.Logger;
4-
import org.slf4j.LoggerFactory;
53
import org.springframework.context.annotation.Bean;
64
import org.springframework.context.annotation.Configuration;
75
import org.springframework.context.annotation.Profile;
86
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
97
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
10-
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
11-
import org.springframework.security.web.authentication.SavedRequestAwareAuthenticationSuccessHandler;
128
import org.springframework.security.web.csrf.CookieCsrfTokenRepository;
9+
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
1310
import org.springframework.security.web.savedrequest.RequestCache;
14-
import org.springframework.security.web.savedrequest.SavedRequest;
11+
import org.springframework.security.web.savedrequest.SimpleSavedRequest;
1512

16-
import javax.servlet.http.Cookie;
1713
import javax.servlet.http.HttpServletRequest;
1814
import javax.servlet.http.HttpServletResponse;
19-
import javax.servlet.http.HttpSession;
20-
import java.util.Collection;
21-
import java.util.List;
22-
import java.util.Locale;
23-
import java.util.Map;
2415

2516
@Configuration
2617
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {
27-
private final Logger log = LoggerFactory.getLogger(SecurityConfiguration.class);
2818

2919
@Override
3020
protected void configure(HttpSecurity http) throws Exception {
31-
RequestCache requestCache = refererRequestCache();
32-
SavedRequestAwareAuthenticationSuccessHandler handler = new SavedRequestAwareAuthenticationSuccessHandler();
33-
handler.setRequestCache(requestCache);
3421
http
35-
.exceptionHandling()
36-
.authenticationEntryPoint(new LoginUrlAuthenticationEntryPoint("/oauth2/authorization/okta"))
37-
.and()
38-
.oauth2Login()
39-
.successHandler(handler)
40-
.and()
22+
.oauth2Login().and()
4123
.csrf()
4224
.csrfTokenRepository(CookieCsrfTokenRepository.withHttpOnlyFalse())
4325
.and()
44-
.requestCache()
45-
.requestCache(requestCache)
46-
.and()
4726
.authorizeRequests()
4827
.antMatchers("/**/*.{js,html,css}").permitAll()
4928
.antMatchers("/", "/api/user").permitAll()
5029
.anyRequest().authenticated();
5130
}
5231

5332
@Bean
33+
@Profile("dev")
5434
public RequestCache refererRequestCache() {
55-
return new RequestCache() {
56-
private String savedAttrName = getClass().getName().concat(".SAVED");
57-
35+
return new HttpSessionRequestCache() {
5836
@Override
5937
public void saveRequest(HttpServletRequest request, HttpServletResponse response) {
6038
String referrer = request.getHeader("referer");
6139
if (referrer != null) {
62-
request.getSession().setAttribute(this.savedAttrName, referrerRequest(referrer));
63-
}
64-
}
65-
66-
@Override
67-
public SavedRequest getRequest(HttpServletRequest request, HttpServletResponse response) {
68-
HttpSession session = request.getSession(false);
69-
70-
if (session != null) {
71-
return (SavedRequest) session.getAttribute(this.savedAttrName);
72-
}
73-
74-
return null;
75-
}
76-
77-
@Override
78-
public HttpServletRequest getMatchingRequest(HttpServletRequest request, HttpServletResponse response) {
79-
return request;
80-
}
81-
82-
@Override
83-
public void removeRequest(HttpServletRequest request, HttpServletResponse response) {
84-
HttpSession session = request.getSession(false);
85-
86-
if (session != null) {
87-
log.debug("Removing SavedRequest from session if present");
88-
session.removeAttribute(this.savedAttrName);
40+
request.getSession().setAttribute("SPRING_SECURITY_SAVED_REQUEST", new SimpleSavedRequest(referrer));
8941
}
9042
}
9143
};
9244
}
93-
94-
private SavedRequest referrerRequest(final String referrer) {
95-
return new SavedRequest() {
96-
@Override
97-
public String getRedirectUrl() {
98-
return referrer;
99-
}
100-
101-
@Override
102-
public List<Cookie> getCookies() {
103-
return null;
104-
}
105-
106-
@Override
107-
public String getMethod() {
108-
return null;
109-
}
110-
111-
@Override
112-
public List<String> getHeaderValues(String name) {
113-
return null;
114-
}
115-
116-
@Override
117-
public Collection<String> getHeaderNames() {
118-
return null;
119-
}
120-
121-
@Override
122-
public List<Locale> getLocales() {
123-
return null;
124-
}
125-
126-
@Override
127-
public String[] getParameterValues(String name) {
128-
return new String[0];
129-
}
130-
131-
@Override
132-
public Map<String, String[]> getParameterMap() {
133-
return null;
134-
}
135-
};
136-
}
13745
}

src/main/resources/application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ spring:
66
client:
77
registration:
88
okta:
9-
client-id: 0oafrf327dXcTWh3j0h7
10-
client-secret: gXoRPO1uKff1X12MZpGIppbsyDDvi6QHFrfqooFU
9+
client-id: 0oafudk8gcSusspTN0h7
10+
client-secret: ZjAdC_75kgU3y1N7E5Kp_BmEY8LhNE3B3DyaFeBx
1111
scope: openid email profile
1212
provider:
1313
okta:

src/test/java/com/okta/developer/jugtours/JugToursApplicationTests.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
@RunWith(SpringRunner.class)
99
@SpringBootTest
10-
public class JugtoursApplicationTests {
10+
public class JugToursApplicationTests {
1111

1212
@Test
1313
public void contextLoads() {

0 commit comments

Comments
 (0)