具有REST服务的Spring Boot应用程序必须允许公共访问某些服务,同时将其他服务限制为仅授权用户.当configure(WebSecurity web)方法添加到SecurityConfig类中时,如下所示,a将403 error被发送到用户的Web浏览器,并且Spring Boot日志文件会发出错误消息,指出:
/registration-form has an empty filter list
Run Code Online (Sandbox Code Playgroud)
需要对下面的代码进行哪些具体更改才能将/registration-form服务成功提供给任何用户,包括匿名/未经身份验证的用户?
这是SecurityConfig班级:
@Configuration
@Order(SecurityProperties.ACCESS_OVERRIDE_ORDER)
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
protected static class SecurityConfiguration extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity webSecurity) throws Exception {
webSecurity.ignoring().antMatchers("/registration-form");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.formLogin()
.and()
.httpBasic().and()
.authorizeRequests()
.antMatchers("/login1").permitAll()
.antMatchers("/login2").permitAll()
.anyRequest().authenticated();
}
}
Run Code Online (Sandbox Code Playgroud)
这是完整的日志:
2016-04-07 16:42:18.548 INFO 8937 --- [nio-8001-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
2016-04-07 16:42:18.548 INFO …Run Code Online (Sandbox Code Playgroud) 在包装类型为war的Spring Boot应用程序中,我正在配置Spring MVC.据我所知,我们不必手动配置Dispatcher Servlet.但是,我用旧的web.xml样式我用来配置Dispatcher Servlet然后我用来传递contextClass和contextConfigLocation如下
<servlet>
<description>
</description>
<display-name>DispatcherServlet</display-name>
<servlet-name>DispatcherServlet</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<init-param>
<description>contextClass</description>
<param-name>contextClass</param-name>
<param-value>org.springframework.web.context.support.AnnotationConfigWebApplicationContext</param-value>
</init-param>
<init-param>
<description>contextConfigLocation</description>
<param-name>contextConfigLocation</param-name>
<param-value>com.xxx.yyy.jdorderspringmvcweb.config.SpringMvcConfig</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
Run Code Online (Sandbox Code Playgroud)
我相信这是为了表明SpringMvcConfig(我的Spring mvc配置的自定义类)是Spring MVC的配置类.
但是,在Spring boot中,如果自动配置Dispatcher Servlet,我如何将自定义类传递给调度程序Servlet?
在我的Spring Boot应用程序中,我的SpringMvcConfig类从WebMvcConfigurerAdapter扩展并使用@Configuration类进行注释
需要帮助...
我有一个使用Spring MVC的Spring引导应用程序(版本1.2.1RELEASE),我需要在JspServlet上设置开发初始化参数。在web.xml中,其外观如下所示:
<servlet>
<servlet-name>jsp</servlet-name>
<servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>
...
<init-param>
<param-name>development</param-name>
<param-value>false</param-value>
</init-param>
...
</servlet>
Run Code Online (Sandbox Code Playgroud)
我以为我可以做这样的事情:如何像在web.xml中那样配置spring-boot servlet?,但我不认为可以用新的JspServlet()替换新的MeteorServlet()并继续前进,因为我确定需要使用有效的ServletConfig调用JspServlet.init(ServletConfig config)。而且,当然,如果我在初始化时没有进行适当的尝试,该应用程序就会给我一个空指针异常(之所以发生,是因为私有的瞬时JspRuntimeContext rctxt;为空):
java.lang.NullPointerException: null
at org.apache.jasper.servlet.JspServlet.periodicEvent(JspServlet.java:361)
at org.apache.catalina.core.StandardWrapper.backgroundProcess(StandardWrapper.java:679)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1377)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1381)
at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1349)
at java.lang.Thread.run(Thread.java:745)
Run Code Online (Sandbox Code Playgroud)
此外,通过实现TomcatEmbeddedServletContainerFactory并提供一个Servlet来覆盖ServletConfig的init方法和getInitParameter方法,我们有一种真正的技巧来做到这一点,但它有点令人讨厌,所以我希望有更好的方法。任何指导将不胜感激。
最后,读取此init-param的代码在org.apache.jasper.EmbeddedServletOptions类中,并且似乎仅查找ServletConfig init参数,因此我无法将其指定为上下文参数(我认为)诸如server.context-parameters.name = value之类的很棒的东西。
String development = config.getInitParameter("development");
if (development != null) {
if (development.equalsIgnoreCase("true")) {
this.development = true;
} else if (development.equalsIgnoreCase("false")) {
this.development = false;
} else {
if (log.isWarnEnabled()) {
log.warn(Localizer.getMessage("jsp.warning.development"));
}
}
Run Code Online (Sandbox Code Playgroud)
}
而且,如果我仍然尝试点击该应用程序,则会出现以下错误:
java.lang.StringIndexOutOfBoundsException: String index out of range: 0
at java.lang.String.charAt(String.java:646) …Run Code Online (Sandbox Code Playgroud)