У меня есть пользовательская форма входа с пружинной защитой, и при входе в систему я получаю 404
Вот моя веб-конфигурация
package coffee.web;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
@Configuration
public class WebConfig implements WebMvcConfigurer {
@Override
public void addViewControllers(ViewControllerRegistry registry) {
registry.addViewController("/").setViewName("/regular/index.html");
}
}
Вот моя конфигурация безопасности
package coffee.security;
import org.springframework.context.annotation.Bean;
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 SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.inMemoryAuthentication().withUser("peter").password("peter").authorities("ROLE_USER");
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests().antMatchers("/admin/**").hasRole("USER").antMatchers("/", "/**").permitAll()
.and().formLogin().loginPage("/regular/login.html").permitAll().defaultSuccessUrl("/admin/adminIndex.html").and().csrf().disable();
}
}
Вот моя html-форма для входа в систему
<head>
<link href="index.css" type="text/css" rel="stylesheet" />
<link href="adminIndex.css" type="text/css" rel="stylesheet" />
</head>
<body>
<div id="page">
<div id="bar"></div>
<header>
<h1><img id="logo" src="resources/logo.png" width="300" height="75" /></h1>
</header>
<section id="main">
<div id="container">
<div id="loginDiv">
<form name="login" id="login" action="login" method="POST">
<div id="formDiv">
<label for="addUsername" class="title">Username</label>
<span id="validateUsername" class="error"></span>
<input class="input" type="text" id="addUsername" name="username" />
<br />
<label for="addPassword" class="title">Password</label>
<span id="validatePassword" class="error"></span>
<input class="input" type="text" id="addPassword" name="password" />
<br />
<button id="submit" name="submit" type="submit" class="submit">submit</button>
</div>
</form>
</div>
</div>
</section>
</div>
</body>
Даже когда я отключаю авторизацию и включена только аутентификация, я все равно получаю 403код ошибки после входа в систему. Хотя я все еще мог перейти непосредственно к admin.adminIndex.html и он работает .. (с отключенной авторизацией и включенной только аутентификацией).
Хорошо, я обновил свой код безопасности с помощью "й () CSRF () отключить ();..»и теперь я получаю ошибку 404 not found, когда я вхожу в систему.