mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Fix minor issues in APPM proxy
This commit is contained in:
parent
cf8e23ff32
commit
96fc71c00b
@ -45,7 +45,6 @@ import javax.servlet.http.HttpSession;
|
|||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
import static java.net.HttpURLConnection.HTTP_BAD_REQUEST;
|
||||||
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;
|
||||||
|
|
||||||
@MultipartConfig @WebServlet("/invoke")
|
@MultipartConfig @WebServlet("/invoke")
|
||||||
@ -83,7 +82,6 @@ public class InvokerHandler extends HttpServlet {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (proxyResponse.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
|
if (proxyResponse.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) {
|
||||||
log.error("Error occurred while invoking the API endpoint.");
|
log.error("Error occurred while invoking the API endpoint.");
|
||||||
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
||||||
@ -136,23 +134,38 @@ public class InvokerHandler extends HttpServlet {
|
|||||||
* @throws IOException If and error occurs while witting error response to client side
|
* @throws IOException If and error occurs while witting error response to client side
|
||||||
*/
|
*/
|
||||||
private static boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
private static boolean validateRequest(HttpServletRequest req, HttpServletResponse resp) throws IOException {
|
||||||
|
serverUrl = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
|
||||||
|
apiEndpoint = req.getParameter("api-endpoint");
|
||||||
|
method = req.getParameter("method");
|
||||||
HttpSession session = req.getSession(false);
|
HttpSession session = req.getSession(false);
|
||||||
if (session == null) {
|
if (session == null) {
|
||||||
resp.sendError(HTTP_UNAUTHORIZED, "Unauthorized, You are not logged in. Please log in to the portal");
|
log.error("Unauthorized, You are not logged in. Please log in to the portal");
|
||||||
|
ProxyResponse proxyResponse = new ProxyResponse();
|
||||||
|
proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED);
|
||||||
|
proxyResponse.setExecutorResponse(
|
||||||
|
HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil.getStatusKey(HttpStatus.SC_UNAUTHORIZED));
|
||||||
|
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
authData = (AuthData) session.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY);
|
authData = (AuthData) session.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY);
|
||||||
platform = (String) session.getAttribute(HandlerConstants.PLATFORM);
|
platform = (String) session.getAttribute(HandlerConstants.PLATFORM);
|
||||||
if (authData == null) {
|
if (authData == null) {
|
||||||
resp.sendError(HTTP_UNAUTHORIZED, "Unauthorized, Access token couldn't found in the current session");
|
log.error("Unauthorized, Access token couldn't found in the current session");
|
||||||
|
ProxyResponse proxyResponse = new ProxyResponse();
|
||||||
|
proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED);
|
||||||
|
proxyResponse.setExecutorResponse(
|
||||||
|
HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil.getStatusKey(HttpStatus.SC_UNAUTHORIZED));
|
||||||
|
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
apiEndpoint = req.getParameter("api-endpoint");
|
|
||||||
method = req.getParameter("method");
|
|
||||||
serverUrl = req.getScheme() + "://" + req.getServerName() + ":" + req.getServerPort();
|
|
||||||
if (apiEndpoint == null || method == null) {
|
if (apiEndpoint == null || method == null) {
|
||||||
resp.sendError(HTTP_BAD_REQUEST, "Bad Request, Either api-endpoint or method is empty");
|
log.error("Bad Request, Either api-endpoint or method is empty");
|
||||||
|
ProxyResponse proxyResponse = new ProxyResponse();
|
||||||
|
proxyResponse.setCode(HttpStatus.SC_BAD_REQUEST);
|
||||||
|
proxyResponse.setExecutorResponse(
|
||||||
|
HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil.getStatusKey(HttpStatus.SC_BAD_REQUEST));
|
||||||
|
HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
@ -161,6 +161,9 @@ public class HandlerUtil {
|
|||||||
proxyResponse.setExecutorResponse(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil
|
proxyResponse.setExecutorResponse(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX + HandlerUtil
|
||||||
.getStatusKey(HandlerConstants.INTERNAL_ERROR_CODE));
|
.getStatusKey(HandlerConstants.INTERNAL_ERROR_CODE));
|
||||||
}
|
}
|
||||||
|
if (platform == null){
|
||||||
|
platform = "default";
|
||||||
|
}
|
||||||
|
|
||||||
resp.setStatus(proxyResponse.getCode());
|
resp.setStatus(proxyResponse.getCode());
|
||||||
resp.setContentType("application/json");
|
resp.setContentType("application/json");
|
||||||
|
|||||||
@ -154,7 +154,7 @@
|
|||||||
<Issuer>app-mgt</Issuer>
|
<Issuer>app-mgt</Issuer>
|
||||||
</SSOConfiguration>
|
</SSOConfiguration>
|
||||||
<LoginResponse>
|
<LoginResponse>
|
||||||
<SuccessCallback>/application-mgt</SuccessCallback>
|
<SuccessCallback>/apps</SuccessCallback>
|
||||||
<FailureCallback>
|
<FailureCallback>
|
||||||
<BadRequest>/pages/error/client-errors/400</BadRequest>
|
<BadRequest>/pages/error/client-errors/400</BadRequest>
|
||||||
<Unauthorized>/pages/error/client-errors/401</Unauthorized>
|
<Unauthorized>/pages/error/client-errors/401</Unauthorized>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user