Closed thomasturrell closed 10 years ago
It looks like a bug in Spring Boot, but it should be really hard to trip. What are the steps to repeat, please?
Hi thank you for looking at this for me.
I think I have tracked it down to spring-boot-starter-actuator in the POM with spring-boot-starter-security also in the POM when the POM packaging is set to war. All though I am at a loss to explain why it would be an issue.
My POM looks like:
<?xml version="1.0" encoding="UTF-8"?>
Note the inclusion of
I have modified WebSecurityConfig inline with https://github.com/dsyer/gs-securing-web/commit/134efa3345e4839852aa8950782aa74976959498#diff-e145d2dcdffe878840b80169748b5e09R24
package hello;
import org.springframework.context.annotation.Configuration; import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; import org.springframework.security.config.annotation.authentication.configurers.GlobalAuthenticationConfigurerAdapter; import org.springframework.security.config.annotation.web.builders.HttpSecurity; import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; import org.springframework.security.config.annotation.web.servlet.configuration.EnableWebMvcSecurity;
@Configuration @EnableWebMvcSecurity public class WebSecurityConfig extends WebSecurityConfigurerAdapter { @Override protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/home").permitAll()
.anyRequest().authenticated();
http
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Configuration
protected static class AuthenticationConfiguration extends
GlobalAuthenticationConfigurerAdapter {
@Override
public void init(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("password").roles("USER");
}
}
}
I have also included the following class as per the guide 'Converting a Spring Boot JAR Application to a WAR using Maven'
package hello;
import org.springframework.boot.builder.SpringApplicationBuilder; import org.springframework.boot.context.web.SpringBootServletInitializer;
public class WebInitializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(Application.class);
}
}
When I run the resulting war file in tomcat I get the aforementioned 'HTTP Status 500 - No matching constant for [0]' error when trying to access any secured page such as http://localhost:8080/gs-securing-web/hello.
The solution seems to be to remove spring-boot-starter-actuator but since I am deploying on Elastic Beanstalk I liked the /health endpoint that actuator gives me.
If you like the Actuator, there's no reason to remove it, if you use one of the workarounds in the issue you referenced. Namely: 1) add @EnableGlobalMethodSecurity
, 2) move the authentication manager declaration out to a GlocalAuthenticationConfigurerAdapter
(init method), 3) downgrade to Boot 1.1.4.RELEASE, 4) Upgrade to Boot 1.1.6.BUILD-SNAPSHOT.
Thank you, downgrading seems to allow me to run actuator with security and deploy as a war. I didn't check 1.1.6.
Hi Sorry to be a pain could you indulge me? Can you check out https://github.com/tommyturrell/gs-securing-web/tree/master/complete I still can't get Actuator to work with either 1.1.5 or 1.1.6 when using Security and packaging as a WAR file. If I remove Actuator everything works, if I drop down to version 1.1.4 it also works.
A comparison of my changes can be found at https://github.com/tommyturrell/gs-securing-web/compare/spring-guides:master...master
Every time I open http://localhost:8080/gs-securing-web/hello I get a HTTP Status 500 - No matching constant for [0] error.
It might just be me or my environment but I think it's a bug.
That's an unrelated problem (https://github.com/spring-projects/spring-boot/issues/1369), and only when you deploy a WAR. Should be fixed now (and it didn't happen in 1.1.4, but the response codes in the metrics filter are not accurate there).
Hi
When I follow the guide 'Converting a Spring Boot JAR Application to a WAR using Maven' (http://spring.io/guides/gs/convert-jar-to-war-maven/) to convert gs-securing-web to a WAR file for deployment to an external application server I get the following error when I try to access secured pages:
This is a bit of a show stopper as it means I can't deploy any spring boot project that uses spring security to a production server.