// Path: authrite-service/src/main/java/com/lewisd/authrite/auth/JWTConfiguration.java
// public class JWTConfiguration {
//     private String jwtSecret = "secret";
//     private int jwtExpirySeconds = 3600;
//     private String cookieName = "jwtToken";
// 
//     @JsonProperty
//     public String getJwtSecret() {
//         return jwtSecret;
//     }
// 
//     public void setJwtSecret(final String jwtSecret) {
//         this.jwtSecret = jwtSecret;
//     }
// 
//     @JsonProperty
//     public int getJwtExpirySeconds() {
//         return jwtExpirySeconds;
//     }
// 
//     public void setJwtExpirySeconds(final int jwtExpirySeconds) {
//         this.jwtExpirySeconds = jwtExpirySeconds;
//     }
// 
//     @JsonProperty
//     public String getCookieName() {
//         return cookieName;
//     }
// 
//     public void setCookieName(final String cookieName) {
//         this.cookieName = cookieName;
//     }
// 
//     public JWTAuthFilter<User> buildAuthFilter() {
//         return new JWTAuthFilter.Builder<User>()
//                 .setCookieName(this.getCookieName())
//                 .setAuthenticator(new JWTAuthenticator(buildTokenManager()))
// //                .setAuthorizer(new ExampleAuthorizer())
//                 .buildAuthFilter();
//     }
// 
//     public JwtTokenManager buildTokenManager() {
//         return new JwtTokenManager(jwtSecret, jwtExpirySeconds);
//     }
// 
// }
// 
// Path: authrite-service/src/main/java/com/lewisd/authrite/auth/JwtTokenManager.java
// public class JwtTokenManager {
// 
//     private final JWTSigner jwtSigner;
//     private final JWTSigner.Options jwtOptions;
//     private final JWTVerifier jwtVerifier;
//     private final ObjectMapper jsonMapper;
// 
//     public JwtTokenManager(final String jwtSecret, final int jwtExpirySeconds) {
//         jwtSigner = new JWTSigner(jwtSecret);
//         jwtVerifier = new JWTVerifier(jwtSecret);
//         jwtOptions = new JWTSigner.Options().setExpirySeconds(jwtExpirySeconds);
// 
//         jsonMapper = new ObjectMapper();
//         jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//     }
// 
//     public JWTSigner getJwtSigner() {
//         return jwtSigner;
//     }
// 
//     public JWTSigner.Options getJwtOptions() {
//         return jwtOptions;
//     }
// 
//     public JWTVerifier getJwtVerifier() {
//         return jwtVerifier;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public Map<String, Object> toJWTClaim(final User user) {
//         try {
//             return jsonMapper.convertValue(user, Map.class);
//         } catch (final IllegalArgumentException e) {
//             throw new RuntimeException("Can't JSONify User, something's badly wrong", e);
//         }
//     }
// 
//     public User fromJWTClaim(final Map<String, Object> claim)
//             throws IllegalArgumentException {
//         final User user = jsonMapper.convertValue(claim, User.class);
//         if (user.getId() == null) {
//             throw new IllegalStateException("User from claim is missing id: " + claim);
//         }
//         if (user.getRoles() == null) {
//             throw new IllegalStateException("User from claim is missing roles: " + claim);
//         }
//         if (user.getEmail() == null) {
//             throw new IllegalStateException("User from claim is missing email: " + claim);
//         }
//         if (user.getDisplayName() == null) {
//             throw new IllegalStateException("User from claim is missing displayName: " + claim);
//         }
//         return user;
//     }
// 
// }


import com.auth0.jwt.JWTVerifyException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Cookie;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
import com.lewisd.authrite.auth.JWTConfiguration;
import com.lewisd.authrite.auth.JwtTokenManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static io.github.unacceptable.alias.AbsentWrappingGenerator.ABSENT;
import static org.junit.Assert.assertNotNull;

        return response;
    }

    private RequestSpecification buildResponse() {
        RequestSpecification requestSpecification = RestAssured.given()
                .contentType(ContentType.JSON);
        if (jwtToken != null) {
            requestSpecification = requestSpecification.cookie("jwtToken", jwtToken);
        }
        return requestSpecification;
    }

    private String createJsonRequestBody(final Map<String, Object> requestBody) {
        final String requestBodyJson;
        try {
            requestBodyJson = new ObjectMapper().writeValueAsString(requestBody);
        } catch (final JsonProcessingException e) {
            throw new RuntimeException("Unable to generate JSON request body", e);
        }
        return requestBodyJson;
    }

    public Cookie getJtwCookie() {
        return jtwCookie;
    }

    public void regenerateToken(final String secret, final String userId, final String email, final String displayName, final String expiry) {

        final JWTConfiguration verifyingConfiguration = new JWTConfiguration();
// Path: authrite-service/src/main/java/com/lewisd/authrite/auth/JWTConfiguration.java
// public class JWTConfiguration {
//     private String jwtSecret = "secret";
//     private int jwtExpirySeconds = 3600;
//     private String cookieName = "jwtToken";
// 
//     @JsonProperty
//     public String getJwtSecret() {
//         return jwtSecret;
//     }
// 
//     public void setJwtSecret(final String jwtSecret) {
//         this.jwtSecret = jwtSecret;
//     }
// 
//     @JsonProperty
//     public int getJwtExpirySeconds() {
//         return jwtExpirySeconds;
//     }
// 
//     public void setJwtExpirySeconds(final int jwtExpirySeconds) {
//         this.jwtExpirySeconds = jwtExpirySeconds;
//     }
// 
//     @JsonProperty
//     public String getCookieName() {
//         return cookieName;
//     }
// 
//     public void setCookieName(final String cookieName) {
//         this.cookieName = cookieName;
//     }
// 
//     public JWTAuthFilter<User> buildAuthFilter() {
//         return new JWTAuthFilter.Builder<User>()
//                 .setCookieName(this.getCookieName())
//                 .setAuthenticator(new JWTAuthenticator(buildTokenManager()))
// //                .setAuthorizer(new ExampleAuthorizer())
//                 .buildAuthFilter();
//     }
// 
//     public JwtTokenManager buildTokenManager() {
//         return new JwtTokenManager(jwtSecret, jwtExpirySeconds);
//     }
// 
// }
// 
// Path: authrite-service/src/main/java/com/lewisd/authrite/auth/JwtTokenManager.java
// public class JwtTokenManager {
// 
//     private final JWTSigner jwtSigner;
//     private final JWTSigner.Options jwtOptions;
//     private final JWTVerifier jwtVerifier;
//     private final ObjectMapper jsonMapper;
// 
//     public JwtTokenManager(final String jwtSecret, final int jwtExpirySeconds) {
//         jwtSigner = new JWTSigner(jwtSecret);
//         jwtVerifier = new JWTVerifier(jwtSecret);
//         jwtOptions = new JWTSigner.Options().setExpirySeconds(jwtExpirySeconds);
// 
//         jsonMapper = new ObjectMapper();
//         jsonMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
//     }
// 
//     public JWTSigner getJwtSigner() {
//         return jwtSigner;
//     }
// 
//     public JWTSigner.Options getJwtOptions() {
//         return jwtOptions;
//     }
// 
//     public JWTVerifier getJwtVerifier() {
//         return jwtVerifier;
//     }
// 
//     @SuppressWarnings("unchecked")
//     public Map<String, Object> toJWTClaim(final User user) {
//         try {
//             return jsonMapper.convertValue(user, Map.class);
//         } catch (final IllegalArgumentException e) {
//             throw new RuntimeException("Can't JSONify User, something's badly wrong", e);
//         }
//     }
// 
//     public User fromJWTClaim(final Map<String, Object> claim)
//             throws IllegalArgumentException {
//         final User user = jsonMapper.convertValue(claim, User.class);
//         if (user.getId() == null) {
//             throw new IllegalStateException("User from claim is missing id: " + claim);
//         }
//         if (user.getRoles() == null) {
//             throw new IllegalStateException("User from claim is missing roles: " + claim);
//         }
//         if (user.getEmail() == null) {
//             throw new IllegalStateException("User from claim is missing email: " + claim);
//         }
//         if (user.getDisplayName() == null) {
//             throw new IllegalStateException("User from claim is missing displayName: " + claim);
//         }
//         return user;
//     }
// 
// }


// Path: authrite-acctests/src/main/java/com/lewisd/authrite/acctests/framework/driver/PublicApiDriver.java
import com.auth0.jwt.JWTVerifyException;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.jayway.restassured.RestAssured;
import com.jayway.restassured.http.ContentType;
import com.jayway.restassured.response.Cookie;
import com.jayway.restassured.response.Response;
import com.jayway.restassured.specification.RequestSpecification;
import com.lewisd.authrite.auth.JWTConfiguration;
import com.lewisd.authrite.auth.JwtTokenManager;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.SignatureException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import static io.github.unacceptable.alias.AbsentWrappingGenerator.ABSENT;
import static org.junit.Assert.assertNotNull;


        return response;
    }

    private RequestSpecification buildResponse() {
        RequestSpecification requestSpecification = RestAssured.given()
                .contentType(ContentType.JSON);
        if (jwtToken != null) {
            requestSpecification = requestSpecification.cookie("jwtToken", jwtToken);
        }
        return requestSpecification;
    }

    private String createJsonRequestBody(final Map<String, Object> requestBody) {
        final String requestBodyJson;
        try {
            requestBodyJson = new ObjectMapper().writeValueAsString(requestBody);
        } catch (final JsonProcessingException e) {
            throw new RuntimeException("Unable to generate JSON request body", e);
        }
        return requestBodyJson;
    }

    public Cookie getJtwCookie() {
        return jtwCookie;
    }

    public void regenerateToken(final String secret, final String userId, final String email, final String displayName, final String expiry) {

        final JWTConfiguration verifyingConfiguration = new JWTConfiguration();
        final JwtTokenManager tokenManager = verifyingConfiguration.buildTokenManager();