Oauth setup

This commit is contained in:
2024-12-25 01:04:05 +01:00
parent aa4ed91b9d
commit e20be63e5e
3 changed files with 22 additions and 17 deletions

View File

@@ -38,6 +38,10 @@
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId> <artifactId>spring-boot-starter-security</artifactId>
</dependency> </dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-oauth2-client</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.springframework.boot</groupId> <groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId> <artifactId>spring-boot-starter-web</artifactId>

View File

@@ -0,0 +1,13 @@
package de.zendric.app.xpensely_server.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
class HomeController {
@GetMapping("/")
public String getAll() {
return "Welcome";
}
}

View File

@@ -2,31 +2,19 @@ package de.zendric.app.xpensely_server.security;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.Customizer;
import org.springframework.security.config.annotation.web.builders.HttpSecurity; 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.SecurityFilterChain;
@Configuration @Configuration
@EnableWebSecurity
public class SecurityConfig { public class SecurityConfig {
@Bean @Bean
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
http http.authorizeHttpRequests(auth -> auth
.authorizeHttpRequests(authorize -> authorize .anyRequest().authenticated()).oauth2Login(Customizer.withDefaults());
.anyRequest().permitAll() // Allow all requests without authentication
)
.csrf().disable(); // Disable CSRF for development purposes
return http.build(); return http.build();
} }
// @Bean
// public SecurityFilterChain securityFilterChain(HttpSecurity http) throws
// Exception {
// return http.authorizeHttpRequests(auth -> {
// auth.requestMatchers("/").permitAll();
// auth.anyRequest().permitAll();
// // auth.anyRequest().authenticated();
// }).oauth2Login(Customizer.withDefaults())
// .build();
// }
} }