// Path: src/main/java/com/github/segator/proxylive/helper/JwtHelper.java
// @Component
// public class JwtHelper {
//     private JwtConfiguration jwtConfiguration;
// 
//     public JwtHelper(JwtConfiguration jwtConfiguration) {
//         this.jwtConfiguration = jwtConfiguration;
//     }
//     public String createJwtForClaims(String subject, List<GrantedAuthority> grantedAuthorities) {
//         Calendar calendar = Calendar.getInstance();
//         calendar.setTimeInMillis(Instant.now().toEpochMilli());
//         calendar.add(Calendar.HOUR, jwtConfiguration.getExpireInHours());
//         return createJwtForClaims(subject,grantedAuthorities,calendar.getTime());
//     }
//     public String createJwtForClaims(String subject, List<GrantedAuthority> grantedAuthorities,Date expirationDate) {
//         JwtBuilder builder =  Jwts.builder().setId("proxylive")
//             .setSubject(subject)
//             .claim("authorities",grantedAuthorities.stream()
//                     .map(GrantedAuthority::getAuthority)
//                     .collect(Collectors.toList()))
//             .setIssuedAt(new Date(System.currentTimeMillis()));
// 
//         if(expirationDate!=null) {
//             builder.setExpiration(expirationDate);
//         }
//         return builder.signWith(SignatureAlgorithm.HS512,
//                 jwtConfiguration.getSecret().getBytes()).compact();
//     }
// }
// 
// Path: src/main/java/com/github/segator/proxylive/service/AuthenticationService.java
// public interface AuthenticationService {
//    public boolean loginUser(String user, String password) throws Exception;
//    public List<GrantedAuthority> getUserRoles(String user);
// }


import com.github.segator.proxylive.helper.JwtHelper;
import com.github.segator.proxylive.service.AuthenticationService;
import io.jsonwebtoken.*;
import org.apache.http.client.utils.URIBuilder;
import org.eclipse.jgit.util.Base64;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
package com.github.segator.proxylive.config;



@Component
public class JWTBasicFilter  extends OncePerRequestFilter {

    private final String HEADER = "Authorization";
    private final String PREFIXBearer = "Bearer ";
    private final String PREFIXBasic = "Basic ";
    private final String PARAM_OLD_USERNAME="user";
    private final String PARAM_OLD_PASSWORD="pass";
    private final JwtConfiguration jwtConfiguration;
    private final AuthenticationService authenticationService;
// Path: src/main/java/com/github/segator/proxylive/helper/JwtHelper.java
// @Component
// public class JwtHelper {
//     private JwtConfiguration jwtConfiguration;
// 
//     public JwtHelper(JwtConfiguration jwtConfiguration) {
//         this.jwtConfiguration = jwtConfiguration;
//     }
//     public String createJwtForClaims(String subject, List<GrantedAuthority> grantedAuthorities) {
//         Calendar calendar = Calendar.getInstance();
//         calendar.setTimeInMillis(Instant.now().toEpochMilli());
//         calendar.add(Calendar.HOUR, jwtConfiguration.getExpireInHours());
//         return createJwtForClaims(subject,grantedAuthorities,calendar.getTime());
//     }
//     public String createJwtForClaims(String subject, List<GrantedAuthority> grantedAuthorities,Date expirationDate) {
//         JwtBuilder builder =  Jwts.builder().setId("proxylive")
//             .setSubject(subject)
//             .claim("authorities",grantedAuthorities.stream()
//                     .map(GrantedAuthority::getAuthority)
//                     .collect(Collectors.toList()))
//             .setIssuedAt(new Date(System.currentTimeMillis()));
// 
//         if(expirationDate!=null) {
//             builder.setExpiration(expirationDate);
//         }
//         return builder.signWith(SignatureAlgorithm.HS512,
//                 jwtConfiguration.getSecret().getBytes()).compact();
//     }
// }
// 
// Path: src/main/java/com/github/segator/proxylive/service/AuthenticationService.java
// public interface AuthenticationService {
//    public boolean loginUser(String user, String password) throws Exception;
//    public List<GrantedAuthority> getUserRoles(String user);
// }


// Path: src/main/java/com/github/segator/proxylive/config/JWTBasicFilter.java
import com.github.segator.proxylive.helper.JwtHelper;
import com.github.segator.proxylive.service.AuthenticationService;
import io.jsonwebtoken.*;
import org.apache.http.client.utils.URIBuilder;
import org.eclipse.jgit.util.Base64;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Component;
import org.springframework.web.filter.OncePerRequestFilter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

package com.github.segator.proxylive.config;



@Component
public class JWTBasicFilter  extends OncePerRequestFilter {

    private final String HEADER = "Authorization";
    private final String PREFIXBearer = "Bearer ";
    private final String PREFIXBasic = "Basic ";
    private final String PARAM_OLD_USERNAME="user";
    private final String PARAM_OLD_PASSWORD="pass";
    private final JwtConfiguration jwtConfiguration;
    private final AuthenticationService authenticationService;
    private final JwtHelper jwtHelper;