I'm starting my application with Spring Boot on http server port 11218 and I have Undertow https listener which listen port 8090. Ssl is working fine, but I can't redirect from 11218 port to 8090. I tried to use Spring Security but received
org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'GET' not supported at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.handleNoMatch(RequestMappingInfoHandlerMapping.java:213) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.lookupHandlerMethod(AbstractHandlerMethodMapping.java:422) at org.springframework.web.servlet.handler.AbstractHandlerMethodMapping.getHandlerInternal(AbstractHandlerMethodMapping.java:367) at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:110) at org.springframework.web.servlet.mvc.method.RequestMappingInfoHandlerMapping.getHandlerInternal(RequestMappingInfoHandlerMapping.java:59) at org.springframework.web.servlet.handler.AbstractHandlerMapping.getHandler(AbstractHandlerMapping.java:395) at org.springframework.web.servlet.DispatcherServlet.getHandler(DispatcherServlet.java:1234) at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1016) at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:943) at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:898) at javax.servlet.http.HttpServlet.service(HttpServlet.java:645) at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) at javax.servlet.http.HttpServlet.service(HttpServlet.java:750) at io.undertow.servlet.handlers.ServletHandler.handleRequest(ServletHandler.java:74) at io.undertow.servlet.handlers.FilterHandler$FilterChainImpl.doFilter(FilterHandler.java:129) at ru.openbank.platform.filters.MDCFilter.doFilterInternal(MDCFilter.java:55) at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:119) at io.undertow.servlet.core.ManagedFilter.doFilter(ManagedFilter.java:61).
Request: http://127.0.0.1:11218/encashment/send
Spring Security:
private void redirect(HttpSecurity http) throws Exception {
http.requiresChannel()
.mvcMatchers("/encashment/send")
.requiresSecure()
.and().portMapper().http(11218).mapsTo(8090);
}
Undertow configuration:
@SneakyThrows
@Bean
public UndertowServletWebServerFactory undertowServletWebServerFactory() {
UndertowServletWebServerFactory undertowServletWebServerFactory = new UndertowServletWebServerFactory();
KeyStore trustStore = KeyStore.getInstance("JKS");
trustStore.load(new FileInputStream(trustStoreFile), trustStorePassword.toCharArray());
KeyManagerFactory keyManagerFactory =
KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
keyManagerFactory.init(trustStore, trustStorePassword.toCharArray());
TrustManagerFactory trustManagerFactory =
TrustManagerFactory.getInstance(TrustManagerFactory.getDefaultAlgorithm());
trustManagerFactory.init(trustStore);
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(keyManagerFactory.getKeyManagers(),
trustManagerFactory.getTrustManagers(),
new SecureRandom());
undertowServletWebServerFactory.addBuilderCustomizers(new UndertowBuilderCustomizer() {
@Override
public void customize(Undertow.Builder builder) {
builder.addHttpsListener(additionalPort, "127.0.0.1",
sslContext).setHandler(path().addPrefixPath("/encashment", websocket(
(exchange, channel) -> {
channel.resumeReceives();
})));
}
});
return undertowServletWebServerFactory;
}
My Controller:
@PostMapping("/send")
@ApiOperation("Передача информации об инкасации на Тибко")
public JsonItem<EncashmentInfoResponse> sendEncashmentInfo(@Valid @RequestBody EncashmentInfoDto encashmentInfoDto) {
encashmentInfoDto.setPersonId(authenticationUtil.getPersonId());
return encashmentService.sendEncashmentInfo(encashmentInfoDto);
}
question from:https://stackoverflow.com/questions/65941061/spring-security-redirect-to-https