コード例 #1
0
 @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());
 }
コード例 #2
0
 @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);
   }
 }
コード例 #3
0
 @Override
 public void add(User user) throws SQLException {
   user.setPassword(new BCryptPasswordEncoder().encode(user.getPassword()));
   userMapper.insert(user);
 }