Skip to content
Snippets Groups Projects
Commit 5b5c7fb1 authored by Tucker Gary Siegel's avatar Tucker Gary Siegel
Browse files

add context

parent 20043509
Branches develop
Tags 0.17.0
No related merge requests found
package edu.umd.dawn.common.jwt;
import org.springframework.stereotype.Component;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import edu.umd.dawn.common.exceptions.BaseExceptions;
import edu.umd.dawn.common.exceptions.DawnException;
import edu.umd.dawn.common.wrappers.DawnHttpServletRequestWrapper;
import jakarta.annotation.PostConstruct;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Value;
/**
* Using this context REQUIRES that a jwt is passed
*/
@Component
public class JWTContext {
@Value("${config.jwt.warn:true}")
private boolean warn;
@Value("${config.accessSecret:empty}")
private String accessSecret;
/**
* try everything possible to get the claims - fail if we can't
* @return
*/
public Claims getClaims() {
HttpServletRequest request =
((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes()).getRequest();
DawnHttpServletRequestWrapper wrappedRequest = new DawnHttpServletRequestWrapper(request, accessSecret);
Claims claims = wrappedRequest.getClaims();
if (claims == null) {
throw new DawnException(BaseExceptions.INVALID_JWT);
}
return claims;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment