@Test public void testAdd() throws Exception { int preSize = userMapper.selectAll().size(); User user = new User(); user.setName("ysjian003"); user.setPassword(new BCryptPasswordEncoder().encode("000")); user.setSex(User.Sex.MALE); userMapper.insert(user); assertEquals(preSize + 1, userMapper.selectAll().size()); }
@Override public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException { LOGGER.info("username = {}", username); try { User user = userMapper.selectByName(username); List<GrantedAuthority> roles = authorityMapper .selectByUserName(username) .stream() .map(authority -> new SimpleGrantedAuthority(authority.getRole().name())) .collect(Collectors.toList()); return new org.springframework.security.core.userdetails.User( user.getName(), user.getPassword(), roles); } catch (SQLException e) { throw new UsernameNotFoundException("SQLException", e); } }
@Override public void add(User user) throws SQLException { user.setPassword(new BCryptPasswordEncoder().encode(user.getPassword())); userMapper.insert(user); }