Skip to content

Commit

Permalink
fix project
Browse files Browse the repository at this point in the history
  • Loading branch information
rieckpil committed Jan 22, 2024
1 parent 4d36cd2 commit 5fa68d2
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.rieckpil.blog;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import jakarta.validation.constraints.NotEmpty;
import jakarta.validation.constraints.NotNull;
import java.util.HashSet;
import java.util.Objects;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.rieckpil.blog;

import jakarta.annotation.PostConstruct;
import org.springframework.stereotype.Service;

import javax.annotation.PostConstruct;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,21 +1,26 @@
package de.rieckpil.blog;

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.WebSecurityConfigurerAdapter;
import org.springframework.security.web.SecurityFilterChain;

import static org.springframework.security.config.Customizer.withDefaults;

@Configuration
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
public class WebSecurityConfig {

@Override
protected void configure(HttpSecurity http) throws Exception {
@Bean
public SecurityFilterChain configure(HttpSecurity http) throws Exception {
http
.authorizeRequests(authorize -> authorize
.mvcMatchers(HttpMethod.GET, "/dashboard").permitAll()
.mvcMatchers("/api/users/**").authenticated()
.mvcMatchers("/**").authenticated()
.authorizeHttpRequests(authorize -> authorize
.requestMatchers(HttpMethod.GET, "/dashboard").permitAll()
.requestMatchers("/api/users/**").authenticated()
.requestMatchers("/**").authenticated()
)
.httpBasic();
.httpBasic(withDefaults());

return http.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.context.annotation.Import;
import org.springframework.test.web.reactive.server.EntityExchangeResult;
import org.springframework.test.web.reactive.server.WebTestClient;
import org.springframework.test.web.servlet.MockMvc;
Expand All @@ -13,6 +14,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;

@Import(WebSecurityConfig.class)
@WebMvcTest(DashboardController.class)
class DashboardControllerTest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.annotation.Import;
import org.springframework.security.test.context.support.WithMockUser;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
Expand All @@ -15,6 +16,7 @@
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;

@Import(WebSecurityConfig.class)
@WebMvcTest(UserController.class)
class UserControllerMockMvcTest {

Expand Down

0 comments on commit 5fa68d2

Please sign in to comment.