|
|
@@ -1,79 +0,0 @@
|
|
|
-//package pl.sudra.securityController;
|
|
|
-//
|
|
|
-//import io.jsonwebtoken.ExpiredJwtException;
|
|
|
-//import jakarta.servlet.FilterChain;
|
|
|
-//import jakarta.servlet.ServletException;
|
|
|
-//import jakarta.servlet.http.HttpServletRequest;
|
|
|
-//import jakarta.servlet.http.HttpServletResponse;
|
|
|
-//import org.springframework.beans.factory.annotation.Autowired;
|
|
|
-//import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
|
-//import org.springframework.security.core.context.SecurityContextHolder;
|
|
|
-//import org.springframework.security.core.userdetails.UserDetails;
|
|
|
-//import org.springframework.security.web.authentication.WebAuthenticationDetailsSource;
|
|
|
-//import org.springframework.web.bind.annotation.CrossOrigin;
|
|
|
-//import org.springframework.web.bind.annotation.RestController;
|
|
|
-//import org.springframework.web.filter.OncePerRequestFilter;
|
|
|
-//import pl.sudra.domain.User;
|
|
|
-//import pl.sudra.service.UserService;
|
|
|
-//
|
|
|
-//import java.io.IOException;
|
|
|
-//import java.util.ArrayList;
|
|
|
-//import java.util.List;
|
|
|
-//
|
|
|
-//@RestController
|
|
|
-//@CrossOrigin(origins = "http://localhost:1410")
|
|
|
-//public class JwtRequestFilter extends OncePerRequestFilter {
|
|
|
-// @Autowired
|
|
|
-// private UserService userService;
|
|
|
-//
|
|
|
-// @Autowired
|
|
|
-// private JwtTokenUtil jwtTokenUtil;
|
|
|
-//
|
|
|
-// @Override
|
|
|
-// protected void doFilterInternal(HttpServletRequest request,
|
|
|
-// HttpServletResponse response,
|
|
|
-// FilterChain chain) throws ServletException, IOException {
|
|
|
-// final String requestTokenHeader = request.getHeader("Authorization");
|
|
|
-// System.out.println("Im doing something");
|
|
|
-// String username = null;
|
|
|
-// String jwtToken = null;// JWT Token is in the form "Bearer token". Remove Bearer word and get only the Token
|
|
|
-//
|
|
|
-// if (requestTokenHeader != null && requestTokenHeader.startsWith("Bearer ")) {
|
|
|
-// jwtToken = requestTokenHeader.substring(7);
|
|
|
-// try {
|
|
|
-// username = jwtTokenUtil.getUsernameFromToken(jwtToken);
|
|
|
-// } catch (IllegalArgumentException e) {
|
|
|
-// System.out.println("Unable to get JWT Token");
|
|
|
-// } catch (ExpiredJwtException e) {
|
|
|
-// System.out.println("JWT Token has expired");
|
|
|
-// }
|
|
|
-// } else {
|
|
|
-// logger.warn("JWT Token does not begin with Bearer String");
|
|
|
-// }
|
|
|
-//
|
|
|
-// //Once we get the token validate it.
|
|
|
-// if (username != null && SecurityContextHolder.getContext().getAuthentication() == null) {
|
|
|
-//
|
|
|
-// User user = this.userService.findByUsername(username).get();
|
|
|
-//
|
|
|
-// // if token is valid configure Spring Security to manually set authentication
|
|
|
-// if (jwtTokenUtil.validateToken(jwtToken, user)) {
|
|
|
-//
|
|
|
-//// UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken =
|
|
|
-//// new UsernamePasswordAuthenticationToken(user,
|
|
|
-//// null, user.getRole());
|
|
|
-//
|
|
|
-// UsernamePasswordAuthenticationToken usernamePasswordAuthenticationToken =
|
|
|
-// new UsernamePasswordAuthenticationToken(user,
|
|
|
-// null, List.of());
|
|
|
-// usernamePasswordAuthenticationToken
|
|
|
-// .setDetails(new WebAuthenticationDetailsSource().buildDetails(request));
|
|
|
-// // After setting the Authentication in the context, we specify
|
|
|
-// // that the current user is authenticated. So it passes the Spring Security Configurations successfully.
|
|
|
-// SecurityContextHolder.getContext().setAuthentication(usernamePasswordAuthenticationToken);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// chain.doFilter(request, response);
|
|
|
-// }
|
|
|
-//
|
|
|
-//}
|