diff --git a/src/main/java/utilities/flex/models/transientToken/Ctx.java b/src/main/java/utilities/flex/models/transientToken/Ctx.java new file mode 100644 index 000000000..062b8fd11 --- /dev/null +++ b/src/main/java/utilities/flex/models/transientToken/Ctx.java @@ -0,0 +1,34 @@ + +package utilities.flex.models.transientToken; + +import javax.annotation.Generated; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +@Generated("jsonschema2pojo") +public class Ctx { + + @SerializedName("data") + @Expose + private Data data; + @SerializedName("type") + @Expose + private String type; + + public Data getData() { + return data; + } + + public void setData(Data data) { + this.data = data; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + +} diff --git a/src/main/java/utilities/flex/models/transientToken/Data.java b/src/main/java/utilities/flex/models/transientToken/Data.java new file mode 100644 index 000000000..9f189af98 --- /dev/null +++ b/src/main/java/utilities/flex/models/transientToken/Data.java @@ -0,0 +1,35 @@ + +package utilities.flex.models.transientToken; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +@Generated("jsonschema2pojo") +public class Data { + + @SerializedName("targetOrigins") + @Expose + private List targetOrigins = null; + @SerializedName("mfOrigin") + @Expose + private String mfOrigin; + + public List getTargetOrigins() { + return targetOrigins; + } + + public void setTargetOrigins(List targetOrigins) { + this.targetOrigins = targetOrigins; + } + + public String getMfOrigin() { + return mfOrigin; + } + + public void setMfOrigin(String mfOrigin) { + this.mfOrigin = mfOrigin; + } + +} diff --git a/src/main/java/utilities/flex/models/transientToken/Flx.java b/src/main/java/utilities/flex/models/transientToken/Flx.java new file mode 100644 index 000000000..c5fb2911c --- /dev/null +++ b/src/main/java/utilities/flex/models/transientToken/Flx.java @@ -0,0 +1,56 @@ + +package utilities.flex.models.transientToken; + +import javax.annotation.Generated; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +@Generated("jsonschema2pojo") +public class Flx { + + @SerializedName("path") + @Expose + private String path; + @SerializedName("data") + @Expose + private String data; + @SerializedName("origin") + @Expose + private String origin; + @SerializedName("jwk") + @Expose + private Jwk jwk; + + public String getPath() { + return path; + } + + public void setPath(String path) { + this.path = path; + } + + public String getData() { + return data; + } + + public void setData(String data) { + this.data = data; + } + + public String getOrigin() { + return origin; + } + + public void setOrigin(String origin) { + this.origin = origin; + } + + public Jwk getJwk() { + return jwk; + } + + public void setJwk(Jwk jwk) { + this.jwk = jwk; + } + +} diff --git a/src/main/java/utilities/flex/models/transientToken/Jwk.java b/src/main/java/utilities/flex/models/transientToken/Jwk.java new file mode 100644 index 000000000..8a457a7ce --- /dev/null +++ b/src/main/java/utilities/flex/models/transientToken/Jwk.java @@ -0,0 +1,67 @@ + +package utilities.flex.models.transientToken; + +import javax.annotation.Generated; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +@Generated("jsonschema2pojo") +public class Jwk { + + @SerializedName("kty") + @Expose + private String kty; + @SerializedName("e") + @Expose + private String e; + @SerializedName("use") + @Expose + private String use; + @SerializedName("n") + @Expose + private String n; + @SerializedName("kid") + @Expose + private String kid; + + public String getKty() { + return kty; + } + + public void setKty(String kty) { + this.kty = kty; + } + + public String getE() { + return e; + } + + public void setE(String e) { + this.e = e; + } + + public String getUse() { + return use; + } + + public void setUse(String use) { + this.use = use; + } + + public String getN() { + return n; + } + + public void setN(String n) { + this.n = n; + } + + public String getKid() { + return kid; + } + + public void setKid(String kid) { + this.kid = kid; + } + +} diff --git a/src/main/java/utilities/flex/models/transientToken/JwtResponseModel.java b/src/main/java/utilities/flex/models/transientToken/JwtResponseModel.java new file mode 100644 index 000000000..a0e603272 --- /dev/null +++ b/src/main/java/utilities/flex/models/transientToken/JwtResponseModel.java @@ -0,0 +1,79 @@ + +package utilities.flex.models.transientToken; + +import java.util.List; +import javax.annotation.Generated; +import com.google.gson.annotations.Expose; +import com.google.gson.annotations.SerializedName; + +@Generated("jsonschema2pojo") +public class JwtResponseModel { + + @SerializedName("flx") + @Expose + private Flx flx; + @SerializedName("ctx") + @Expose + private List ctx = null; + @SerializedName("iss") + @Expose + private String iss; + @SerializedName("exp") + @Expose + private Integer exp; + @SerializedName("iat") + @Expose + private Integer iat; + @SerializedName("jti") + @Expose + private String jti; + + public Flx getFlx() { + return flx; + } + + public void setFlx(Flx flx) { + this.flx = flx; + } + + public List getCtx() { + return ctx; + } + + public void setCtx(List ctx) { + this.ctx = ctx; + } + + public String getIss() { + return iss; + } + + public void setIss(String iss) { + this.iss = iss; + } + + public Integer getExp() { + return exp; + } + + public void setExp(Integer exp) { + this.exp = exp; + } + + public Integer getIat() { + return iat; + } + + public void setIat(Integer iat) { + this.iat = iat; + } + + public String getJti() { + return jti; + } + + public void setJti(String jti) { + this.jti = jti; + } + +} diff --git a/src/main/java/utilities/flex/transientToken/TransientTokenUtility.java b/src/main/java/utilities/flex/transientToken/TransientTokenUtility.java new file mode 100644 index 000000000..913fcce02 --- /dev/null +++ b/src/main/java/utilities/flex/transientToken/TransientTokenUtility.java @@ -0,0 +1,34 @@ +package utilities.flex.transientToken; + +import java.util.Base64; + +import com.google.gson.Gson; + +public class TransientTokenUtility { + + /** + * This is the method to extract transient token from given jwt token + * @param jwt + * @return + */ + public JwtResponseModel extractTransientToken(String jwt) + { + // split the jwt token into two parts + // bearer and token part + String splitContents[] = jwt.split("."); + if(splitContents.length > 1) + { + // decode the base 64 encoded string + String encodedString = splitContents[1]; + byte[] decodedBytes = Base64.getDecoder().decode(encodedString); + String decodedString = new String(decodedBytes); + Gson gson=new Gson(); + // Map decoded string to response model + JwtResponseModel jwtResponseModel = gson.fromJson(decodedString,JwtResponseModel.class); + // return JTI string + return jwtResponseModel; + } + + return null; + } +}