Refactor admin component and update application properties for production setup

Gradle _jambotron_build
aplication.properties for dev and prod
This commit is contained in:
liosha84
2025-07-30 01:27:11 +03:00
parent 90b2eaa036
commit 4e030b2a52
118 changed files with 254 additions and 3488 deletions
@@ -31,7 +31,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;
//@CrossOrigin(origins = "*", maxAge = 3600)
@CrossOrigin(origins = "*", maxAge = 3600)
//@CrossOrigin(origins = "http://localhost:4200,https://a576-5-248-149-207.ngrok-free.app, https://pony-sincere-chimp.ngrok-free.app", maxAge = 3600, allowCredentials="true")
@RestController
@RequestMapping("/api/auth")
@@ -10,7 +10,6 @@ import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
@CrossOrigin(origins = "${app.origin}", maxAge = 3600, allowCredentials="true")
@RestController
@RequestMapping("/api")
public class RolesController {
@@ -1,6 +1,5 @@
package com.jambotronGroup.jambotron.controllers;
import com.jambotronGroup.jambotron.model.Tutorial;
import com.jambotronGroup.jambotron.model.User;
import com.jambotronGroup.jambotron.repository.UserRepository;
@@ -8,10 +7,8 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import java.util.*;
@CrossOrigin(origins = "${app.origin}", maxAge = 3600, allowCredentials="true")
@RestController
@RequestMapping("/api")
public class UsersController {
@@ -7,6 +7,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.env.Environment;
import org.springframework.security.authentication.AuthenticationManager;
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
import org.springframework.security.config.annotation.authentication.configuration.AuthenticationConfiguration;
@@ -35,6 +36,10 @@ import static org.springframework.security.config.Customizer.withDefaults;
//prePostEnabled = true)
@ComponentScan("com.jambotronGroup.jambotron.security")
public class WebSecurityConfig implements WebMvcConfigurer {// extends WebSecurityConfigurerAdapter {
@Autowired
private Environment _environment;
@Autowired
UserDetailsServiceImpl userDetailsService;
@@ -78,35 +83,7 @@ public class WebSecurityConfig implements WebMvcConfigurer {// extends WebSecuri
return new BCryptPasswordEncoder();
}
// @Override
// protected void configure(HttpSecurity http) throws Exception {
// http
// .csrf()
// .disable()
// .exceptionHandling().authenticationEntryPoint(unauthorizedHandler).and()
// .authorizeRequests()
//
//
// // //Доступ только для пользователей с ролью Администратор
// //.antMatchers("/api/users").hasRole("ADMIN")
// // .antMatchers("/news").hasRole("USER")
// //Доступ разрешен всем пользователей
// .antMatchers("/*", "/home", "/resources/**").permitAll()
// .antMatchers("/api/auth/**").permitAll()
// .antMatchers("/api/tutorials").permitAll()
// .antMatchers("/api/tutorials/**").permitAll()
// //.antMatchers("/api/test/**").permitAll()
// //Все остальные страницы требуют аутентификации
// .anyRequest().authenticated()
// .and()
// .sessionManagement()
// .sessionCreationPolicy(SessionCreationPolicy.STATELESS)
// .and()
// .addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
//
//
// //http.addFilterBefore(authenticationJwtTokenFilter(), UsernamePasswordAuthenticationFilter.class);
// }
@Bean
public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
@@ -126,8 +103,6 @@ public class WebSecurityConfig implements WebMvcConfigurer {// extends WebSecuri
//TODO: need check the puth
.requestMatchers("/api/public/zhipuai/image/**").permitAll()
// need for cerbot why i don't know
.requestMatchers("/.well-known/acme-challenge/**").permitAll()
// Access permitted for specific roles
.requestMatchers("/api/user/**").hasRole("USER")
@@ -167,7 +142,20 @@ public class WebSecurityConfig implements WebMvcConfigurer {// extends WebSecuri
*/
).redirectToHttps(withDefaults());
);
/* if(_environment.getProperty("app.cors_enabled") != null &&
_environment.getProperty("app.cors_enabled").equalsIgnoreCase("true")) {
http.cors(withDefaults());
} else {
http.cors(cors -> cors.disable());
}*/
if(_environment.getProperty("server.port") != null &&
_environment.getProperty("server.port").equalsIgnoreCase("443")) {
http.redirectToHttps(withDefaults());
}
http.authenticationProvider(authenticationProvider());
@@ -176,77 +164,18 @@ public class WebSecurityConfig implements WebMvcConfigurer {// extends WebSecuri
return http.build();
}
/*@Bean
/* @Bean
public CorsFilter corsFilter() {
CorsConfiguration corsConfiguration = new CorsConfiguration();
corsConfiguration.setAllowCredentials(true); // Allow credentials
corsConfiguration.addAllowedOrigin("http://localhost:4200/");
corsConfiguration.addAllowedHeader("*"); // Allow all headers
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
// config.setAllowCredentials(true);
// config.addAllowedOrigin("http://localhost:4200");
// config.addAllowedHeader("*");
// config.addAllowedMethod("*");
// source.registerCorsConfiguration("/**", config);
//
// config = new CorsConfiguration();
// config.setAllowCredentials(true);
// config.addAllowedOrigin("http://213.111.120.199");
// config.addAllowedHeader("*");
// config.addAllowedMethod("*");
// source.registerCorsConfiguration("/**", config);
// config = new CorsConfiguration();
// config.setAllowCredentials(false);
// config.addAllowedOrigin("http://www.jambotron.run.place");
// config.addAllowedHeader("*");
// config.addAllowedMethod("*");
// source.registerCorsConfiguration("/**", config);
config = new CorsConfiguration();
config.setAllowCredentials(false);
config.addAllowedOrigin("http://www.jambotron.run.place");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/api/user/**", config);
source.registerCorsConfiguration("/**", corsConfiguration); // Apply to all endpoints
return new CorsFilter(source);
}*/
/* public UrlBasedCorsConfigurationSource corsCongigSource() {
UrlBasedCorsConfigurationSource source = new UrlBasedCorsConfigurationSource();
CorsConfiguration config = new CorsConfiguration();
// config.setAllowCredentials(true);
// config.addAllowedOrigin("http://localhost:4200");
// config.addAllowedHeader("*");
// config.addAllowedMethod("*");
// source.registerCorsConfiguration("/**", config);
//
// config = new CorsConfiguration();
// config.setAllowCredentials(true);
// config.addAllowedOrigin("http://213.111.120.199");
// config.addAllowedHeader("*");
// config.addAllowedMethod("*");
// source.registerCorsConfiguration("/**", config);
// config = new CorsConfiguration();
// config.setAllowCredentials(false);
// config.addAllowedOrigin("http://www.jambotron.run.place");
// config.addAllowedHeader("*");
// config.addAllowedMethod("*");
// source.registerCorsConfiguration("/**", config);
config = new CorsConfiguration();
config.setAllowCredentials(false);
config.addAllowedOrigin("http://localhost:4200, http://www.jambotron.run.place");
config.addAllowedHeader("*");
config.addAllowedMethod("*");
source.registerCorsConfiguration("/api/user/**", config);
return source;
}*/
/* @Bean
public WebSecurityCustomizer webSecurityCustomizer() {
return (web) -> web.ignoring().requestMatchers("/images/**", "/js/**", "/webjars/**");
}*/
}