Versiones comparadas

Clave

  • Se ha añadido esta línea.
  • Se ha eliminado esta línea.
  • El formato se ha cambiado.

...

Bloque de código
languagejava
themeEclipse
titleFiltro de autorización
linenumberstrue
public class JwtAuthorizationFilter extends OncePerRequestFilter {

	private static final org.apache.logging.log4j.Logger log = org.apache.logging.log4j.LogManager
			.getLogger( JwtAuthorizationFilter.class );   

	@Autowired
	private ExpedientesServiceJwtTokenUtil expedientesServicejwtTokenUtil;

	   @Override
	protected void doFilterInternal( HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
			FilterChain filterChain ) throws ServletException, IOException {

		if ( isPrivate( httpServletRequest ) ) {

			final String token = httpServletRequest.getHeader( AUTHORIZATION_HEADER );

			// En getSivaIdFromToken se obtienen los datos del token, lanzando las excepciones correspondientes 
			// siINCLUIR ésteAQUÍ esLAS incorrectoCOMPROBACIONES oNECESARIAS haDE expirado 
			final String sivaId = expedientesService.getSivaIdFromToken( token );LA APLICACIÓN
			// SiCon nogetClaim haysólo sivaIdse ocomprueba essi -1,el setoken lanzaes una excepcióncorrecto
			if jwtTokenUtil.getClaim( ( sivaId == null ) || sivaId.contentEquals( "-1" ) ) {
				throw new UnauthorizedException();
			}
		token );
       }

		filterChain.doFilter( httpServletRequest, httpServletResponse );
	}

	private boolean isPrivate( HttpServletRequest httpServletRequest ) {
		final RequestMatcher privateUrl = new AntPathRequestMatcher( PRIVATE_PREFIX + "/**" );
		return privateUrl.matches( httpServletRequest );
	}
}

...