最近,我在springbootsecurity中学习了一个身份验证和授权教程,我想当谈到sql时,我会迷失方向。虽然它没有显示任何错误,即使我输入了正确的用户名和密码,它仍然显示错误的凭据。这是我的密码:
userdetailsserviceimpl.java
@Override
public UserDetails loadUserByUsername(String userName) throws UsernameNotFoundException {
WebUser appUser = this.appUserDAO.findUserAccount(userName);
if (appUser == null) {
System.out.println("User not found! " + userName);
throw new UsernameNotFoundException("User " + userName + " was not found in the database");
}
System.out.println("Found User: " + appUser);
// [ROLE_USER, ROLE_ADMIN,..]
List<String> roleNames = this.appRoleDAO.getRoleNames(appUser.getId());
List<GrantedAuthority> grantList = new ArrayList<GrantedAuthority>();
if (roleNames != null) {
for (String role : roleNames) {
// ROLE_USER, ROLE_ADMIN,..
GrantedAuthority authority = new SimpleGrantedAuthority(role);
grantList.add(authority);
}
}
UserDetails userDetails = (UserDetails) new User(appUser.getUsername(), //
appUser.getPass(), grantList);
return userDetails;
}
webusermapper.java文件
public static final String BASE_SQL //
= "Select u.Id, u.Username, u.Pass From User u ";
@Override
public WebUser mapRow(ResultSet rs, int rowNum) throws SQLException {
Long userId = rs.getLong("Id");
String userName = rs.getString("Username");
String encrytedPassword = rs.getString("Pass");
return new WebUser(userId, userName, encrytedPassword);
}
Web安全配置.java
@Bean
public BCryptPasswordEncoder passwordEncoder() {
BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
return bCryptPasswordEncoder;
}
@Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
// Setting Service to find User in the database.
// And Setting PassswordEncoder
auth.userDetailsService(userDetailsService).passwordEncoder(passwordEncoder());
}
这是我的数据库:
它返回以下错误:
Found User: test/$2y$12$MemyV61IuKV7SAntLOEVqeLPPvl2snXjQwlk3RSFDmn5eWrRcHwxm
2018-10-21 20:32:57.110 WARN 1300 --- [nio-8080-exec-3] o.s.s.c.bcrypt.BCryptPasswordEncoder : Encoded password does not look like BCrypt
密码是123。即使我在密码里输入了“123”,我也不知道为什么它不起作用。希望你能帮我。非常感谢
1条答案
按热度按时间jaql4c8m1#
尝试使用bcrypt编码器在服务器端对客户端进行编码。