Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding code changes to TransientTokenUtility #81

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 34 additions & 0 deletions src/main/java/utilities/flex/models/transientToken/Ctx.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
35 changes: 35 additions & 0 deletions src/main/java/utilities/flex/models/transientToken/Data.java
Original file line number Diff line number Diff line change
@@ -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<String> targetOrigins = null;
@SerializedName("mfOrigin")
@Expose
private String mfOrigin;

public List<String> getTargetOrigins() {
return targetOrigins;
}

public void setTargetOrigins(List<String> targetOrigins) {
this.targetOrigins = targetOrigins;
}

public String getMfOrigin() {
return mfOrigin;
}

public void setMfOrigin(String mfOrigin) {
this.mfOrigin = mfOrigin;
}

}
56 changes: 56 additions & 0 deletions src/main/java/utilities/flex/models/transientToken/Flx.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
67 changes: 67 additions & 0 deletions src/main/java/utilities/flex/models/transientToken/Jwk.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -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> 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<Ctx> getCtx() {
return ctx;
}

public void setCtx(List<Ctx> 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;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package utilities.flex.models.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;
}
}