java - spring boot:登录后调用时出现 404
问题描述
我知道有很多这样的问题,但我发现没有任何东西可以帮助我解决这个问题。我正在使用具有安全性的 Spring Boot 来处理登录,并带有自定义登录页面。这是我的配置:
@SpringBootApplication
public class CompetencyMatrixApplication {
public static void main(String[] args) {
SpringApplication.run(CompetencyMatrixApplication.class, args);
}
}
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter
{
private final UserDetailsService userDetailsService;
public SecurityConfig(UserDetailsService userDetailsService)
{
this.userDetailsService = userDetailsService;
}
@Override
protected void configure(AuthenticationManagerBuilder auth) throws Exception {
auth.userDetailsService(userDetailsService);
}
@Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
.antMatchers("/", "/matrix", "/matrix/show", "/cas/getImage", "/documentModal").access("hasRole('2')")
.antMatchers("/matrix/fromFile", "/matrix/upload").access("hasRole('1')")
.antMatchers("/cas/new", "/cas/uploadImage").access("hasRole('1')")
.antMatchers("/department/**", "/departmentType/**").access("hasRole('1')")
.antMatchers("/employee/**").access("hasRole('1')")
.antMatchers("/position", "/position/**").access("hasRole('1')")
.antMatchers("/login").permitAll()
.antMatchers("/resources/**").permitAll()
.and().formLogin()
.loginPage("/sign-in").permitAll()
.defaultSuccessUrl("/",true)
.failureUrl("/sign-in?error")
.usernameParameter("email")
.passwordParameter("password")
.and().logout().logoutSuccessUrl("/sign-in?logout")
.and().exceptionHandling().accessDeniedPage("/403");
}
}
和登录页面(只是表单部分)
<c:url var="loginUrl" value="/login"/>
<form action="${loginUrl}" method="post">
<div class="mb-4">
<label for="email" class="block text-gray-700 text-sm font-bold mb-2">Email</label>
<input id="email" type='text' name='email' value=''
class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500">
</div>
<div class="mb-4">
<label for="password" class="block text-gray-700 text-sm font-bold mb-2">Hasło</label>
<input id="password" type='password' name='password'
class="block appearance-none w-full bg-gray-200 border border-gray-200 text-gray-700 py-3 px-4 pr-8 rounded leading-tight focus:outline-none focus:bg-white focus:border-gray-500">
</div>
<input name="submit" type="submit" value="Zaloguj"
class="shadow bg-purple-500 hover:bg-purple-400 focus:shadow-outline focus:outline-none text-white font-bold py-2 px-4 rounded"/>
</form>
所以我得到了我的登录自定义页面,但是当我提交它时,我得到了 404 Whitelabel 错误页面。我在这里想念什么?我看到的每个示例都只是使用默认的 /login url 来发布登录详细信息并且它有效,我的显然甚至没有到达 UserDetailsService
解决方案
发现了问题,如果有人来这里寻找解决方案,对我来说添加
http.csrf().disable();
成功了
推荐阅读
- javascript - 单击时添加折线并在鼠标光标上显示下一个点
- python - Python中try子句的无效语法错误
- ajax - 呈现 AJAX 响应的 HTML
- azure - 为 Azure 存储访问配置独立 Spark
- javascript - 在 javascript 中,如何获取 setattribute 值来引用变量?
- google-drive-api - 我可以在云网站上使用 G-Drive 吗?
- java - AWS Lambda Java SDK 连接超时问题
- swift4 - Sort方法的时间复杂度
- c++ - 在 C++ 中提取字符串
- c# - VS 代码错误“找不到 .NET CLI 工具...”