我有一个 Spring Boot 应用程序,我试图在其中创建一个自定义安全过滤器,如下所示:
public class CustomSecurityFilter extends GenericFilterBean {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
//it should be invoked only for "/needCustomSecurityOnThisURL"
chain.doFilter(request, response);
}
}
Run Code Online (Sandbox Code Playgroud)
现在,我只想在特定的 URL 上调用它,但我无法弄清楚这一点。我正在使用以下代码调用它:
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.anyRequest().authenticated()
.and()
.csrf().disable() // Disable CSRF Token
.httpBasic();
// Disable Session Management
http
.sessionManagement()
.sessionCreationPolicy(SessionCreationPolicy.STATELESS);
//want to add the Custom Security Filter n it should …Run Code Online (Sandbox Code Playgroud) java spring restful-authentication spring-security spring-filter
我使用 Spring Boot 使用此处定义的步骤创建了一个 webservice当我尝试下载 wsdl 时,我必须在 url 中使用 .wsdl 。但是,当我使用 ?wsdl 时,没有下载 wsdl。当我在 url 中使用 ?wsdl 时,如何重写 url 以下载 wsdl?
我做了一个简单的 servlet 过滤器来减慢我的应用程序的响应速度:
import javax.servlet.*;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
public class DelayFilter implements Filter {
@Override
public void init(FilterConfig filterConfig) throws ServletException {}
@Override
public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
Integer seconds = 10;
try {
Thread.sleep(seconds * 1000);
} catch (InterruptedException e) {
throw new ServletException("Interrupted!");
}
HttpServletResponse response = (HttpServletResponse) resp;
response.setHeader("Cache-Control", "no-cache, must-revalidate");
chain.doFilter(req, resp);
}
@Override
public void destroy() {}
}
Run Code Online (Sandbox Code Playgroud)
我读了一堆文章,为应用程序注册它是这样的:在此处输入链接描述 通常有两种注册方法,一种用于使用web.xml,一种用于编程配置。我必须使用的应用程序不使用 XML,但也没有任何初始化程序类。配置是使用 Config Class 完成的,如下所示:
@Configuration
@EnableWebMvc …Run Code Online (Sandbox Code Playgroud) 我正在尝试热重新加载 Spring Boot 应用程序的内容安全策略(CSP)中的更改,即用户应该能够通过管理 UI 更改它,而无需重新启动服务器。
Spring Boot 中常规的做法是:
@Configuration
class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(HttpSecurity http) {
// ... lots more config here...
http.headers()
.addHeaderWriter(
StaticHeadersWriter(
"Content-Security-Policy",
"<some policy string>"
)
)
}
}
Run Code Online (Sandbox Code Playgroud)
...但这不允许在分配后重新配置。
我可以在运行时(重新)配置它吗?重新加载应用程序上下文不是一个选项,我只需要能够适应这个特定的设置。