在线观看不卡亚洲电影_亚洲妓女99综合网_91青青青亚洲娱乐在线观看_日韩无码高清综合久久

鍍金池/ 問答/Java/ spring-security 認證失敗,如何解決?

spring-security 認證失敗,如何解決?

clipboard.png

clipboard.png

到了下面這一步怎么都驗證不通過,請高手指點一二

        final Authentication authentication = authenticationManager.authenticate(upToken);
回答
編輯回答
艷骨

已經(jīng)解決了,問題是出在我在JwtUser.java的時候,應(yīng)該是:

@JsonIgnore
@Override
public String getPassword() {
return password;
}

@Override
public String getUsername() {
return username;
}
可是我寫成了:
@JsonIgnore
@Override
public String getPassword() {
return null;
}

@Override
public String getUsername() {
return null;
}
2017年8月9日 22:03
編輯回答
女流氓

我在官方demo中找到如下代碼:

// Perform the security
        final Authentication authentication = authenticationManager.authenticate(
                new UsernamePasswordAuthenticationToken(
                        authenticationRequest.getUsername(),
                        authenticationRequest.getPassword()
                )
        );
        SecurityContextHolder.getContext().setAuthentication(authentication);
         // Reload password post-security so we can generate token
        final UserDetails userDetails = userDetailsService.loadUserByUsername(authenticationRequest.getUsername());
        final String token = jwtTokenUtil.generateToken(userDetails, device);

不知道是否對你有所幫助

2017年8月9日 09:21