Skip to content

Commit c9d77ac

Browse files
Fix SecurituConfig and Dockerfile
1 parent 3cc9997 commit c9d77ac

File tree

2 files changed

+19
-15
lines changed

2 files changed

+19
-15
lines changed

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ WORKDIR /
44

55
COPY / .
66

7-
ENV SPRING_PROFILES_ACTIVE=dev
7+
ENV SENTRY_AUTH_TOKEN=${SENTRY_AUTH_TOKEN}
88

99
RUN ./gradlew --no-daemon clean build
1010

11-
CMD ["java", "-jar", "build/libs/java-project-99-0.0.1-SNAPSHOT.jar"]
11+
CMD ["java", "-jar", "build/libs/app-0.0.1-SNAPSHOT.jar"]

src/main/java/hexlet/code/config/SecurityConfig.java

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@
2121

2222

2323
@Configuration
24-
@EnableMethodSecurity(prePostEnabled = true)
25-
//@EnableMethodSecurity
2624
@EnableWebSecurity
25+
@EnableMethodSecurity
26+
//@EnableMethodSecurity(prePostEnabled = true)
2727
public class SecurityConfig {
2828
private final JwtDecoder jwtDecoder;
2929
private final PasswordEncoder passwordEncoder;
@@ -51,22 +51,22 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http, HandlerMapping
5151
// По умолчанию все запрещено
5252
return http
5353
.csrf(csrf -> csrf.disable())
54-
// Disables the X-Frame-Options header for vie H2 base
55-
// .headers(headers -> headers.frameOptions(frameOptions -> frameOptions.disable()))
5654
.authorizeHttpRequests(auth -> auth
57-
.requestMatchers("/index.html").permitAll().requestMatchers("/favicon.ico").permitAll()
55+
// general
5856
.requestMatchers("/").permitAll()
59-
.requestMatchers("/assets/**").permitAll()
6057
.requestMatchers("/api/login").permitAll()
61-
.requestMatchers("/h2-console/**").permitAll()
58+
.requestMatchers(HttpMethod.GET, "/welcome").permitAll()
59+
// frontend
60+
.requestMatchers("/index.html").permitAll().requestMatchers("/favicon.ico").permitAll()
61+
.requestMatchers("/assets/**").permitAll()
62+
// OpenAPI
6263
.requestMatchers("/api-docs/**").permitAll()
6364
.requestMatchers("/v3/api-docs/**").permitAll()
6465
.requestMatchers("/swagger-ui.html").permitAll()
6566
.requestMatchers("/swagger-ui/**").permitAll()
66-
.requestMatchers(HttpMethod.GET, "/welcome").permitAll()
67+
// .requestMatchers("/h2-console/**").permitAll()
6768
.anyRequest().authenticated())
68-
.sessionManagement(session -> session
69-
.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
69+
.sessionManagement(session -> session.sessionCreationPolicy(SessionCreationPolicy.STATELESS))
7070
.oauth2ResourceServer(rs -> rs.jwt(jwt -> jwt.decoder(jwtDecoder)))
7171
.httpBasic(Customizer.withDefaults())
7272
.build();
@@ -84,12 +84,16 @@ public AuthenticationManager authenticationManager(HttpSecurity http) throws Exc
8484
}
8585

8686
/**
87-
* @param auth
87+
*
88+
* @param passwordEncoder
89+
* @param userService
8890
* @return AuthenticationProvider
8991
*/
9092
@Bean
91-
public AuthenticationProvider daoAuthProvider(AuthenticationManagerBuilder auth) {
92-
var provider = new DaoAuthenticationProvider(userService);
93+
public AuthenticationProvider daoAuthProvider(PasswordEncoder passwordEncoder,
94+
CustomUserDetailsService userService) {
95+
var provider = new DaoAuthenticationProvider();
96+
provider.setUserDetailsService(userService);
9397
provider.setPasswordEncoder(passwordEncoder);
9498
return provider;
9599
}

0 commit comments

Comments
 (0)