-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathWebSecurityConfig.java
More file actions
53 lines (46 loc) · 2.21 KB
/
Copy pathWebSecurityConfig.java
File metadata and controls
53 lines (46 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.docusign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.security.web.authentication.LoginUrlAuthenticationEntryPoint;
import org.springframework.security.web.savedrequest.HttpSessionRequestCache;
import org.springframework.security.web.savedrequest.RequestCache;
import com.docusign.core.security.CustomAuthenticationFailureHandler;
@EnableWebSecurity
public class WebSecurityConfig {
@Autowired
public DSConfiguration dsConfiguration;
@Bean
public RequestCache requestCache() {
return new HttpSessionRequestCache();
}
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
http
.authorizeHttpRequests(authorize -> {
try {
authorize
.antMatchers("/", "/error**", "/assets/**", "/ds/mustAuthenticate**",
"/ds/authenticate**", "/ds/selectApi**", "/con001", "/pkce")
.permitAll()
.anyRequest().authenticated()
.and()
.exceptionHandling()
.authenticationEntryPoint(
new LoginUrlAuthenticationEntryPoint("/ds/mustAuthenticate"));
} catch (Exception e) {
throw new RuntimeException(e);
}
})
.requestCache().requestCache(requestCache()).and()
.oauth2Login(login -> login.failureHandler(new CustomAuthenticationFailureHandler()))
.oauth2Client(Customizer.withDefaults())
.logout(logout -> logout
.logoutSuccessUrl("/"))
.csrf().disable();
return http.build();
}
}