From 9d161734f879cf7efc47c8ced5acf8afd4d1a856 Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Fri, 11 Oct 2019 09:32:31 +0530 Subject: [PATCH 1/4] Add white background for page headers in APPM UI --- .../src/pages/dashboard/add-new-app/AddNewCustomApp.js | 2 +- .../src/pages/dashboard/add-new-app/AddNewEnterpriseApp.js | 2 +- .../src/pages/dashboard/add-new-app/AddNewPublicApp.js | 2 +- .../react-app/src/pages/dashboard/add-new-app/AddNewWebClip.js | 2 +- .../src/pages/dashboard/add-new-release/AddNewRelease.js | 2 +- .../react-app/src/pages/dashboard/manage/Manage.js | 2 +- .../manage/android-enterprise/ManageAndroidEnterprise.js | 2 +- .../src/pages/dashboard/manage/android-enterprise/page/Page.js | 2 +- 8 files changed, 8 insertions(+), 8 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewCustomApp.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewCustomApp.js index 8cc1bdb4d4..e1a523e9a2 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewCustomApp.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewCustomApp.js @@ -59,7 +59,7 @@ class AddNewCustomApp extends React.Component { render() { return (
- + Home diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewEnterpriseApp.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewEnterpriseApp.js index 537c3b67dd..c51f56ba5b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewEnterpriseApp.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewEnterpriseApp.js @@ -53,7 +53,7 @@ class AddNewEnterpriseApp extends React.Component { render() { return (
- + Home diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewPublicApp.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewPublicApp.js index 3e4e815ba6..b5961871da 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewPublicApp.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewPublicApp.js @@ -61,7 +61,7 @@ class AddNewEnterpriseApp extends React.Component { render() { return (
- + Home diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewWebClip.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewWebClip.js index db562e6507..f37e453901 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewWebClip.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-app/AddNewWebClip.js @@ -57,7 +57,7 @@ class AddNewEnterpriseApp extends React.Component { render() { return (
- + Home diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-release/AddNewRelease.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-release/AddNewRelease.js index fdc4d3623a..2cdaf6d2ab 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-release/AddNewRelease.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/add-new-release/AddNewRelease.js @@ -42,7 +42,7 @@ class AddNewRelease extends React.Component { const {appId, deviceType} = this.props.match.params; return (
- + Home diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/Manage.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/Manage.js index bd8039f747..2932d335b1 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/Manage.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/Manage.js @@ -36,7 +36,7 @@ class Manage extends React.Component { render() { return (
- + Home diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/android-enterprise/ManageAndroidEnterprise.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/android-enterprise/ManageAndroidEnterprise.js index 96638d2505..e0348e8fc5 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/android-enterprise/ManageAndroidEnterprise.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/android-enterprise/ManageAndroidEnterprise.js @@ -38,7 +38,7 @@ class ManageAndroidEnterprise extends React.Component { render() { return (
- + Home diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/android-enterprise/page/Page.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/android-enterprise/page/Page.js index bd4ad771e8..12f8720780 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/android-enterprise/page/Page.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/pages/dashboard/manage/android-enterprise/page/Page.js @@ -281,7 +281,7 @@ class Page extends React.Component { const {pageName, loading, clusters, applications, isAddNewClusterVisible, links} = this.state; return (
- + Home From 112eb1f77f50c86ddf7b5431504cdde7f609dc1f Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Fri, 11 Oct 2019 12:31:49 +0530 Subject: [PATCH 2/4] Call user API to get logged-in user's data when loading APPM publisher UI --- .../react-app/src/App.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js index 801f875404..cc0ab3486b 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js @@ -98,19 +98,24 @@ class App extends React.Component { }; checkUserLoggedIn = (config) => { - axios.get( - window.location.origin + config.serverConfig.invoker.uri + - config.serverConfig.invoker.publisher + "/applications/categories" + axios.post( + window.location.origin + "/publisher-ui-request-handler/user", + "platform=publisher" ).then(res => { - this.getAndroidEnterpriseToken(config); + const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); + if (lastURLSegment !== "login") { + window.location.href = window.location.origin + `/publisher/`; + } else { + this.getAndroidEnterpriseToken(config); + } }).catch((error) => { if (error.hasOwnProperty("response") && error.response.status === 401) { const redirectUrl = encodeURI(window.location.href); const pageURL = window.location.pathname; const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); - if(lastURLSegment!=="login"){ + if (lastURLSegment !== "login") { window.location.href = window.location.origin + `/publisher/login?redirect=${redirectUrl}`; - }else{ + } else { this.getAndroidEnterpriseToken(config); } } else { From ce40ea57c7431265291074aa3eaf5bf8b6e655bb Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Fri, 11 Oct 2019 14:52:00 +0530 Subject: [PATCH 3/4] Fix server error issue when calling get logged-in user in APPM The following changes are with this commit, - Check authData object is null in UserHandler class - Add check logged-in user functionality to APPM UI --- .../react-app/src/App.js | 3 +- .../react-app/src/App.js | 26 ++++++++++------ .../ui/request/interceptor/UserHandler.java | 31 ++++++++++++------- 3 files changed, 38 insertions(+), 22 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js index cc0ab3486b..0765dcff5f 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.publisher.ui/react-app/src/App.js @@ -102,8 +102,9 @@ class App extends React.Component { window.location.origin + "/publisher-ui-request-handler/user", "platform=publisher" ).then(res => { + const pageURL = window.location.pathname; const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); - if (lastURLSegment !== "login") { + if (lastURLSegment === "login") { window.location.href = window.location.origin + `/publisher/`; } else { this.getAndroidEnterpriseToken(config); diff --git a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js index 4fc452939e..9f4690c87a 100644 --- a/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js +++ b/components/application-mgt/org.wso2.carbon.device.application.mgt.store.ui/react-app/src/App.js @@ -78,22 +78,28 @@ class App extends React.Component { } checkUserLoggedIn = (config) => { - axios.get( - window.location.origin + config.serverConfig.invoker.uri + - config.serverConfig.invoker.publisher + "/applications/categories" + axios.post( + window.location.origin + "/store-ui-request-handler/user", + "platform=publisher" ).then(res => { - this.setState({ - loading: false, - config: config - }) + const pageURL = window.location.pathname; + const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); + if (lastURLSegment === "login") { + window.location.href = window.location.origin + `/store/`; + } else { + this.setState({ + loading: false, + config: config + }); + } }).catch((error) => { if (error.hasOwnProperty("response") && error.response.status === 401) { const redirectUrl = encodeURI(window.location.href); const pageURL = window.location.pathname; const lastURLSegment = pageURL.substr(pageURL.lastIndexOf('/') + 1); - if(lastURLSegment!=="login"){ + if (lastURLSegment !== "login") { window.location.href = window.location.origin + `/store/login?redirect=${redirectUrl}`; - }else{ + } else { this.setState({ loading: false, config: config @@ -106,7 +112,7 @@ class App extends React.Component { }) } }); - } + }; render() { const {loading, error} = this.state; diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java index e742e543fd..00f7a4914c 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java @@ -43,32 +43,36 @@ import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import java.io.IOException; -@MultipartConfig @WebServlet("/user") public class UserHandler extends HttpServlet { +@MultipartConfig +@WebServlet("/user") +public class UserHandler extends HttpServlet { private static final Log log = LogFactory.getLog(UserHandler.class); private static final long serialVersionUID = 9050048549140517002L; - @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) { + @Override + protected void doPost(HttpServletRequest req, HttpServletResponse resp) { try { String platform = req.getParameter(HandlerConstants.PLATFORM); String serverUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR + req.getServerName() + HandlerConstants.COLON + System.getProperty("iot.gateway.https.port"); if (StringUtils.isBlank(platform)) { - ProxyResponse proxyResponse = new ProxyResponse(); - proxyResponse.setCode(HttpStatus.SC_BAD_REQUEST); - HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse); + sendUnAuthorizeResponse(req, resp, serverUrl, platform); return; } HttpSession httpSession = req.getSession(false); if (httpSession == null) { - ProxyResponse proxyResponse = new ProxyResponse(); - proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED); - HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse); + sendUnAuthorizeResponse(req, resp, serverUrl, platform); return; } AuthData authData = (AuthData) httpSession.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY); + if (authData == null) { + sendUnAuthorizeResponse(req, resp, serverUrl, platform); + return; + } + String accessToken = authData.getAccessToken(); HttpPost tokenEndpoint = new HttpPost(serverUrl + HandlerConstants.INTROSPECT_ENDPOINT); @@ -94,9 +98,7 @@ import java.io.IOException; if (jTokenResult.isJsonObject()) { JsonObject jTokenResultAsJsonObject = jTokenResult.getAsJsonObject(); if (!jTokenResultAsJsonObject.get("active").getAsBoolean()) { - ProxyResponse proxyResponse = new ProxyResponse(); - proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED); - HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse); + sendUnAuthorizeResponse(req, resp, serverUrl, platform); return; } ProxyResponse proxyResponse = new ProxyResponse(); @@ -110,4 +112,11 @@ import java.io.IOException; log.error("Error occurred while parsing the response. ", e); } } + + private void sendUnAuthorizeResponse(HttpServletRequest req, HttpServletResponse resp, String serverUrl, String platform) + throws IOException { + ProxyResponse proxyResponse = new ProxyResponse(); + proxyResponse.setCode(HttpStatus.SC_UNAUTHORIZED); + HandlerUtil.handleError(req, resp, serverUrl, platform, proxyResponse); + } } From 02cac02d458079b3f53bebe781ffb752b543c1cf Mon Sep 17 00:00:00 2001 From: Jayasanka Date: Fri, 11 Oct 2019 15:00:23 +0530 Subject: [PATCH 4/4] Add javadoc comments to UserHandler class --- .../java/io/entgra/ui/request/interceptor/UserHandler.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java index 00f7a4914c..5268160689 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/src/main/java/io/entgra/ui/request/interceptor/UserHandler.java @@ -113,6 +113,13 @@ public class UserHandler extends HttpServlet { } } + /** + * Send UnAuthorized Response to the user + * @param req HttpServletRequest object + * @param resp HttpServletResponse object + * @param serverUrl Url of the server + * @param platform Requested platform + */ private void sendUnAuthorizeResponse(HttpServletRequest req, HttpServletResponse resp, String serverUrl, String platform) throws IOException { ProxyResponse proxyResponse = new ProxyResponse();