亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Spring Security 自定義登錄頁面不起作用

Spring Security 自定義登錄頁面不起作用

楊__羊羊 2023-07-28 16:32:42
我正在制作企業 Web 應用程序,我已經構建了自定義登錄頁面,但不知怎的,只有 Spring Security 登錄頁面出現,而不是我的自定義登錄頁面。下面是我的安全配置類。請幫忙。@Configuration@EnableWebSecuritypublic class SecurityConfiguration extends WebSecurityConfigurerAdapter {@Autowiredpublic void configureGlobalSecurity(AuthenticationManagerBuilder auth)        throws Exception {    auth.inMemoryAuthentication().withUser("test").password("pwd123")            .roles("USER", "ADMIN");}@Overrideprotected void configure(HttpSecurity http) throws Exception {    http            .authorizeRequests()            .antMatchers("/login").permitAll()            .antMatchers("/", "/*todo*/**").access("hasRole('USER')").and()            .formLogin();        http.csrf().disable();}
查看完整描述

3 回答

?
qq_遁去的一_1

TA貢獻1725條經驗 獲得超8個贊

看起來一切都很好,這對我來說是工作:


@Override

protected void configure(HttpSecurity http) throws Exception {

? ? http

? ? ? ? ?.authorizeRequests()

? ? ? ? ? ? ?.antMatchers("/todo/**").hasRole("USER")

? ? ? ? ? ? ?.antMatchers("/", "/home").permitAll()

? ? ? ? ? ? ?.antMatchers("/login").permitAll()

? ? ? ? ? ? ?.anyRequest().authenticated()

? ? ? ? ? ? ?.and()

? ? ? ? .formLogin()

? ? ? ? ? ? ?.loginPage("/login")

? ? ? ? ? ? ?.defaultSuccessUrl("/home")

? ? ? ? ? ? ?.permitAll()

? ? ? ? ? ? ?.and()

? ? ? ? ?.logout()?

? ? ? ? ? ? ?.logoutRequestMatcher(new AntPathRequestMatcher("/logout"))

? ? ? ? ? ? ?.logoutSuccessUrl("/home")

? ? ? ? ? ? ?.permitAll()

? ? ? ? ? ? ?.and()

? ? ? ? ?.exceptionHandling().accessDeniedPage("/403");

? }

查看完整回答
反對 回復 2023-07-28
?
幕布斯7119047

TA貢獻1794條經驗 獲得超8個贊

@Override

protected void configure(HttpSecurity http) throws Exception {

http.csrf().disable();

? ? ?http.authorizeRequests().antMatchers("/login").permitAll()

? ? ?.anyRequest().authenticated().and()

? ? ?.formLogin()

? ? ?.loginPage("/login")

? ? ?.defaultSuccessUrl("/home")

? ? ?.failureUrl("/login?error=true")

? ? ?.permitAll()

? ? ?.and()

? ? ?.logout()

? ? ?.logoutSuccessUrl("/login?logout=true")

? ? ?.invalidateHttpSession(true)

? ? ?.deleteCookies("JSESSIONID")

? ? ?.permitAll();

?}


查看完整回答
反對 回復 2023-07-28
?
侃侃無極

TA貢獻2051條經驗 獲得超10個贊

您必須指定自定義登錄頁面的 URL。


@Override

protected void configure(HttpSecurity http) throws Exception {

    http.authorizeRequests()

        .antMatchers("/login").permitAll()

        .antMatchers("/", "/*todo*/**").access("hasRole('USER')").and()

        .formLogin()


         // put the relative URL to your custom login here

             .loginPage("/login")

             .permitAll();

    http.csrf().disable();

}

希望這可以幫助。


查看完整回答
反對 回復 2023-07-28
  • 3 回答
  • 0 關注
  • 308 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號