@Transactional public List getUserWithEmails(long userId){ User user = userDao.findUser(userId); if (user == null) { throw new UserNotFoundException("Could not find user with id = " + userId); } for(Email email:user.getEmails()){ email.getId(); } return user; }
@RequestMapping(value = "login", method = RequestMethod.GET) @ResponseBody public User login(@RequestParam String username, @RequestParam String password) { User user = userService.login(username, password); if (user == null) throw new UserNotFoundException(username); //or another exception, it's up to you return user; } }
throw new UserNotFoundException( "The username provided for the given group '" + oldGroup + "' does not exist");
//Tests what happens when a username is found in the backend public void testLoginSuccessful() { UserService mockUserService = EasyMock.createMock(UserService.class); EasyMock.expect(mockUserService.getUser("aUsername")).andReturn(new User(...)); EasyMock.replay(mockUserService); classUnderTest.setUserService(mockUserService); boolean isLoggedIn = classUnderTest.login("username"); assertTrue(isLoggedIn); } //Tests what happens when the user does not exist public void testLoginFailure() { UserService mockUserService = EasyMock.createMock(UserService.class); EasyMock.expect(mockUserService.getUser("aUsername")).andThrow(new UserNotFoundException()); EasyMock.replay(mockUserService); classUnderTest.setUserService(mockUserService); boolean isLoggedIn = classUnderTest.login("username"); assertFalse(isLoggedIn); }
throw new MalformedXmlException(e); }catch (UserNotFoundException e){ throw new UserNotFoundException(); } catch (Exception e){
if (user == null) { SECURITY_LOGGER.tracef("User '%s' not found.", userName); throw new UserNotFoundException(userName);
if (user == null) { SECURITY_LOGGER.tracef("User '%s' not found.", userName); throw new UserNotFoundException(userName);
if (userFound == false) { SECURITY_LOGGER.tracef("User '%s' not found in properties file.", userName); throw new UserNotFoundException(userName); if (userFound == false) { SECURITY_LOGGER.tracef("User '%s' not found in properties file.", userName); throw new UserNotFoundException(userName); if (userFound == false) { SECURITY_LOGGER.tracef("User '%s' not found in properties file.", userName); throw new UserNotFoundException(userName);
if (userFound == false) { SECURITY_LOGGER.tracef("User '%s' not found in properties file.", userName); throw new UserNotFoundException(userName); if (userFound == false) { SECURITY_LOGGER.tracef("User '%s' not found in properties file.", userName); throw new UserNotFoundException(userName); if (userFound == false) { SECURITY_LOGGER.tracef("User '%s' not found in properties file.", userName); throw new UserNotFoundException(userName);
if (credential == null) { SECURITY_LOGGER.tracef("User '%s' not found.", userName); throw new UserNotFoundException(userName); if (credential == null) { SECURITY_LOGGER.tracef("User '%s' not found.", userName); throw new UserNotFoundException(userName); if (credential == null) { SECURITY_LOGGER.tracef("User '%s' not found.", userName); throw new UserNotFoundException(userName);
if (credential == null) { SECURITY_LOGGER.tracef("User '%s' not found.", userName); throw new UserNotFoundException(userName); if (credential == null) { SECURITY_LOGGER.tracef("User '%s' not found.", userName); throw new UserNotFoundException(userName); if (credential == null) { SECURITY_LOGGER.tracef("User '%s' not found.", userName); throw new UserNotFoundException(userName);