Bypass Spring security authentication for remote devtools endpoint
Closes gh-17878
This commit is contained in:
@@ -23,10 +23,13 @@ import javax.servlet.Filter;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.boot.autoconfigure.AutoConfigureAfter;
|
||||
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
|
||||
import org.springframework.boot.autoconfigure.security.SecurityProperties;
|
||||
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties;
|
||||
import org.springframework.boot.autoconfigure.web.ServerProperties.Servlet;
|
||||
import org.springframework.boot.context.properties.EnableConfigurationProperties;
|
||||
@@ -45,7 +48,11 @@ import org.springframework.boot.devtools.restart.server.SourceFolderUrlFilter;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.core.annotation.Order;
|
||||
import org.springframework.http.server.ServerHttpRequest;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
|
||||
|
||||
/**
|
||||
* {@link EnableAutoConfiguration Auto-configuration} for remote development support.
|
||||
@@ -53,12 +60,14 @@ import org.springframework.http.server.ServerHttpRequest;
|
||||
* @author Phillip Webb
|
||||
* @author Rob Winch
|
||||
* @author Andy Wilkinson
|
||||
* @author Madhura Bhave
|
||||
* @since 1.3.0
|
||||
*/
|
||||
@Configuration(proxyBeanMethods = false)
|
||||
@Conditional(OnEnabledDevToolsCondition.class)
|
||||
@ConditionalOnProperty(prefix = "spring.devtools.remote", name = "secret")
|
||||
@ConditionalOnClass({ Filter.class, ServerHttpRequest.class })
|
||||
@AutoConfigureAfter(SecurityAutoConfiguration.class)
|
||||
@EnableConfigurationProperties({ ServerProperties.class, DevToolsProperties.class })
|
||||
public class RemoteDevToolsAutoConfiguration {
|
||||
|
||||
@@ -127,4 +136,25 @@ public class RemoteDevToolsAutoConfiguration {
|
||||
|
||||
}
|
||||
|
||||
@Configuration
|
||||
@Order(SecurityProperties.BASIC_AUTH_ORDER - 1)
|
||||
@ConditionalOnClass(WebSecurityConfigurerAdapter.class)
|
||||
static class SecurityConfiguration extends WebSecurityConfigurerAdapter {
|
||||
|
||||
private final String url;
|
||||
|
||||
SecurityConfiguration(DevToolsProperties devToolsProperties, ServerProperties serverProperties) {
|
||||
Servlet servlet = serverProperties.getServlet();
|
||||
String servletContextPath = (servlet.getContextPath() != null) ? servlet.getContextPath() : "";
|
||||
this.url = servletContextPath + devToolsProperties.getRemote().getContextPath() + "/restart";
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
http.requestMatcher(new AntPathRequestMatcher(this.url)).authorizeRequests().anyRequest().anonymous().and()
|
||||
.csrf().disable();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user