-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #87 from Opetushallitus/spring-boot-3
KH-410 upgrade to springboot 3
- Loading branch information
Showing
9 changed files
with
120 additions
and
198 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 0 additions & 46 deletions
46
server/src/main/java/fi/vm/sade/koodisto/config/DevUserDetailsServiceConfiguration.java
This file was deleted.
Oops, something went wrong.
67 changes: 31 additions & 36 deletions
67
server/src/main/java/fi/vm/sade/koodisto/config/DevWebSecurityConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,59 +1,54 @@ | ||
package fi.vm.sade.koodisto.config; | ||
|
||
|
||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Profile; | ||
import org.springframework.security.authentication.dao.DaoAuthenticationProvider; | ||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | ||
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity; | ||
import org.springframework.security.config.annotation.method.configuration.EnableMethodSecurity; | ||
import org.springframework.security.config.annotation.web.builders.HttpSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; | ||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.security.core.userdetails.UserDetails; | ||
import org.springframework.security.core.userdetails.UserDetailsService; | ||
import org.springframework.security.crypto.password.PasswordEncoder; | ||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | ||
import org.springframework.security.provisioning.InMemoryUserDetailsManager; | ||
import org.springframework.security.web.SecurityFilterChain; | ||
import org.springframework.security.web.access.AccessDeniedHandler; | ||
|
||
@Profile("dev") | ||
@Configuration | ||
@EnableWebSecurity | ||
@EnableGlobalMethodSecurity(jsr250Enabled = false, prePostEnabled = false, securedEnabled = true) | ||
public class DevWebSecurityConfiguration extends WebSecurityConfigurerAdapter { | ||
|
||
UserDetailsService userDetailsService; | ||
PasswordEncoder passwordEncoder; | ||
|
||
@Autowired | ||
public DevWebSecurityConfiguration(UserDetailsService userDetailsService, PasswordEncoder passwordEncoder) { | ||
this.userDetailsService = userDetailsService; | ||
this.passwordEncoder = passwordEncoder; | ||
} | ||
|
||
@EnableMethodSecurity(jsr250Enabled = false, prePostEnabled = false, securedEnabled = true) | ||
public class DevWebSecurityConfiguration { | ||
@Bean | ||
public DaoAuthenticationProvider authProvider() { | ||
DaoAuthenticationProvider authProvider = new DaoAuthenticationProvider(); | ||
authProvider.setUserDetailsService(userDetailsService); | ||
authProvider.setPasswordEncoder(this.passwordEncoder); | ||
return authProvider; | ||
SecurityFilterChain filterChain(HttpSecurity http) throws Exception { | ||
http | ||
.httpBasic(it -> {}) | ||
.headers(headers -> headers.disable()) | ||
.csrf(csrf -> csrf.disable()) | ||
.securityMatcher("/**") | ||
.authorizeHttpRequests(authz -> authz | ||
.requestMatchers("/health").permitAll() | ||
.anyRequest().authenticated()) | ||
.exceptionHandling(exceptions -> exceptions.accessDeniedHandler(accessDeniedHandler())); | ||
return http.build(); | ||
} | ||
|
||
@Override | ||
protected void configure(HttpSecurity http) throws Exception { | ||
http.csrf().disable().authorizeRequests() | ||
.antMatchers("/health").permitAll() | ||
.anyRequest().authenticated() | ||
.and().exceptionHandling().accessDeniedHandler(accessDeniedHandler()) | ||
.and().httpBasic(); | ||
@Bean | ||
AccessDeniedHandler accessDeniedHandler() { | ||
return new CustomAccessDeniedHandler(); | ||
} | ||
|
||
@Bean | ||
public AccessDeniedHandler accessDeniedHandler() { | ||
return new CustomAccessDeniedHandler(); | ||
BCryptPasswordEncoder passwordEncoder() { | ||
return new BCryptPasswordEncoder(); | ||
} | ||
|
||
@Override | ||
protected void configure(AuthenticationManagerBuilder auth) throws Exception { | ||
auth.authenticationProvider(authProvider()); | ||
@Bean | ||
UserDetailsService userDetailsService() { | ||
UserDetails user = User.withUsername("devaaja") | ||
.password(passwordEncoder().encode("devaaja")) | ||
.roles("APP_OPPIJANUMEROREKISTERI_REKISTERINPITAJA") | ||
.build(); | ||
return new InMemoryUserDetailsManager(user); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 0 additions & 2 deletions
2
server/src/main/java/fi/vm/sade/koodisto/config/UrlConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
26 changes: 0 additions & 26 deletions
26
server/src/main/java/fi/vm/sade/koodisto/config/UserDetailsServiceConfiguration.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.