|
|
|
@@ -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/**");
|
|
|
|
|
}*/
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|