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

Add support to get redirect_uri using par request_uri in OBIdentifierAuthenticator #25

Closed
wants to merge 4 commits into from
Closed
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -515,6 +515,25 @@ private void appendRedirectUri(JSONObject sessionData) throws OpenBankingExcepti
}
}

/**
* Get redirect_uri using request_uri.
*
* @param requestUri - request_uri
* @return redirect_uri
* @throws OpenBankingException - OpenBankingException
*/
@Generated(message = "Excluding from code coverage since it requires a valid cache entry")
public String getRedirectUri(String requestUri) throws OpenBankingException {

JSONObject requestObjectVal = getParRequestObject(requestUri);
if (requestObjectVal.has(REDIRECT_URI)) {
return requestObjectVal.get(REDIRECT_URI).toString();
} else {
log.error("redirect_uri could not be found in the par request object.");
throw new OpenBankingException("redirect_uri could not be found in the par request object.");
}
}

/**
* Retrieve PAR request object from session data cache.
*
Expand All @@ -526,10 +545,36 @@ private void appendRedirectUri(JSONObject sessionData) throws OpenBankingExcepti
private JSONObject getParRequestObject(JSONObject sessionData) throws OpenBankingException {

//get request ref Ex -> "IVL...." from "urn::IVL..."
String[] requestUri = sessionData.get(REQUEST_URI).toString().split(":");
String requestUriRef = requestUri[requestUri.length - 1];
String requestUri = sessionData.get(REQUEST_URI).toString();
return getParRequestObject(requestUri);
}

/**
* Retrieve PAR request object from request_uri.
*
* @param requestUri - request_uri
* @return Request object json.
* @throws OpenBankingException - OpenBankingException
*/
@Generated(message = "Excluding from code coverage since it requires a valid cache entry")
private JSONObject getParRequestObject(String requestUri) throws OpenBankingException {

String[] requestUriArr = requestUri.split(":");
String requestUriRef = requestUriArr[requestUriArr.length - 1];
return getRequestObjectUsingUriReference(requestUriRef);
}

/**
* Retrieve PAR request object using request_uri reference.
*
* @param requestUriReference - request_uri reference (i.e:last part of request_uri split by :)
* @return Request object json.
* @throws OpenBankingException - OpenBankingException
*/
@Generated(message = "Excluding from code coverage since it requires a valid cache entry")
private JSONObject getRequestObjectUsingUriReference(String requestUriReference) throws OpenBankingException {

SessionDataCacheKey cacheKey = new SessionDataCacheKey(requestUriRef);
SessionDataCacheKey cacheKey = new SessionDataCacheKey(requestUriReference);
SessionDataCacheEntry cacheEntry = SessionDataCache.getInstance().getValueFromCache(cacheKey);

if (cacheEntry != null) {
Expand All @@ -543,8 +588,8 @@ private JSONObject getParRequestObject(JSONObject sessionData) throws OpenBankin
}
return new JSONObject(new String(requestObject, StandardCharsets.UTF_8));
} else {
log.error("Could not able to fetch par request object from session data cache.");
throw new OpenBankingException("Could not able to fetch par request object from session data cache.");
log.error("Unable to fetch par request object from session data cache.");
throw new OpenBankingException("Unable to fetch par request object from session data cache.");
}
}

Expand Down
Loading