Skip to content

Commit

Permalink
Modified the settings in the example based on the developer's recomme…
Browse files Browse the repository at this point in the history
…ndations.
  • Loading branch information
mklinkj committed Nov 30, 2023
1 parent f2c3a58 commit 406dcc4
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 14 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.mklinkj.qna.spring_security.config;

import org.mklinkj.qna.spring_security.security.HelloSecurityConfig;
import org.springframework.web.servlet.support.AbstractAnnotationConfigDispatcherServletInitializer;

public class HelloWebInitializer extends AbstractAnnotationConfigDispatcherServletInitializer {
Expand All @@ -10,7 +11,7 @@ protected Class<?>[] getRootConfigClasses() {

@Override
protected Class<?>[] getServletConfigClasses() {
return new Class<?>[] {HelloWebConfig.class};
return new Class<?>[] {HelloSecurityConfig.class, HelloWebConfig.class};
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,11 @@
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.provisioning.InMemoryUserDetailsManager;
import org.springframework.security.web.SecurityFilterChain;
import org.springframework.web.servlet.handler.HandlerMappingIntrospector;

@Slf4j
@Configuration
@EnableWebSecurity
public class HelloSecurityConfig {
@Bean
HandlerMappingIntrospector mvcHandlerMappingIntrospector() {
return new HandlerMappingIntrospector();
}

@Bean
UserDetailsService userDetailsService() {
val user =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,6 @@

@Slf4j
public class HelloSecurityInitializer extends AbstractSecurityWebApplicationInitializer {

public HelloSecurityInitializer() {
super(HelloSecurityConfig.class);
}

@Override
protected void beforeSpringSecurityFilterChain(ServletContext servletContext) {
LOGGER.info("### ServerInfo: {} ###", servletContext.getServerInfo()); // Tomcat 9.0.82
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,11 +47,14 @@ void testHttpStatus500() throws IOException, InterruptedException {
HttpRequest request =
HttpRequest.newBuilder() //
.uri(URI.create("http://localhost:%d".formatted(getGrettyRandomPort())))
.timeout(Duration.ofSeconds(5)) // 타임아웃 설정을 꼭 해야한다. 제대로 연결이 안될 때, 무한정 대기함.
.timeout(Duration.ofSeconds(5))
// 타임아웃을 설정해야 합니다. 제대로 연결되지 않은 경우 무기한 대기합니다.
// Be sure to set a timeout.
// Waiting indefinitely when there is no proper connection.
.build();

HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertThat(response.statusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR.value());
assertThat(response.statusCode()).isEqualTo(HttpStatus.OK.value());
}

@Test
Expand Down

0 comments on commit 406dcc4

Please sign in to comment.