まずはJavaの設定を使用してSpringアプリケーションのセキュリティを設定する際にインデントを使用することをおすすめします。読みやすくするために役立ちます。
最初のインデントのすべての最上位メソッド(authRequest、formLogin、logout)はすべて、HTTPオブジェクト自体を構成/更新します。これらの要素はすべてorg.springframework.security.config.annotation.web.builders.HttpSecurity
クラスからのものです。
これらのクラスの子は、HTTPセキュリティ設定をさらに絞り込みます。
http
.authorizeRequests()
.antMatchers("/","/register*","/resetPassword","/forgotPassword","/login","/404")
.permitAll()
.antMatchers("/admin/**").hasAuthority("ADMIN")
.anyRequest().authenticated() // <--------
.and()
.formLogin()
.loginPage("/login")
.failureUrl("/login?error")
.defaultSuccessUrl("/dashboard")
.usernameParameter("email").passwordParameter("password")
.and()
.logout()
.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))
.logoutSuccessUrl("/login?logout")
.and()
.exceptionHandling()
.accessDeniedPage("/access-denied");
注.anyRequest().authenticated()
、具体的にどんな要求が認証されなければならないことを述べて。したがって、あなたのドメイン上に見つからないURLに移動しようとすると、404ページに行くのではなくログインするように求められます。
その文を削除して、欠落しているURLページに移動しようとすると、404ページにリダイレクトされます。