第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

Springboot 安全配置未重定向到 successUrl

Springboot 安全配置未重定向到 successUrl

尚方寶劍之說(shuō) 2021-11-17 15:27:32
我似乎不明白我的代碼有什么問(wèn)題。我正在嘗試使用 Springboot 安全登錄,一切似乎都正確,我可以在控制臺(tái)上看到我的用戶名和密碼。誰(shuí)能告訴我我出了什么問(wèn)題?這是我的 SecSecurityConfig 類(lèi)     package com.scanapp.config;     import com.scanapp.repositories.RoleRepository;     import com.scanapp.services.UserDetailsService;     import org.springframework.beans.factory.annotation.Autowired;     import org.springframework.beans.factory.annotation.Qualifier;     import org.springframework.context.annotation.Bean;     import org.springframework.context.annotation.Configuration;     import      org.springframework.security.authentication.dao.DaoAuthenticationProvider;     import org.springframework.security.crypto.password.PasswordEncoder;     @Configuration     @EnableWebSecurity     public class SecSecurityConfig extends WebSecurityConfigurerAdapter {     @Autowired     private RoleRepository roleRepository;    @Autowired    @Qualifier("myuserdet")    UserDetailsService userDetailsService;    protected void init(AuthenticationManagerBuilder auth) throws Exception {        System.out.println("I'm here");        auth.authenticationProvider(authProvider());    }    @Bean    public DaoAuthenticationProvider authProvider() {        System.out.println("got here");        DaoAuthenticationProvider authProvider = new        DaoAuthenticationProvider();        authProvider.setUserDetailsService(userDetailsService);        authProvider.setPasswordEncoder(passwordEncoder());        return authProvider;    }    @Bean    public PasswordEncoder passwordEncoder()      {        return new CustomPassword();       }
查看完整描述

3 回答

?
catspeake

TA貢獻(xiàn)1111條經(jīng)驗(yàn) 獲得超0個(gè)贊

嘗試從配置中刪除此塊。理論上,Spring 在幕后創(chuàng)建了所有這些 bean(自動(dòng)獲取您的 passwordEncoder 和 UserDetailsService)。


@Autowired

@Qualifier("myuserdet")

UserDetailsService userDetailsService;

protected void init(AuthenticationManagerBuilder auth) throws Exception {

    System.out.println("I'm here");

    auth.authenticationProvider(authProvider());

}


@Bean

public DaoAuthenticationProvider authProvider() {

    System.out.println("got here");

    DaoAuthenticationProvider authProvider = new 

   DaoAuthenticationProvider();

    authProvider.setUserDetailsService(userDetailsService);

    authProvider.setPasswordEncoder(passwordEncoder());

    return authProvider;

}

如果它不起作用,請(qǐng)嘗試重命名您的 UserDetailsService(盡管這是一個(gè)遠(yuǎn)景)。


查看完整回答
反對(duì) 回復(fù) 2021-11-17
?
呼如林

TA貢獻(xiàn)1798條經(jīng)驗(yàn) 獲得超3個(gè)贊

你的代碼中有很多噪音。


1.您定義了自定義密碼,它只是擴(kuò)展了 BCryptPasswordEncoder。我建議返回


@Bean

public PasswordEncoder passwordEncoder(){

    return new BCryptPasswordEncoder();

}

2. 您定義了另一個(gè) User 模型,該模型什么也不做,并且授予權(quán)限的列表為空。這很奇怪,因?yàn)槿绻麢?quán)限列表為空,它應(yīng)該會(huì)失敗。請(qǐng)退回進(jìn)口


org.springframework.security.core.userdetails.User;


//..

return new User(userName, encodedPassword, Collections.singletonList(new SimpleGrantedAuthority("USER")

3.最好為你的豆子使用另一個(gè)名字,而不是春天的名字。請(qǐng)將 UserDetailsService 重命名為 CustomUserDetailsService 并且不要在您的配置中使用限定符。


4.請(qǐng)確保當(dāng)您將密碼保存在數(shù)據(jù)庫(kù)中時(shí),它們會(huì)使用 BCryptPasswordEncoder 進(jìn)行哈希處理。


查看完整回答
反對(duì) 回復(fù) 2021-11-17
?
隔江千里

TA貢獻(xiàn)1906條經(jīng)驗(yàn) 獲得超10個(gè)贊

好的。另一個(gè)想法:根據(jù)文檔,此方法不應(yīng)返回 null:


@Override

public Collection<? extends GrantedAuthority> getAuthorities() {


        return null;

}

AuthorityUtils.NO_AUTHORITIES;而是返回。


理論上,它可以NullpointerException在您的 UserDetailsService 創(chuàng)建主體后的身份驗(yàn)證期間引發(fā)。如果那里有一個(gè)將軍catch (Exception e),那么它將被簡(jiǎn)單地嵌入到AuthenticationException.


- - 編輯


哎喲!


您還應(yīng)該將返回值更改為類(lèi)true中的最后四個(gè)方法MyUserPrincipal:


@Override

public boolean isAccountNonExpired() {

    return true;

}


@Override

public boolean isAccountNonLocked() {

    return true;

}


@Override

public boolean isCredentialsNonExpired() {

    return true;

}


@Override

public boolean isEnabled() {

    return true;

}

你的校長(zhǎng)總是被禁用和過(guò)期等等。當(dāng)然是不允許登錄的!:)


查看完整回答
反對(duì) 回復(fù) 2021-11-17
  • 3 回答
  • 0 關(guān)注
  • 160 瀏覽
慕課專(zhuān)欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)