StruckCroissant / Game-DB

Game-DB is a game database search engine deployed on Docker and powered by Java Spring Boot and AngularJS
GNU General Public License v3.0
1 stars 0 forks source link

make configure file for endpoint constants #21

Closed github-actions[bot] closed 10 months ago

github-actions[bot] commented 2 years ago

https://github.com/StruckCroissant/Game-DB/blob/ce0447eeb9492536f57bbcbf51c2c9ced1c1fabf/api/main/java/com/StruckCroissant/GameDB/security/config/WebSecurityConfig.java#L28


package com.StruckCroissant.GameDB.security.config;

import com.StruckCroissant.GameDB.user.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
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.crypto.bcrypt.BCryptPasswordEncoder;

@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter  {

    private final UserService userService;

    private final BCryptPasswordEncoder bCryptPasswordEncoder;

    @Autowired
    public WebSecurityConfig(UserService userService, BCryptPasswordEncoder bCryptPasswordEncoder) {
        this.userService = userService;
        this.bCryptPasswordEncoder = bCryptPasswordEncoder;
    }

    // TODO make configure file for endpoint constants
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
                .csrf().disable()
                .authorizeRequests()
                    .antMatchers("/api/v*/user/**")
                    .permitAll()
                .anyRequest()
                .authenticated();

    }

    @Override
    protected void configure(AuthenticationManagerBuilder auth) throws Exception {
        auth.authenticationProvider(daoAuthenticationProvider());
    }

    @Bean
    public DaoAuthenticationProvider daoAuthenticationProvider(){
        DaoAuthenticationProvider provider =
                new DaoAuthenticationProvider();
        provider.setPasswordEncoder(bCryptPasswordEncoder);
        provider.setUserDetailsService(userService);
        return provider;
    }
}
StruckCroissant commented 10 months ago

Discovered that this isn't really possible with spring. Closing