当前位置: 首页 > 知识库问答 >
问题:

spring Boot:登录后调用时的404

赫连睿
2023-03-14

我知道有很多这样的问题,但我没有找到任何帮助我解决问题。我正在使用带有安全性的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>

共有1个答案

聂永怡
2023-03-14

我发现了问题,如果有人来这里寻找解决方案,我可以添加http.csrf().disable();来解决问题

 类似资料:
  • 在我的JMeter性能测试中,增加了用户线程,发现在登录之前调用了一些请求。所以这些请求都失败了。 在里面csv文件,添加了1000名用户,用户使用,并发出 有谁能帮我,我们如何才能做到这一点?

  • 似乎Springboot自动配置自己来使用Tomcat的Logback。我想禁用它,并使用我在类路径中提供的一个。 LoggerFactory不是LoggerContext,但Logback位于类路径上。删除Logback或类[org.slf4j.impl.SimpleLoggerFactory]的竞争实现(类org.slf4j.impl.SimpleLoggerFactory)对象必须是类ch.

  • 我尝试将springboot应用程序配置为每天登录一个文件,因此我将logback.xml配置为: 所以当我尝试运行我的应用程序时,我得到了这个错误:

  • 系统后端采用springboot,jwt认证,jwt设置了过期时间,并已实现jwt自动续签功能 请教一下:当用户退出登录时,是直接让前端删除用户jwt还是说后端将退出登录用户jwt添加到黑名单中?以及他们各自的安全性及其他考量?

  • 我几乎完成了我的一个项目(对我来说,我是一个初学者)。我想隐藏登录链接时,一个角色(管理员或用户)是登录到数据库。我还想显示一个名为“添加等级”的链接,仅当Admin(Manager)登录时。我正在使用spring boot、Tymeleaf、spring security5和h2&JDBC。 总之,我想隐藏或显示基于用户角色的HTML 更新:当我使用 匿名用户 这是我在navbar中包含或不包含

  • 我有一个NodeJS Express服务器运行在LocalHost:5000上,我的ReactJS服务器运行在端口LocalHost:3000上 我的package.json中有代理 从我的组件中,我尝试做常规的axios调用我的后端来打开窗口以选择谷歌用户...我有点不知道这部分应该如何工作。我的代码: 我得到的错误: