Advertisement
Guest User

Untitled

a guest
Jul 5th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.50 KB | None | 0 0
  1. @Component
  2. public class LoginAuthenticationProvider implements AuthenticationProvider {
  3.  
  4. @Override
  5. public Authentication authenticate(Authentication authentication)
  6. throws AuthenticationException {
  7.  
  8. /* Aqui tento recuperar os cookies */
  9. RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
  10. HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
  11. /* Aqui tento recuperar os cookies */
  12.  
  13. String username = authentication.getName().toString();
  14. String password = (String) authentication.getCredentials();
  15.  
  16. if (! AuthenticationConvert.validaSchema(username)) {
  17. throw new SchemaNotFoundException();
  18. }
  19.  
  20. SecurityContextHolder.getContext().setAuthentication(authentication);
  21.  
  22.  
  23. Usuario usuario = usuarioService.findUsuario(AuthenticationConvert.getLogin(authentication.getName().toString()));
  24.  
  25. if (usuario == null)
  26. throw new UsernameNotFoundException("Usuário não encontrado.");
  27.  
  28. if (! usuario.getSenha().equalsIgnoreCase(password))
  29. throw new BadCredentialsException("Senha incorreta.");
  30.  
  31. return new UsernamePasswordAuthenticationToken(username, password, null);
  32. }
  33.  
  34. }
  35.  
  36. public void metodo(@CookieValue("nome") String cookie) {
  37.  
  38. }
  39.  
  40. public void metodo2(HttpServletResponse response) {
  41. Cookie cookie = new Cookie("chave", "valor");
  42. //configurações do cookie
  43. response.addCookie(cookie);
  44. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement