|
|
@ -23,7 +23,6 @@ import com.google.gson.JsonObject;
|
|
|
|
import com.google.gson.JsonParser;
|
|
|
|
import com.google.gson.JsonParser;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
|
|
|
import org.apache.http.HttpResponse;
|
|
|
|
|
|
|
|
import org.apache.http.HttpStatus;
|
|
|
|
import org.apache.http.HttpStatus;
|
|
|
|
import org.apache.http.client.methods.HttpDelete;
|
|
|
|
import org.apache.http.client.methods.HttpDelete;
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
|
import org.apache.http.client.methods.HttpGet;
|
|
|
@ -32,9 +31,10 @@ import org.apache.http.client.methods.HttpPut;
|
|
|
|
import org.apache.http.client.methods.HttpRequestBase;
|
|
|
|
import org.apache.http.client.methods.HttpRequestBase;
|
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
|
import org.apache.http.entity.ContentType;
|
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
|
import org.apache.http.entity.StringEntity;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.common.ProxyResponse;
|
|
|
|
import org.wso2.carbon.device.application.mgt.handler.beans.AuthData;
|
|
|
|
import org.wso2.carbon.device.application.mgt.handler.beans.AuthData;
|
|
|
|
import org.wso2.carbon.device.application.mgt.handler.util.HandlerConstants;
|
|
|
|
import org.wso2.carbon.device.application.mgt.handler.util.HandlerConstants;
|
|
|
|
|
|
|
|
import org.wso2.carbon.device.application.mgt.handler.util.HandlerUtil;
|
|
|
|
|
|
|
|
|
|
|
|
import javax.servlet.annotation.MultipartConfig;
|
|
|
|
import javax.servlet.annotation.MultipartConfig;
|
|
|
|
import javax.servlet.annotation.WebServlet;
|
|
|
|
import javax.servlet.annotation.WebServlet;
|
|
|
@ -43,16 +43,12 @@ import javax.servlet.http.HttpServletRequest;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import javax.servlet.http.HttpSession;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.IOException;
|
|
|
|
import java.io.PrintWriter;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
|
|
|
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
|
|
|
import static java.net.HttpURLConnection.HTTP_INTERNAL_ERROR;
|
|
|
|
|
|
|
|
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
|
|
|
|
import static java.net.HttpURLConnection.HTTP_UNAUTHORIZED;
|
|
|
|
import static org.wso2.carbon.device.application.mgt.handler.util.HandlerUtil.execute;
|
|
|
|
import static org.wso2.carbon.device.application.mgt.handler.util.HandlerUtil.execute;
|
|
|
|
import static org.wso2.carbon.device.application.mgt.handler.util.HandlerUtil.retrieveResponseString;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@MultipartConfig
|
|
|
|
@MultipartConfig @WebServlet("/invoke")
|
|
|
|
@WebServlet("/invoke")
|
|
|
|
|
|
|
|
public class InvokerHandler extends HttpServlet {
|
|
|
|
public class InvokerHandler extends HttpServlet {
|
|
|
|
private static final Log log = LogFactory.getLog(LoginHandler.class);
|
|
|
|
private static final Log log = LogFactory.getLog(LoginHandler.class);
|
|
|
|
private static final long serialVersionUID = -6508020875358160165L;
|
|
|
|
private static final long serialVersionUID = -6508020875358160165L;
|
|
|
@ -60,174 +56,171 @@ public class InvokerHandler extends HttpServlet {
|
|
|
|
private static String apiEndpoint;
|
|
|
|
private static String apiEndpoint;
|
|
|
|
private static String method;
|
|
|
|
private static String method;
|
|
|
|
private static String serverUrl;
|
|
|
|
private static String serverUrl;
|
|
|
|
|
|
|
|
private static String platform;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
|
|
|
if (!validateRequest(req, resp)) {
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
HttpRequestBase executor = constructExecutor(req);
|
|
|
|
|
|
|
|
if (executor == null) {
|
|
|
|
|
|
|
|
resp.sendError(HTTP_BAD_REQUEST, "Bad Request, method: " + method + " is not supported");
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
executor.setHeader(HandlerConstants.AUTHORIZATION_HEADER_KEY, "Bearer " + authData.getAccessToken());
|
|
|
|
|
|
|
|
|
|
|
|
// @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
|
|
|
|
ProxyResponse proxyResponse = execute(executor);
|
|
|
|
// try {
|
|
|
|
if (HandlerConstants.TOKEN_IS_EXPIRED.equals(proxyResponse.getExecutorResponse())) {
|
|
|
|
// if (!validateRequest(req, resp)) {
|
|
|
|
if (!refreshToken(req, resp)) {
|
|
|
|
// return;
|
|
|
|
return;
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
//
|
|
|
|
executor.setHeader(HandlerConstants.AUTHORIZATION_HEADER_KEY, "Bearer " + authData.getAccessToken());
|
|
|
|
// HttpRequestBase executor = constructExecutor(req);
|
|
|
|
proxyResponse = execute(executor);
|
|
|
|
// if (executor == null) {
|
|
|
|
if (proxyResponse.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
|
|
|
|
// resp.sendError(HTTP_BAD_REQUEST, "Bad Request, method: " + method + " is not supported");
|
|
|
|
log.error("Error occurred while invoking the API after refreshing the token.");
|
|
|
|
// return;
|
|
|
|
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
|
|
|
// }
|
|
|
|
return;
|
|
|
|
// String accessToken = authData.getAccessToken();
|
|
|
|
}
|
|
|
|
// executor.setHeader("Authorization", "Bearer " + accessToken);
|
|
|
|
}
|
|
|
|
//
|
|
|
|
|
|
|
|
// String result = execute(executor, HttpStatus.SC_OK);
|
|
|
|
if (proxyResponse.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
|
|
|
|
//
|
|
|
|
log.error("Error occurred while invoking the API endpoint.");
|
|
|
|
//// unauthorized
|
|
|
|
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
|
|
|
//// if (response == null) {
|
|
|
|
return;
|
|
|
|
//// resp.sendError(HTTP_INTERNAL_ERROR, "Empty response retried for the API call.");
|
|
|
|
}
|
|
|
|
//// return;
|
|
|
|
|
|
|
|
//// }
|
|
|
|
HandlerUtil.handleSuccess(req, resp, serverUrl, platform, proxyResponse);
|
|
|
|
//
|
|
|
|
|
|
|
|
//// int responseCode = response.getStatusLine().getStatusCode();
|
|
|
|
} catch (IOException e) {
|
|
|
|
//// String result = retrieveResponseString(response);
|
|
|
|
log.error("Error occured when processing invoke call.", e);
|
|
|
|
//
|
|
|
|
}
|
|
|
|
// if (responseCode == HttpStatus.SC_UNAUTHORIZED && (result.contains("Access token expired") || result
|
|
|
|
}
|
|
|
|
// .contains("Invalid input. Access token validation failed"))) {
|
|
|
|
|
|
|
|
// if (!refreshToken(req, resp)) {
|
|
|
|
/***
|
|
|
|
// return;
|
|
|
|
*
|
|
|
|
// }
|
|
|
|
* @param req {@link HttpServletRequest}
|
|
|
|
// response = execute(executor);
|
|
|
|
* @return {@link HttpRequestBase} if method equals to either GET, POST, PUT or DELETE otherwise returns NULL.
|
|
|
|
// if (response == null) {
|
|
|
|
*/
|
|
|
|
// resp.sendError(HTTP_INTERNAL_ERROR, "Empty response retried for the token renewal API call.");
|
|
|
|
private HttpRequestBase constructExecutor(HttpServletRequest req) {
|
|
|
|
// return;
|
|
|
|
String payload = req.getParameter("payload");
|
|
|
|
// }
|
|
|
|
String contentType = req.getParameter("content-type");
|
|
|
|
// responseCode = response.getStatusLine().getStatusCode();
|
|
|
|
if (contentType == null || contentType.isEmpty()) {
|
|
|
|
// result = retrieveResponseString(response);
|
|
|
|
contentType = ContentType.APPLICATION_JSON.toString();
|
|
|
|
// }
|
|
|
|
}
|
|
|
|
// if (responseCode != HttpStatus.SC_OK && responseCode != HttpStatus.SC_CREATED) {
|
|
|
|
|
|
|
|
// resp.sendError(responseCode, "Error response retrieved for the API call.");
|
|
|
|
HttpRequestBase executor;
|
|
|
|
// return;
|
|
|
|
if (HttpGet.METHOD_NAME.equalsIgnoreCase(method)) {
|
|
|
|
// }
|
|
|
|
executor = new HttpGet(serverUrl + HandlerConstants.API_COMMON_CONTEXT + apiEndpoint);
|
|
|
|
// try (PrintWriter writer = resp.getWriter()) {
|
|
|
|
} else if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) {
|
|
|
|
// writer.write(result);
|
|
|
|
executor = new HttpPost(serverUrl + HandlerConstants.API_COMMON_CONTEXT + apiEndpoint);
|
|
|
|
// }
|
|
|
|
StringEntity payloadEntity = new StringEntity(payload, ContentType.create(contentType));
|
|
|
|
// } catch (IOException e) {
|
|
|
|
((HttpPost) executor).setEntity(payloadEntity);
|
|
|
|
// log.error("Error occured when processing invoke call.", e);
|
|
|
|
} else if (HttpPut.METHOD_NAME.equalsIgnoreCase(method)) {
|
|
|
|
// }
|
|
|
|
executor = new HttpPut(serverUrl + HandlerConstants.API_COMMON_CONTEXT + apiEndpoint);
|
|
|
|
// }
|
|
|
|
StringEntity payloadEntity = new StringEntity(payload, ContentType.create(contentType));
|
|
|
|
//
|
|
|
|
((HttpPut) executor).setEntity(payloadEntity);
|
|
|
|
// /***
|
|
|
|
} else if (HttpDelete.METHOD_NAME.equalsIgnoreCase(method)) {
|
|
|
|
// *
|
|
|
|
executor = new HttpDelete(serverUrl + HandlerConstants.API_COMMON_CONTEXT + apiEndpoint);
|
|
|
|
// * @param req {@link HttpServletRequest}
|
|
|
|
} else {
|
|
|
|
// * @return {@link HttpRequestBase} if method equals to either GET, POST, PUT or DELETE otherwise returns NULL.
|
|
|
|
return null;
|
|
|
|
// */
|
|
|
|
}
|
|
|
|
// private HttpRequestBase constructExecutor(HttpServletRequest req) {
|
|
|
|
return executor;
|
|
|
|
// String payload = req.getParameter("payload");
|
|
|
|
}
|
|
|
|
// String contentType = req.getParameter("content-type");
|
|
|
|
|
|
|
|
// if (contentType == null || contentType.isEmpty()) {
|
|
|
|
/***
|
|
|
|
// contentType = ContentType.APPLICATION_JSON.toString();
|
|
|
|
*
|
|
|
|
// }
|
|
|
|
* @param req {@link HttpServletRequest}
|
|
|
|
//
|
|
|
|
* @param resp {@link HttpServletResponse}
|
|
|
|
// HttpRequestBase executor;
|
|
|
|
* @return If request is a valid one, returns TRUE, otherwise return FALSE
|
|
|
|
// if (HttpGet.METHOD_NAME.equalsIgnoreCase(method)) {
|
|
|
|
* @throws IOException If and error occurs while witting error response to client side
|
|
|
|
// executor = new HttpGet(serverUrl + HandlerConstants.API_COMMON_CONTEXT + apiEndpoint);
|
|
|
|
*/
|
|
|
|
// } else if (HttpPost.METHOD_NAME.equalsIgnoreCase(method)) {
|
|
|
|
private static boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
|
|
|
// executor = new HttpPost(serverUrl + HandlerConstants.API_COMMON_CONTEXT + apiEndpoint);
|
|
|
|
HttpSession session = req.getSession(false);
|
|
|
|
// StringEntity payloadEntity = new StringEntity(payload, ContentType.create(contentType));
|
|
|
|
if (session == null) {
|
|
|
|
// ((HttpPost) executor).setEntity(payloadEntity);
|
|
|
|
resp.sendError(HTTP_UNAUTHORIZED, "Unauthorized, You are not logged in. Please log in to the portal");
|
|
|
|
// } else if (HttpPut.METHOD_NAME.equalsIgnoreCase(method)) {
|
|
|
|
return false;
|
|
|
|
// executor = new HttpPut(serverUrl + HandlerConstants.API_COMMON_CONTEXT + apiEndpoint);
|
|
|
|
}
|
|
|
|
// StringEntity payloadEntity = new StringEntity(payload, ContentType.create(contentType));
|
|
|
|
authData = (AuthData) session.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY);
|
|
|
|
// ((HttpPut) executor).setEntity(payloadEntity);
|
|
|
|
platform = (String) session.getAttribute(HandlerConstants.PLATFORM);
|
|
|
|
// } else if (HttpDelete.METHOD_NAME.equalsIgnoreCase(method)) {
|
|
|
|
if (authData == null) {
|
|
|
|
// executor = new HttpDelete(serverUrl + HandlerConstants.API_COMMON_CONTEXT + apiEndpoint);
|
|
|
|
resp.sendError(HTTP_UNAUTHORIZED, "Unauthorized, Access token couldn't found in the current session");
|
|
|
|
// } else {
|
|
|
|
return false;
|
|
|
|
// return null;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return executor;
|
|
|
|
apiEndpoint = req.getParameter("api-endpoint");
|
|
|
|
// }
|
|
|
|
method = req.getParameter("method");
|
|
|
|
//
|
|
|
|
serverUrl = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
|
|
|
|
// /***
|
|
|
|
if (apiEndpoint == null || method == null) {
|
|
|
|
// *
|
|
|
|
resp.sendError(HTTP_BAD_REQUEST, "Bad Request, Either api-endpoint or method is empty");
|
|
|
|
// * @param req {@link HttpServletRequest}
|
|
|
|
return false;
|
|
|
|
// * @param resp {@link HttpServletResponse}
|
|
|
|
}
|
|
|
|
// * @return If request is a valid one, returns TRUE, otherwise return FALSE
|
|
|
|
return true;
|
|
|
|
// * @throws IOException If and error occurs while witting error response to client side
|
|
|
|
}
|
|
|
|
// */
|
|
|
|
|
|
|
|
// private static boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
|
|
|
/***
|
|
|
|
// HttpSession session = req.getSession(false);
|
|
|
|
*
|
|
|
|
// if (session == null) {
|
|
|
|
* @param req {@link HttpServletRequest}
|
|
|
|
// resp.sendError(HTTP_UNAUTHORIZED, "Unauthorized, You are not logged in. Please log in to the portal");
|
|
|
|
* @param resp {@link HttpServletResponse}
|
|
|
|
// return false;
|
|
|
|
* @return If successfully renew tokens, returns TRUE otherwise return FALSE
|
|
|
|
// }
|
|
|
|
* @throws IOException If and error occurs while witting error response to client side or invoke token renewal API
|
|
|
|
// authData = (AuthData) session.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY);
|
|
|
|
*/
|
|
|
|
// if (authData == null) {
|
|
|
|
private static boolean refreshToken(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
|
|
|
// resp.sendError(HTTP_UNAUTHORIZED, "Unauthorized, Access token couldn't found in the current session");
|
|
|
|
log.debug("refreshing the token");
|
|
|
|
// return false;
|
|
|
|
HttpPost tokenEndpoint = new HttpPost(
|
|
|
|
// }
|
|
|
|
serverUrl + HandlerConstants.API_COMMON_CONTEXT + HandlerConstants.TOKEN_ENDPOINT);
|
|
|
|
//
|
|
|
|
HttpSession session = req.getSession(false);
|
|
|
|
// apiEndpoint = req.getParameter("api-endpoint");
|
|
|
|
if (session == null) {
|
|
|
|
// method = req.getParameter("method");
|
|
|
|
log.error("Couldn't find a session, hence it is required to login and proceed.");
|
|
|
|
//
|
|
|
|
ProxyResponse proxyResponse = new ProxyResponse();
|
|
|
|
// serverUrl = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
|
|
|
|
proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED);
|
|
|
|
// if (apiEndpoint == null || method == null) {
|
|
|
|
proxyResponse.setExecutorResponse(
|
|
|
|
// resp.sendError(HTTP_BAD_REQUEST, "Bad Request, Either api-endpoint or method is empty");
|
|
|
|
HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil.getStatusKey(HttpStatus.SC_UNAUTHORIZED));
|
|
|
|
// return false;
|
|
|
|
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
|
|
|
// }
|
|
|
|
return false;
|
|
|
|
// return true;
|
|
|
|
}
|
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
StringEntity tokenEndpointPayload = new StringEntity(
|
|
|
|
// /***
|
|
|
|
"grant_type=refresh_token&refresh_token=" + authData.getRefreshToken() + "&scope=PRODUCTION",
|
|
|
|
// *
|
|
|
|
ContentType.APPLICATION_FORM_URLENCODED);
|
|
|
|
// * @param req {@link HttpServletRequest}
|
|
|
|
|
|
|
|
// * @param resp {@link HttpServletResponse}
|
|
|
|
tokenEndpoint.setEntity(tokenEndpointPayload);
|
|
|
|
// * @return If successfully renew tokens, returns TRUE otherwise return FALSE
|
|
|
|
String encodedClientApp = authData.getEncodedClientApp();
|
|
|
|
// * @throws IOException If and error occurs while witting error response to client side or invoke token renewal API
|
|
|
|
tokenEndpoint.setHeader("Authorization", "Basic " + encodedClientApp);
|
|
|
|
// */
|
|
|
|
tokenEndpoint.setHeader("Content-Type", ContentType.APPLICATION_FORM_URLENCODED.toString());
|
|
|
|
// private static boolean refreshToken(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
|
|
|
|
|
|
|
// log.debug("refreshing the token");
|
|
|
|
ProxyResponse tokenResultResponse = execute(tokenEndpoint);
|
|
|
|
// HttpPost tokenEndpoint = new HttpPost(
|
|
|
|
if (tokenResultResponse.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
|
|
|
|
// serverUrl + HandlerConstants.API_COMMON_CONTEXT + HandlerConstants.TOKEN_ENDPOINT);
|
|
|
|
log.error("Error occurred while refreshing access token.");
|
|
|
|
// HttpSession session = req.getSession(false);
|
|
|
|
HandlerUtil.handleError(req, resp, serverUrl, platform, tokenResultResponse);
|
|
|
|
// if (session == null) {
|
|
|
|
return false;
|
|
|
|
// resp.sendError(HTTP_UNAUTHORIZED, "Session is expired. Please log in to the server.");
|
|
|
|
}
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
JsonParser jsonParser = new JsonParser();
|
|
|
|
//
|
|
|
|
JsonElement jTokenResult = jsonParser.parse(tokenResultResponse.getData());
|
|
|
|
// StringEntity tokenEndpointPayload = new StringEntity(
|
|
|
|
|
|
|
|
// "grant_type=refresh_token&refresh_token=" + authData.getRefreshToken() + "&scope=PRODUCTION",
|
|
|
|
if (jTokenResult.isJsonObject()) {
|
|
|
|
// ContentType.APPLICATION_FORM_URLENCODED);
|
|
|
|
JsonObject jTokenResultAsJsonObject = jTokenResult.getAsJsonObject();
|
|
|
|
//
|
|
|
|
AuthData newAuthData = new AuthData();
|
|
|
|
// tokenEndpoint.setEntity(tokenEndpointPayload);
|
|
|
|
|
|
|
|
// String encodedClientApp = authData.getEncodedClientApp();
|
|
|
|
newAuthData.setAccessToken(jTokenResultAsJsonObject.get("access_token").getAsString());
|
|
|
|
// tokenEndpoint.setHeader("Authorization", "Basic " + encodedClientApp);
|
|
|
|
newAuthData.setRefreshToken(jTokenResultAsJsonObject.get("refresh_token").getAsString());
|
|
|
|
// tokenEndpoint.setHeader("Content-Type", ContentType.APPLICATION_FORM_URLENCODED.toString());
|
|
|
|
newAuthData.setScope(jTokenResultAsJsonObject.get("scope").getAsString());
|
|
|
|
//
|
|
|
|
newAuthData.setClientId(authData.getClientId());
|
|
|
|
// HttpResponse response = execute(tokenEndpoint);
|
|
|
|
newAuthData.setClientSecret(authData.getClientSecret());
|
|
|
|
// if (response == null) {
|
|
|
|
newAuthData.setEncodedClientApp(authData.getEncodedClientApp());
|
|
|
|
// resp.sendError(HTTP_INTERNAL_ERROR,
|
|
|
|
newAuthData.setUsername(authData.getUsername());
|
|
|
|
// "Internal Server Error, response of the token refresh API call is null.");
|
|
|
|
authData = newAuthData;
|
|
|
|
// return false;
|
|
|
|
session.setAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY, newAuthData);
|
|
|
|
// } else if ((response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)) {
|
|
|
|
return true;
|
|
|
|
// resp.sendError(response.getStatusLine().getStatusCode(),
|
|
|
|
}
|
|
|
|
// "Error occured while getting new access token by using refresh token.");
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
log.error("Error Occurred in token renewal process.");
|
|
|
|
// }
|
|
|
|
ProxyResponse proxyResponse = new ProxyResponse();
|
|
|
|
// String tokenResult = retrieveResponseString(response);
|
|
|
|
proxyResponse.setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
|
|
|
// JsonParser jsonParser = new JsonParser();
|
|
|
|
proxyResponse.setExecutorResponse(
|
|
|
|
//
|
|
|
|
HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil.getStatusKey(HttpStatus.SC_INTERNAL_SERVER_ERROR));
|
|
|
|
// JsonElement jTokenResult = jsonParser.parse(tokenResult);
|
|
|
|
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
|
|
|
// if (jTokenResult.isJsonObject()) {
|
|
|
|
return false;
|
|
|
|
// JsonObject jTokenResultAsJsonObject = jTokenResult.getAsJsonObject();
|
|
|
|
}
|
|
|
|
// AuthData newAuthData = new AuthData();
|
|
|
|
|
|
|
|
//
|
|
|
|
|
|
|
|
// newAuthData.setAccessToken(jTokenResultAsJsonObject.get("access_token").getAsString());
|
|
|
|
|
|
|
|
// newAuthData.setRefreshToken(jTokenResultAsJsonObject.get("refresh_token").getAsString());
|
|
|
|
|
|
|
|
// newAuthData.setScope(jTokenResultAsJsonObject.get("scope").getAsString());
|
|
|
|
|
|
|
|
// newAuthData.setClientId(authData.getClientId());
|
|
|
|
|
|
|
|
// newAuthData.setClientSecret(authData.getClientSecret());
|
|
|
|
|
|
|
|
// newAuthData.setEncodedClientApp(authData.getEncodedClientApp());
|
|
|
|
|
|
|
|
// newAuthData.setUsername(authData.getUsername());
|
|
|
|
|
|
|
|
// authData = newAuthData;
|
|
|
|
|
|
|
|
// session.setAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY, newAuthData);
|
|
|
|
|
|
|
|
// return true;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
// return false;
|
|
|
|
|
|
|
|
// }
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|