// Path: src/main/java/com/kazale/pontointeligente/api/security/JwtAuthenticationEntryPoint.java
// @Component
// public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
// 
// 	@Override
// 	public void commence(HttpServletRequest request, HttpServletResponse response,
// 			AuthenticationException authException) throws IOException {
// 		response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
// 				"Acesso negado. Você deve estar autenticado no sistema para acessar a URL solicitada.");
// 	}
// 
// }
// 
// Path: src/main/java/com/kazale/pontointeligente/api/security/filters/JwtAuthenticationTokenFilter.java
// public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
// 
// 	private static final String AUTH_HEADER = "Authorization";
// 	private static final String BEARER_PREFIX = "Bearer ";
// 
// 	@Autowired
//     private UserDetailsService userDetailsService;
// 	
// 	@Autowired
//     private JwtTokenUtil jwtTokenUtil;
// 
// 	@Override
//     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
//         String token = request.getHeader(AUTH_HEADER);
//         if (token != null && token.startsWith(BEARER_PREFIX)) {
//         	token = token.substring(7);
//         }
//         String username = jwtTokenUtil.getUsernameFromToken(token);
// 
//         if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
// 
//             UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
//             
//             if (jwtTokenUtil.tokenValido(token)) {
//                 UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
//                 authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
//                 SecurityContextHolder.getContext().setAuthentication(authentication);
//             }
//         }
// 
//         chain.doFilter(request, response);
//     }
// 
// }


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import com.kazale.pontointeligente.api.security.JwtAuthenticationEntryPoint;
import com.kazale.pontointeligente.api.security.filters.JwtAuthenticationTokenFilter;
package com.kazale.pontointeligente.api.security.config;



@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

	@Autowired
	private JwtAuthenticationEntryPoint unauthorizedHandler;

	@Autowired
	private UserDetailsService userDetailsService;

	@Autowired
	public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
		authenticationManagerBuilder.userDetailsService(this.userDetailsService).passwordEncoder(passwordEncoder());
	}

	@Bean
	public PasswordEncoder passwordEncoder() {
		return new BCryptPasswordEncoder();
	}

// Path: src/main/java/com/kazale/pontointeligente/api/security/JwtAuthenticationEntryPoint.java
// @Component
// public class JwtAuthenticationEntryPoint implements AuthenticationEntryPoint {
// 
// 	@Override
// 	public void commence(HttpServletRequest request, HttpServletResponse response,
// 			AuthenticationException authException) throws IOException {
// 		response.sendError(HttpServletResponse.SC_UNAUTHORIZED,
// 				"Acesso negado. Você deve estar autenticado no sistema para acessar a URL solicitada.");
// 	}
// 
// }
// 
// Path: src/main/java/com/kazale/pontointeligente/api/security/filters/JwtAuthenticationTokenFilter.java
// public class JwtAuthenticationTokenFilter extends OncePerRequestFilter {
// 
// 	private static final String AUTH_HEADER = "Authorization";
// 	private static final String BEARER_PREFIX = "Bearer ";
// 
// 	@Autowired
//     private UserDetailsService userDetailsService;
// 	
// 	@Autowired
//     private JwtTokenUtil jwtTokenUtil;
// 
// 	@Override
//     protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain chain) throws ServletException, IOException {
//         String token = request.getHeader(AUTH_HEADER);
//         if (token != null && token.startsWith(BEARER_PREFIX)) {
//         	token = token.substring(7);
//         }
//         String username = jwtTokenUtil.getUsernameFromToken(token);
// 
//         if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
// 
//             UserDetails userDetails = this.userDetailsService.loadUserByUsername(username);
//             
//             if (jwtTokenUtil.tokenValido(token)) {
//                 UsernamePasswordAuthenticationToken authentication = new UsernamePasswordAuthenticationToken(userDetails, null, userDetails.getAuthorities());
//                 authentication.setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
//                 SecurityContextHolder.getContext().setAuthentication(authentication);
//             }
//         }
// 
//         chain.doFilter(request, response);
//     }
// 
// }


// Path: src/main/java/com/kazale/pontointeligente/api/security/config/WebSecurityConfig.java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
import org.springframework.security.config.http.SessionCreationPolicy;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.security.web.authentication.UsernamePasswordAuthenticationFilter;
import com.kazale.pontointeligente.api.security.JwtAuthenticationEntryPoint;
import com.kazale.pontointeligente.api.security.filters.JwtAuthenticationTokenFilter;

package com.kazale.pontointeligente.api.security.config;



@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

	@Autowired
	private JwtAuthenticationEntryPoint unauthorizedHandler;

	@Autowired
	private UserDetailsService userDetailsService;

	@Autowired
	public void configureAuthentication(AuthenticationManagerBuilder authenticationManagerBuilder) throws Exception {
		authenticationManagerBuilder.userDetailsService(this.userDetailsService).passwordEncoder(passwordEncoder());
	}

	@Bean
	public PasswordEncoder passwordEncoder() {
		return new BCryptPasswordEncoder();
	}

	@Bean