In a Spring Boot securityproject I get a Whitelabel Error Page when trying to be redirected from the login (after typed username and password) to the chosen page. The details are if I begin with the views that are jsp-files.
The start.jsp
only have one purpose, to redirect to test.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
<title>Startpage</title>
</head>
<body>
<p>Click <a href="/test">here</a> Start.</p>
</body>
</html>
The securitysetting for start.jsp
is permitAll and the setting for test.jsp
is authenticated so before test.jsp
login.jsp
will be called to type username and password
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
<title>Login</title>
</head>
<body>
<form method="POST" action="/login">
User Name : <input type="text" name="username"/>
Password: <input type="password" name="password"/>
<button type="submit">Submit</button>
</form>
</body>
</html>
and the endpage test.jsp
looks like this
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-
8859-1">
<title>Insert title here</title>
</head>
<body>
Hi
</body>
</html>
The errormessage is
Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this as a fallback. Thu Mar 01 21:43:40 CET 2018 There was an unexpected error (type=Forbidden, status=403). Could not verify the provided CSRF token because your session was not found.
It is run on my localhost as a http without any ssl or any other securitysettings chosen except for the Spring Boot Securitydependency in the pom.xml-file.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
The Mvc is handled by
package com.proj.db_proj;
import org.springframework.context.annotation.Configuration;
import
org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import
org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter;
@Configuration
public class MvcConfig extends WebMvcConfigurerAdapter {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/login").setViewName("login");
registry.addViewController("/startpage").setViewName("startpage");
registry.addViewController("/test").setViewName("test");
registry.addViewController("/").setViewName("start");
}
}
and the Websecurity with the authentication and configuration
package com.proj.db_proj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.
builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.
web.builders.HttpSecurity;
import org.springframework.security.config.annotation.
web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.¨
web.configuration.WebSecurityConfigurerAdapter;
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http
.authorizeRequests()
.antMatchers("/", "/start").permitAll()
.anyRequest().authenticated()
.and()
.formLogin()
.loginPage("/login")
.permitAll()
.and()
.logout()
.permitAll();
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth)
throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password("user").roles("USER");
}
}
Anyone can see any error or know why I get the Whitelabel error page? I have followed manuals and checked tutorials and also questions here on stackoverflow without any answers.