From 4d3c7e1c79cc9d978dc0c2c9285671e47f75d2d2 Mon Sep 17 00:00:00 2001 From: lasanthaDLPDS Date: Wed, 9 Oct 2019 10:14:12 +0530 Subject: [PATCH] Fix APPM login issue --- .../io/entgra/ui/request/interceptor/LoginHandler.java | 9 +++++++-- .../ui/request/interceptor/util/HandlerConstants.java | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/LoginHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/LoginHandler.java index eec6f87e51..314a863c56 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/LoginHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/LoginHandler.java @@ -118,9 +118,12 @@ public class LoginHandler extends HttpServlet { apiRegEndpoint.setEntity(constructAppRegPayload(tags)); ProxyResponse clientAppResponse = HandlerUtil.execute(apiRegEndpoint); - String clientAppResult = clientAppResponse.getData(); - if (!StringUtils.isEmpty(clientAppResult) && getTokenAndPersistInSession(req, resp, + if (clientAppResponse.getCode() == HttpStatus.SC_UNAUTHORIZED){ + HandlerUtil.handleError(req, resp, serverUrl, platform, clientAppResponse); + return; + } + if (clientAppResponse.getCode() == HttpStatus.SC_CREATED && getTokenAndPersistInSession(req, resp, clientAppResponse.getData(), scopes)) { ProxyResponse proxyResponse = new ProxyResponse(); proxyResponse.setCode(HttpStatus.SC_OK); @@ -253,6 +256,8 @@ public class LoginHandler extends HttpServlet { private StringEntity constructAppRegPayload(JsonArray tags) { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty(HandlerConstants.APP_NAME_KEY, HandlerConstants.PUBLISHER_APPLICATION_NAME); + jsonObject.addProperty(HandlerConstants.USERNAME, username); + jsonObject.addProperty(HandlerConstants.PASSWORD, password); jsonObject.addProperty("isAllowedToAllDomains", "false"); jsonObject.add(HandlerConstants.TAGS_KEY, tags); String payload = jsonObject.toString(); diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java index 12a44905a2..562f497678 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/util/HandlerConstants.java @@ -31,6 +31,8 @@ public class HandlerConstants { public static final String SESSION_AUTH_DATA_KEY = "authInfo"; public static final String UI_CONFIG_KEY = "ui-config"; public static final String PLATFORM = "platform"; + public static final String USERNAME = "username"; + public static final String PASSWORD = "password"; public static final String DEFAULT_ERROR_CALLBACK = "/pages/error/default"; public static final String ERROR_CALLBACK_KEY = "errorCallback"; public static final String API_COMMON_CONTEXT = "/api";