@Test public void testIsLoginValidEmptyParams() { assertNull(userService.isLoginValid(null, null) ); assertNull(userService.isLoginValid("", null)); assertNull(userService.isLoginValid(null, "")); verifyZeroInteractions(userRepository, shaPasswordEncoder); }
public User isLoginValid(String username, String pass) { if(!StringUtils.hasText(username) || !StringUtils.hasText(pass)) { return null; } String password = new String(Base64.decodeBase64(pass.getBytes())); User u = userRepository.findByUsername(username); if(u == null) { return null; } if(!u.getPassword().equals(shaPasswordEncoder.encodePassword(password, u.getSalt()))) { return null; } return u; }
UserService { public User isLoginValid(String username, String pass) { if(!StringUtils.hasText(username) || !StringUtils.hasText(pass)) { return null; } String password = new String(Base64.decodeBase64(pass.getBytes())); User u = userRepository.findByUsername(username); if(u == null) { return null; } if(!u.getPassword().equals(shaPasswordEncoder.encodePassword(password, u.getSalt()))) { return null; } return u; } }
UserService { public User isLoginValid(String username, String pass) { if(!StringUtils.hasText(username) || !StringUtils.hasText(pass)) { return null; } String password = new String(Base64.decodeBase64(pass.getBytes())); User u = userRepository.findByUsername(username); if(u == null) { return null; } if(!u.getPassword().equals(shaPasswordEncoder.encodePassword(password, u.getSalt()))) { return null; } return u; }  }
UserService { public User isLoginValid(String username, String pass) { if(!StringUtils.hasText(username) || !StringUtils.hasText(pass)) { return null; } String password = new String(Base64.decodeBase64(pass.getBytes())); User u = userRepository.findByUsername(username); if(u == null) { return null; } if(!u.getPassword().equals(shaPasswordEncoder.encodePassword(password, u.getSalt()))) { return null; } return u; }  void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret); }
UserService { public User isLoginValid(String username, String pass) { if(!StringUtils.hasText(username) || !StringUtils.hasText(pass)) { return null; } String password = new String(Base64.decodeBase64(pass.getBytes())); User u = userRepository.findByUsername(username); if(u == null) { return null; } if(!u.getPassword().equals(shaPasswordEncoder.encodePassword(password, u.getSalt()))) { return null; } return u; }  void create(String username, String password, String role); User isLoginValid(String username, String pass); User findByUsername(String username); User createUserToken(String username, String secret); User validateUser(String token, String secret);  }