Class JWTAuthenticationFilter

  • All Implemented Interfaces:
    javax.servlet.Filter, org.springframework.beans.factory.Aware, org.springframework.beans.factory.BeanNameAware, org.springframework.beans.factory.DisposableBean, org.springframework.beans.factory.InitializingBean, org.springframework.context.ApplicationEventPublisherAware, org.springframework.context.EnvironmentAware, org.springframework.context.MessageSourceAware, org.springframework.core.env.EnvironmentCapable, org.springframework.web.context.ServletContextAware

    public class JWTAuthenticationFilter
    extends org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
    Classe que representa filtro de autenticação
    Author:
    José Henrique
    • Field Summary

      • Fields inherited from class org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

        SPRING_SECURITY_FORM_PASSWORD_KEY, SPRING_SECURITY_FORM_USERNAME_KEY
      • Fields inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter

        authenticationDetailsSource, eventPublisher, messages
      • Fields inherited from class org.springframework.web.filter.GenericFilterBean

        logger
    • Constructor Summary

      Constructors 
      Constructor Description
      JWTAuthenticationFilter​(org.springframework.security.authentication.AuthenticationManager authenticationManager, JWTUtil jwtUtil)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      org.springframework.security.core.Authentication attemptAuthentication​(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse)
      Tenta fazer a autenticação de usuário
      protected void successfulAuthentication​(javax.servlet.http.HttpServletRequest httpServletRequest, javax.servlet.http.HttpServletResponse httpServletResponse, javax.servlet.FilterChain filterChain, org.springframework.security.core.Authentication authentication)
      Retorna um token JWT para o usuário caso a autenticação tenha ocorrido com sucesso
      • Methods inherited from class org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter

        getPasswordParameter, getUsernameParameter, obtainPassword, obtainUsername, setDetails, setPasswordParameter, setPostOnly, setUsernameParameter
      • Methods inherited from class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter

        afterPropertiesSet, doFilter, getAllowSessionCreation, getAuthenticationManager, getFailureHandler, getRememberMeServices, getSuccessHandler, requiresAuthentication, setAllowSessionCreation, setApplicationEventPublisher, setAuthenticationDetailsSource, setAuthenticationFailureHandler, setAuthenticationManager, setAuthenticationSuccessHandler, setContinueChainBeforeSuccessfulAuthentication, setFilterProcessesUrl, setMessageSource, setRememberMeServices, setRequiresAuthenticationRequestMatcher, setSessionAuthenticationStrategy, unsuccessfulAuthentication
      • Methods inherited from class org.springframework.web.filter.GenericFilterBean

        addRequiredProperty, createEnvironment, destroy, getEnvironment, getFilterConfig, getFilterName, getServletContext, init, initBeanWrapper, initFilterBean, setBeanName, setEnvironment, setServletContext
    • Constructor Detail

      • JWTAuthenticationFilter

        public JWTAuthenticationFilter​(org.springframework.security.authentication.AuthenticationManager authenticationManager,
                                       JWTUtil jwtUtil)
    • Method Detail

      • attemptAuthentication

        public org.springframework.security.core.Authentication attemptAuthentication​(javax.servlet.http.HttpServletRequest httpServletRequest,
                                                                                      javax.servlet.http.HttpServletResponse httpServletResponse)
                                                                               throws org.springframework.security.core.AuthenticationException
        Tenta fazer a autenticação de usuário
        Overrides:
        attemptAuthentication in class org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter
        Parameters:
        httpServletRequest - Requisição feita pelo usuário
        httpServletResponse - Resposta a ser enviada pelo usuário
        Returns:
        Um Authentication
        Throws:
        org.springframework.security.core.AuthenticationException
      • successfulAuthentication

        protected void successfulAuthentication​(javax.servlet.http.HttpServletRequest httpServletRequest,
                                                javax.servlet.http.HttpServletResponse httpServletResponse,
                                                javax.servlet.FilterChain filterChain,
                                                org.springframework.security.core.Authentication authentication)
                                         throws IOException,
                                                javax.servlet.ServletException
        Retorna um token JWT para o usuário caso a autenticação tenha ocorrido com sucesso
        Overrides:
        successfulAuthentication in class org.springframework.security.web.authentication.AbstractAuthenticationProcessingFilter
        Parameters:
        httpServletRequest - Requisição feita pelo usuário
        httpServletResponse - Resposta a ser enviada para o usuário
        filterChain - Objeto usado para chamada de funções posteriores na cadeia de responsabilidade
        authentication - Autenticação feita anteriormente em attemptAuthentication
        Throws:
        IOException
        javax.servlet.ServletException