diff --git a/README.md b/README.md index f0933e8..3b5c309 100644 --- a/README.md +++ b/README.md @@ -23,4 +23,11 @@ artemis: enabled: true sendAdminDetails: true destination: http://localhost:8081 +``` + +We use basic authentication for getting the data from the telemetry service. You will need to adjust the `application.yml` of the telemetry service accordingly: +``` +telemetry: + user: + password: ``` \ No newline at end of file diff --git a/build.gradle b/build.gradle index 8b2bf6b..732b94e 100644 --- a/build.gradle +++ b/build.gradle @@ -20,6 +20,7 @@ repositories { dependencies { implementation "org.springframework.boot:spring-boot-starter-data-jpa" implementation "org.springframework.boot:spring-boot-starter-web" + implementation "org.springframework.boot:spring-boot-starter-security" implementation "org.hibernate.orm:hibernate-community-dialects:${hibernate_version}" implementation "org.apache.commons:commons-lang3" implementation "com.zaxxer:HikariCP" diff --git a/src/main/java/de/tum/cit/ase/artemistelemetry/security/SecurityConfig.java b/src/main/java/de/tum/cit/ase/artemistelemetry/security/SecurityConfig.java new file mode 100644 index 0000000..4c46ee2 --- /dev/null +++ b/src/main/java/de/tum/cit/ase/artemistelemetry/security/SecurityConfig.java @@ -0,0 +1,50 @@ +package de.tum.cit.ase.artemistelemetry.security; + +import org.springframework.beans.factory.annotation.Value; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.http.HttpMethod; +import org.springframework.security.config.annotation.web.builders.HttpSecurity; +import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity; +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.provisioning.InMemoryUserDetailsManager; +import org.springframework.security.web.SecurityFilterChain; + +@Configuration +@EnableWebSecurity +public class SecurityConfig { + + @Value("${telemetry.user}") + private String telemetryUser; + + @Value("${telemetry.password}") + private String telemetryPassword; + + + + @Bean + public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception { + http + .csrf(csrf -> csrf.disable()) + .authorizeHttpRequests(auth -> auth + .requestMatchers(HttpMethod.GET, "/api/telemetry/**").authenticated() + .anyRequest().permitAll() + ) + .httpBasic(httpBasic -> {}); + + return http.build(); + } + + @Bean + public UserDetailsService userDetailsService() { + UserDetails user = User.withDefaultPasswordEncoder() + .username(telemetryUser) + .password(telemetryPassword) + .roles("USER") + .build(); + + return new InMemoryUserDetailsManager(user); + } +} \ No newline at end of file