Advertisement
Guest User

Untitled

a guest
Sep 30th, 2014
184
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. @Controller
  2.  
  3. public class PersonController {
  4.  
  5. @Autowired
  6. private PersonRepository personRepository;
  7.  
  8. @RequestMapping(value="/authenticate", method = RequestMethod.POST)
  9. public ResponseEntity<String> authenticate(@RequestBody Person person) {
  10.  
  11. Person authenticated = personRepository.findByUsernameAndPassword(person.getUsername(), person.getPassword());
  12.  
  13. if (authenticated == null) {
  14. return new ResponseEntity<>("UNKNOWN", HttpStatus.UNAUTHORIZED);
  15. }
  16. return new ResponseEntity<>(authenticated.getName(), HttpStatus.OK);
  17.  
  18. }
  19. }
  20. public interface PersonRepository extends JpaRepository<Person, Long> {
  21.  
  22. @RestResource(exported = false)
  23. @Override
  24. public void delete(Long id);
  25. public Person findByUsernameAndPassword(String username, String password);
  26.  
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement