Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @Component
- public class LoginAuthenticationProvider implements AuthenticationProvider {
- @Override
- public Authentication authenticate(Authentication authentication)
- throws AuthenticationException {
- /* Aqui tento recuperar os cookies */
- RequestAttributes requestAttributes = RequestContextHolder.getRequestAttributes();
- HttpServletRequest request = ((ServletRequestAttributes) requestAttributes).getRequest();
- /* Aqui tento recuperar os cookies */
- String username = authentication.getName().toString();
- String password = (String) authentication.getCredentials();
- if (! AuthenticationConvert.validaSchema(username)) {
- throw new SchemaNotFoundException();
- }
- SecurityContextHolder.getContext().setAuthentication(authentication);
- Usuario usuario = usuarioService.findUsuario(AuthenticationConvert.getLogin(authentication.getName().toString()));
- if (usuario == null)
- throw new UsernameNotFoundException("Usuário não encontrado.");
- if (! usuario.getSenha().equalsIgnoreCase(password))
- throw new BadCredentialsException("Senha incorreta.");
- return new UsernamePasswordAuthenticationToken(username, password, null);
- }
- }
- public void metodo(@CookieValue("nome") String cookie) {
- }
- public void metodo2(HttpServletResponse response) {
- Cookie cookie = new Cookie("chave", "valor");
- //configurações do cookie
- response.addCookie(cookie);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement