From 96f387b9321ce67ea09590580719413278a9a09a Mon Sep 17 00:00:00 2001 From: MuhammedS Date: Thu, 20 Aug 2020 13:41:38 +0300 Subject: [PATCH 1/6] add cxorigin to headers --- CX-SDK-API/pom.xml | 6 +++--- CX-SDK-Application-Contracts/pom.xml | 4 ++-- CX-SDK-Application/pom.xml | 6 +++--- CX-SDK-Domain/pom.xml | 2 +- CX-SDK-Infrastructure/pom.xml | 10 +++++----- CX-SDK-OIDC-login/pom.xml | 9 ++------- .../java/com/cx/sdk/oidcLogin/CxOIDCConnector.java | 2 +- .../com/cx/sdk/oidcLogin/restClient/CxServerImpl.java | 7 ++++++- .../com/cx/sdk/oidcLogin/restClient/ICxServer.java | 2 ++ pom.xml | 2 +- 10 files changed, 26 insertions(+), 24 deletions(-) diff --git a/CX-SDK-API/pom.xml b/CX-SDK-API/pom.xml index fc36667..e339b3b 100644 --- a/CX-SDK-API/pom.xml +++ b/CX-SDK-API/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.2 + 2.3 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Application - 2.2 + 2.3 com.cx.sdk CX-SDK-Infrastructure - 2.2 + 2.3 org.modelmapper diff --git a/CX-SDK-Application-Contracts/pom.xml b/CX-SDK-Application-Contracts/pom.xml index be16594..31b9e97 100644 --- a/CX-SDK-Application-Contracts/pom.xml +++ b/CX-SDK-Application-Contracts/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.2 + 2.3 @@ -19,7 +19,7 @@ com.cx.sdk CX-SDK-Domain - 2.2 + 2.3 diff --git a/CX-SDK-Application/pom.xml b/CX-SDK-Application/pom.xml index d62e375..a635b8e 100644 --- a/CX-SDK-Application/pom.xml +++ b/CX-SDK-Application/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.2 + 2.3 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Domain - 2.2 + 2.3 com.cx.sdk CX-SDK-Application-Contracts - 2.2 + 2.3 org.mockito diff --git a/CX-SDK-Domain/pom.xml b/CX-SDK-Domain/pom.xml index 61f2402..80e789d 100644 --- a/CX-SDK-Domain/pom.xml +++ b/CX-SDK-Domain/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.2 + 2.3 diff --git a/CX-SDK-Infrastructure/pom.xml b/CX-SDK-Infrastructure/pom.xml index c3fc0cf..a1be53d 100644 --- a/CX-SDK-Infrastructure/pom.xml +++ b/CX-SDK-Infrastructure/pom.xml @@ -8,29 +8,29 @@ checkmarx-sdk com.cx.sdk - 2.2 + 2.3 UTF-8 1.19.3 - 3.3.6 + 3.3.7 com.cx.sdk CX-SDK-Domain - 2.2 + 2.3 com.cx.sdk CX-SDK-Application-Contracts - 2.2 + 2.3 com.cx.sdk CX-SDK-OIDC-login - 2.2 + 2.3 diff --git a/CX-SDK-OIDC-login/pom.xml b/CX-SDK-OIDC-login/pom.xml index 8f7c122..ce6a586 100644 --- a/CX-SDK-OIDC-login/pom.xml +++ b/CX-SDK-OIDC-login/pom.xml @@ -5,7 +5,7 @@ checkmarx-sdk com.cx.sdk - 2.2 + 2.3 4.0.0 CX-SDK-OIDC-login @@ -55,12 +55,7 @@ ${teamdev.version} provided - + com.teamdev.jxbrowser jxbrowser-cross-platform diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java index d6c10e7..a81c5d4 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java @@ -19,7 +19,7 @@ public CxOIDCConnector(ICxServer cxServer, IOIDCWebBrowser webBrowser, String cl } public LoginData connect() throws Exception { - if (cxServer.getCxVersion().equals("Pre 9.0")) { + if (cxServer.getCxVersion(clientName).equals("Pre 9.0")) { throw new CxRestLoginException("The Cx version is either older than 9.0 or the server can't be reached"); } diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java index 60601d3..b34e923 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java @@ -84,7 +84,11 @@ public String getServerURL() { return serverURL; } - public String getCxVersion() { + public String getCxVersion(){ + return getCxVersion(""); + } + + public String getCxVersion(String clientName) { HttpResponse response; HttpUriRequest request; String version; @@ -92,6 +96,7 @@ public String getCxVersion() { request = RequestBuilder .get() .setUri(versionURL) + .setHeader("cxOrigin",clientName) .setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString()) .build(); response = client.execute(request); diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/ICxServer.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/ICxServer.java index 2d1d724..4bb0614 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/ICxServer.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/ICxServer.java @@ -18,4 +18,6 @@ public interface ICxServer { Permissions getPermissionsFromUserInfo(String accessToken) throws CxValidateResponseException; String getCxVersion(); + + Object getCxVersion(String clientName); } diff --git a/pom.xml b/pom.xml index 6295c66..d529382 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.cx.sdk checkmarx-sdk pom - 2.2 + 2.3 CX-SDK-API From 67ae97d62aaf7bd2fadc27a59370163538a63a2a Mon Sep 17 00:00:00 2001 From: MuhammedS Date: Thu, 27 Aug 2020 11:52:36 +0300 Subject: [PATCH 2/6] add more logging --- CX-SDK-API/pom.xml | 6 ++-- CX-SDK-Application-Contracts/pom.xml | 4 +-- CX-SDK-Application/pom.xml | 6 ++-- CX-SDK-Domain/pom.xml | 2 +- CX-SDK-Infrastructure/pom.xml | 8 ++--- CX-SDK-OIDC-login/pom.xml | 2 +- .../com/cx/sdk/oidcLogin/CxOIDCConnector.java | 14 +++++++-- .../oidcLogin/restClient/CxServerImpl.java | 31 ++++++++++--------- .../sdk/oidcLogin/restClient/ICxServer.java | 6 ++-- pom.xml | 2 +- 10 files changed, 47 insertions(+), 34 deletions(-) diff --git a/CX-SDK-API/pom.xml b/CX-SDK-API/pom.xml index e339b3b..8bb6526 100644 --- a/CX-SDK-API/pom.xml +++ b/CX-SDK-API/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.3 + 2.4 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Application - 2.3 + 2.4 com.cx.sdk CX-SDK-Infrastructure - 2.3 + 2.4 org.modelmapper diff --git a/CX-SDK-Application-Contracts/pom.xml b/CX-SDK-Application-Contracts/pom.xml index 31b9e97..1e80aa4 100644 --- a/CX-SDK-Application-Contracts/pom.xml +++ b/CX-SDK-Application-Contracts/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.3 + 2.4 @@ -19,7 +19,7 @@ com.cx.sdk CX-SDK-Domain - 2.3 + 2.4 diff --git a/CX-SDK-Application/pom.xml b/CX-SDK-Application/pom.xml index a635b8e..35faf13 100644 --- a/CX-SDK-Application/pom.xml +++ b/CX-SDK-Application/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.3 + 2.4 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Domain - 2.3 + 2.4 com.cx.sdk CX-SDK-Application-Contracts - 2.3 + 2.4 org.mockito diff --git a/CX-SDK-Domain/pom.xml b/CX-SDK-Domain/pom.xml index 80e789d..879cf84 100644 --- a/CX-SDK-Domain/pom.xml +++ b/CX-SDK-Domain/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.3 + 2.4 diff --git a/CX-SDK-Infrastructure/pom.xml b/CX-SDK-Infrastructure/pom.xml index a1be53d..66f643d 100644 --- a/CX-SDK-Infrastructure/pom.xml +++ b/CX-SDK-Infrastructure/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.3 + 2.4 @@ -20,17 +20,17 @@ com.cx.sdk CX-SDK-Domain - 2.3 + 2.4 com.cx.sdk CX-SDK-Application-Contracts - 2.3 + 2.4 com.cx.sdk CX-SDK-OIDC-login - 2.3 + 2.4 diff --git a/CX-SDK-OIDC-login/pom.xml b/CX-SDK-OIDC-login/pom.xml index ce6a586..f625c8d 100644 --- a/CX-SDK-OIDC-login/pom.xml +++ b/CX-SDK-OIDC-login/pom.xml @@ -5,7 +5,7 @@ checkmarx-sdk com.cx.sdk - 2.3 + 2.4 4.0.0 CX-SDK-OIDC-login diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java index a81c5d4..4818963 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java @@ -2,11 +2,14 @@ import com.cx.sdk.oidcLogin.exceptions.CxRestLoginException; +import com.cx.sdk.oidcLogin.exceptions.CxValidateResponseException; import com.cx.sdk.oidcLogin.restClient.ICxServer; import com.cx.sdk.oidcLogin.webBrowsing.AuthenticationData; import com.cx.sdk.oidcLogin.webBrowsing.IOIDCWebBrowser; import com.cx.sdk.oidcLogin.webBrowsing.LoginData; +import java.io.IOException; + public class CxOIDCConnector { private ICxServer cxServer; private String clientName; @@ -19,8 +22,15 @@ public CxOIDCConnector(ICxServer cxServer, IOIDCWebBrowser webBrowser, String cl } public LoginData connect() throws Exception { - if (cxServer.getCxVersion(clientName).equals("Pre 9.0")) { - throw new CxRestLoginException("The Cx version is either older than 9.0 or the server can't be reached"); + String version =""; + try { + version= (String) cxServer.getCxVersion(clientName); + } catch (IOException|CxValidateResponseException e) { + throw new CxRestLoginException(e.getMessage()); + } + + if ("Pre 9.0".equals(version) ) { + throw new CxRestLoginException("sast version is older than 9.x"); } AuthenticationData authenticationData = webBrowser.browseAuthenticationData(cxServer.getServerURL(), clientName); diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java index b34e923..1cff297 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java @@ -84,27 +84,25 @@ public String getServerURL() { return serverURL; } - public String getCxVersion(){ + public String getCxVersion() throws IOException, CxValidateResponseException { return getCxVersion(""); } - public String getCxVersion(String clientName) { + public String getCxVersion(String clientName) throws CxValidateResponseException, IOException { HttpResponse response; HttpUriRequest request; String version; - try { - request = RequestBuilder - .get() - .setUri(versionURL) - .setHeader("cxOrigin",clientName) - .setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString()) - .build(); - response = client.execute(request); - validateResponse(response, 200, GET_VERSION_ERROR); - version = new BasicResponseHandler().handleResponse(response); - } catch (IOException | CxValidateResponseException e) { - version = "Pre 9.0"; - } + + request = RequestBuilder + .get() + .setUri(versionURL) + .setHeader("cxOrigin", clientName) + .setHeader(HTTP.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString()) + .build(); + response = client.execute(request); + validateResponse(response, 200, GET_VERSION_ERROR); + version = new BasicResponseHandler().handleResponse(response); + return version; } @@ -126,6 +124,7 @@ public LoginData login(String code) throws CxRestLoginException, CxValidateRespo Long accessTokenExpirationInMilli = getAccessTokenExpirationInMilli(jsonResponse.getExpiresIn()); return new LoginData(jsonResponse.getAccessToken(), jsonResponse.getRefreshToken(), accessTokenExpirationInMilli, jsonResponse.getIdToken()); } catch (IOException e) { + logger.trace("Failed to login", e); throw new CxRestLoginException("Failed to login: " + e.getMessage()); } finally { HttpClientUtils.closeQuietly(loginResponse); @@ -151,6 +150,7 @@ public LoginData getAccessTokenFromRefreshToken(String refreshToken) throws CxRe Long accessTokenExpirationInMilli = getAccessTokenExpirationInMilli(jsonResponse.getExpiresIn()); return new LoginData(jsonResponse.getAccessToken(), jsonResponse.getRefreshToken(), accessTokenExpirationInMilli, jsonResponse.getIdToken()); } catch (IOException e) { + logger.trace("Failed to get new access token from refresh token: ", e); throw new CxRestLoginException("Failed to get new access token from refresh token: " + e.getMessage()); } finally { HttpClientUtils.closeQuietly(loginResponse); @@ -210,6 +210,7 @@ private static void validateResponse(HttpResponse response, int status, String m } } } catch (IOException e) { + e.printStackTrace(); throw new CxValidateResponseException("Error parse REST response body: " + e.getMessage()); } } diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/ICxServer.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/ICxServer.java index 4bb0614..785338e 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/ICxServer.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/ICxServer.java @@ -7,6 +7,8 @@ import com.cx.sdk.oidcLogin.restClient.entities.Permissions; import com.cx.sdk.oidcLogin.webBrowsing.LoginData; +import java.io.IOException; + public interface ICxServer { String getServerURL(); @@ -17,7 +19,7 @@ public interface ICxServer { Permissions getPermissionsFromUserInfo(String accessToken) throws CxValidateResponseException; - String getCxVersion(); + String getCxVersion() throws IOException, CxValidateResponseException; - Object getCxVersion(String clientName); + Object getCxVersion(String clientName) throws CxValidateResponseException, IOException; } diff --git a/pom.xml b/pom.xml index d529382..a9ad23a 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.cx.sdk checkmarx-sdk pom - 2.3 + 2.4 CX-SDK-API From 772ff5bdeafae00c9b13daf6a429edacb135ee8e Mon Sep 17 00:00:00 2001 From: MuhammedS Date: Thu, 3 Sep 2020 16:22:05 +0300 Subject: [PATCH 3/6] support mac, creat browserview in UI thread --- CX-SDK-API/pom.xml | 6 +-- CX-SDK-Application-Contracts/pom.xml | 4 +- CX-SDK-Application/pom.xml | 6 +-- CX-SDK-Domain/pom.xml | 2 +- CX-SDK-Infrastructure/pom.xml | 8 ++-- CX-SDK-OIDC-login/pom.xml | 4 +- .../oidcLogin/webBrowsing/OIDCWebBrowser.java | 44 +++++++++++++------ pom.xml | 2 +- 8 files changed, 47 insertions(+), 29 deletions(-) diff --git a/CX-SDK-API/pom.xml b/CX-SDK-API/pom.xml index 8bb6526..739bb36 100644 --- a/CX-SDK-API/pom.xml +++ b/CX-SDK-API/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.4 + 2.5 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Application - 2.4 + 2.5 com.cx.sdk CX-SDK-Infrastructure - 2.4 + 2.5 org.modelmapper diff --git a/CX-SDK-Application-Contracts/pom.xml b/CX-SDK-Application-Contracts/pom.xml index 1e80aa4..016626f 100644 --- a/CX-SDK-Application-Contracts/pom.xml +++ b/CX-SDK-Application-Contracts/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.4 + 2.5 @@ -19,7 +19,7 @@ com.cx.sdk CX-SDK-Domain - 2.4 + 2.5 diff --git a/CX-SDK-Application/pom.xml b/CX-SDK-Application/pom.xml index 35faf13..3678322 100644 --- a/CX-SDK-Application/pom.xml +++ b/CX-SDK-Application/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.4 + 2.5 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Domain - 2.4 + 2.5 com.cx.sdk CX-SDK-Application-Contracts - 2.4 + 2.5 org.mockito diff --git a/CX-SDK-Domain/pom.xml b/CX-SDK-Domain/pom.xml index 879cf84..031851f 100644 --- a/CX-SDK-Domain/pom.xml +++ b/CX-SDK-Domain/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.4 + 2.5 diff --git a/CX-SDK-Infrastructure/pom.xml b/CX-SDK-Infrastructure/pom.xml index 66f643d..75bb5e5 100644 --- a/CX-SDK-Infrastructure/pom.xml +++ b/CX-SDK-Infrastructure/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.4 + 2.5 @@ -20,17 +20,17 @@ com.cx.sdk CX-SDK-Domain - 2.4 + 2.5 com.cx.sdk CX-SDK-Application-Contracts - 2.4 + 2.5 com.cx.sdk CX-SDK-OIDC-login - 2.4 + 2.5 diff --git a/CX-SDK-OIDC-login/pom.xml b/CX-SDK-OIDC-login/pom.xml index f625c8d..f5ec031 100644 --- a/CX-SDK-OIDC-login/pom.xml +++ b/CX-SDK-OIDC-login/pom.xml @@ -5,7 +5,7 @@ checkmarx-sdk com.cx.sdk - 2.4 + 2.5 4.0.0 CX-SDK-OIDC-login @@ -81,7 +81,7 @@ commons-io commons-io - 2.4 + 2.5 log4j diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java index 1dac843..31626e3 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java @@ -17,6 +17,7 @@ import com.teamdev.jxbrowser.net.callback.*; import com.teamdev.jxbrowser.os.Environment; import com.teamdev.jxbrowser.view.swing.BrowserView; + import javax.swing.*; import java.awt.*; import java.awt.event.WindowAdapter; @@ -28,7 +29,9 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.concurrent.TimeUnit; +import static com.teamdev.jxbrowser.os.Environment.isMac; import static javax.swing.JOptionPane.OK_OPTION; public class OIDCWebBrowser extends JFrame implements IOIDCWebBrowser { @@ -61,7 +64,7 @@ public AuthenticationData browseAuthenticationData(String serverUrl, String clie } private void initBrowser(String restUrl) { - if (Environment.isMac()) { + if (isMac()) { System.setProperty("java.ipc.external", "true"); System.setProperty("jxbrowser.ipc.external", "true"); @@ -85,34 +88,49 @@ private void initBrowser(String restUrl) { browser = engine.newBrowser(); + browser.navigation().on(FrameLoadFinished.class, AddResponsesHandler()); + String postData = getPostData(); String pathToImage = "/checkmarxIcon.jpg"; setIconImage(new ImageIcon(getClass().getResource(pathToImage), "checkmarx icon").getImage()); - browser.navigation().loadUrlAndWait(restUrl+"?"+postData); - contentPane.add(BrowserView.newInstance(browser)); - browser.navigation().on(FrameLoadFinished.class, AddResponsesHandler()); - setSize(700, 650); - setLocationRelativeTo(null); - getContentPane().add(contentPane, BorderLayout.CENTER); addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { - engine.close(); + close(); if (response == null) { response = new AuthenticationData(true); } notifyAuthenticationFinish(); } }); - setVisible(true); + SwingUtilities.invokeLater(() -> { + BrowserView browserView = BrowserView.newInstance(browser); + contentPane.add(browserView); + setSize(700, 650); + setLocationRelativeTo(null); + getContentPane().add(contentPane, BorderLayout.CENTER); + setVisible(true); + browser.navigation().loadUrlAndWait(restUrl + "?" + postData); + }); + + + } + + private static void close() { + if (isMac()) { + // On macOS the engine must be closed in UI thread + ENGINE.close(); + } else { + // On Windows and Linux it must be closed in non-UI thread + new Thread(ENGINE::close).start(); + } } public static Engine defaultEngine() { - if(ENGINE == null || ENGINE.isClosed() ) { + if (ENGINE == null || ENGINE.isClosed()) { ENGINE = Engine.newInstance(EngineOptions .newBuilder(RenderingMode.HARDWARE_ACCELERATED) .userAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.149 Safari/537.36") - .enableIncognito() .addSwitch("--disable-google-traffic") .build()); ENGINE.network().set(CanGetCookiesCallback.class, params -> CanGetCookiesCallback.Response.can()); @@ -153,12 +171,12 @@ public void logout(String idToken) { Engine engine = defaultEngine(); browser = engine.newBrowser(); browser.navigation().loadUrl(endSessionEndPoint + String.format(END_SESSION_FORMAT, idToken, serverUrl + "/cxwebclient/")); - browser.navigation().on(FrameLoadFinished.class,disposeOnLoadDone()); + browser.navigation().on(FrameLoadFinished.class, disposeOnLoadDone()); } private Observer disposeOnLoadDone() { return param -> { - param.frame().browser().close(); + param.frame().browser().close(); }; } diff --git a/pom.xml b/pom.xml index a9ad23a..d9e34df 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.cx.sdk checkmarx-sdk pom - 2.4 + 2.5 CX-SDK-API From cf25c104ccfb5b05bf1cf722b8697fe067544598 Mon Sep 17 00:00:00 2001 From: MuhammedS Date: Sun, 20 Sep 2020 16:11:40 +0300 Subject: [PATCH 4/6] handle large expiration time --- CX-SDK-API/pom.xml | 6 ++--- CX-SDK-Application-Contracts/pom.xml | 4 +-- CX-SDK-Application/pom.xml | 6 ++--- CX-SDK-Domain/pom.xml | 2 +- CX-SDK-Infrastructure/pom.xml | 8 +++--- CX-SDK-OIDC-login/pom.xml | 4 +-- .../cx/sdk/oidcLogin/dto/AccessTokenDTO.java | 6 ++--- .../oidcLogin/restClient/CxServerImpl.java | 2 +- .../oidcLogin/webBrowsing/OIDCWebBrowser.java | 27 ++++++++++++------- pom.xml | 2 +- 10 files changed, 37 insertions(+), 30 deletions(-) diff --git a/CX-SDK-API/pom.xml b/CX-SDK-API/pom.xml index 739bb36..991a1a1 100644 --- a/CX-SDK-API/pom.xml +++ b/CX-SDK-API/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.5 + 2.6 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Application - 2.5 + 2.6 com.cx.sdk CX-SDK-Infrastructure - 2.5 + 2.6 org.modelmapper diff --git a/CX-SDK-Application-Contracts/pom.xml b/CX-SDK-Application-Contracts/pom.xml index 016626f..71a23c3 100644 --- a/CX-SDK-Application-Contracts/pom.xml +++ b/CX-SDK-Application-Contracts/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.5 + 2.6 @@ -19,7 +19,7 @@ com.cx.sdk CX-SDK-Domain - 2.5 + 2.6 diff --git a/CX-SDK-Application/pom.xml b/CX-SDK-Application/pom.xml index 3678322..cf58cd1 100644 --- a/CX-SDK-Application/pom.xml +++ b/CX-SDK-Application/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.5 + 2.6 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Domain - 2.5 + 2.6 com.cx.sdk CX-SDK-Application-Contracts - 2.5 + 2.6 org.mockito diff --git a/CX-SDK-Domain/pom.xml b/CX-SDK-Domain/pom.xml index 031851f..e4eb017 100644 --- a/CX-SDK-Domain/pom.xml +++ b/CX-SDK-Domain/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.5 + 2.6 diff --git a/CX-SDK-Infrastructure/pom.xml b/CX-SDK-Infrastructure/pom.xml index 75bb5e5..6ec7224 100644 --- a/CX-SDK-Infrastructure/pom.xml +++ b/CX-SDK-Infrastructure/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.5 + 2.6 @@ -20,17 +20,17 @@ com.cx.sdk CX-SDK-Domain - 2.5 + 2.6 com.cx.sdk CX-SDK-Application-Contracts - 2.5 + 2.6 com.cx.sdk CX-SDK-OIDC-login - 2.5 + 2.6 diff --git a/CX-SDK-OIDC-login/pom.xml b/CX-SDK-OIDC-login/pom.xml index f5ec031..574f821 100644 --- a/CX-SDK-OIDC-login/pom.xml +++ b/CX-SDK-OIDC-login/pom.xml @@ -5,7 +5,7 @@ checkmarx-sdk com.cx.sdk - 2.5 + 2.6 4.0.0 CX-SDK-OIDC-login @@ -31,7 +31,7 @@ UTF-8 - 7.5 + 7.9 6.23 diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/dto/AccessTokenDTO.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/dto/AccessTokenDTO.java index 52d28f9..7a2e162 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/dto/AccessTokenDTO.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/dto/AccessTokenDTO.java @@ -11,7 +11,7 @@ public class AccessTokenDTO { private String accessToken; @JsonProperty("expires_in") - private int expiresIn; + private long expiresIn; @JsonProperty("token_type") private String tokenType; @@ -35,11 +35,11 @@ public void setAccessToken(String accessToken) { this.accessToken = accessToken; } - public int getExpiresIn() { + public long getExpiresIn() { return expiresIn; } - public void setExpiresIn(int expiresIn) { + public void setExpiresIn(long expiresIn) { this.expiresIn = expiresIn; } diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java index 1cff297..6ea49ed 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/restClient/CxServerImpl.java @@ -190,7 +190,7 @@ private Permissions getPermissions(UserInfoDTO jsonResponse) { sastPermissions.contains(Consts.MANAGE_RESULTS_EXPLOITABILITY)); } - private Long getAccessTokenExpirationInMilli(int accessTokenExpirationInSec) { + private Long getAccessTokenExpirationInMilli(long accessTokenExpirationInSec) { long currentTime = System.currentTimeMillis(); long accessTokenExpInMilli = accessTokenExpirationInSec * 1000; return currentTime + accessTokenExpInMilli; diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java index 31626e3..f183c67 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java @@ -4,6 +4,7 @@ import com.cx.sdk.oidcLogin.exceptions.CxRestLoginException; import com.google.common.base.Splitter; import com.teamdev.jxbrowser.browser.Browser; +import com.teamdev.jxbrowser.browser.event.BrowserClosed; import com.teamdev.jxbrowser.dom.Document; import com.teamdev.jxbrowser.dom.Element; import com.teamdev.jxbrowser.engine.Engine; @@ -93,19 +94,25 @@ private void initBrowser(String restUrl) { String postData = getPostData(); String pathToImage = "/checkmarxIcon.jpg"; setIconImage(new ImageIcon(getClass().getResource(pathToImage), "checkmarx icon").getImage()); - addWindowListener(new WindowAdapter() { - @Override - public void windowClosing(WindowEvent e) { - close(); - if (response == null) { - response = new AuthenticationData(true); - } - notifyAuthenticationFinish(); - } - }); + SwingUtilities.invokeLater(() -> { + browser.on(BrowserClosed.class, event -> + SwingUtilities.invokeLater(() -> { + this.setVisible(false); + this.dispose(); + })); BrowserView browserView = BrowserView.newInstance(browser); contentPane.add(browserView); + addWindowListener(new WindowAdapter() { + @Override + public void windowClosing(WindowEvent e) { + SwingUtilities.invokeLater(engine::close); + if (response == null) { + response = new AuthenticationData(true); + } + notifyAuthenticationFinish(); + } + }); setSize(700, 650); setLocationRelativeTo(null); getContentPane().add(contentPane, BorderLayout.CENTER); diff --git a/pom.xml b/pom.xml index d9e34df..76ce533 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.cx.sdk checkmarx-sdk pom - 2.5 + 2.6 CX-SDK-API From e97dd64081ab0567be1f6d7c4dc82f0a6c71aead Mon Sep 17 00:00:00 2001 From: MuhammedS Date: Sun, 20 Sep 2020 16:14:39 +0300 Subject: [PATCH 5/6] handle large expiration time --- CX-SDK-OIDC-login/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CX-SDK-OIDC-login/pom.xml b/CX-SDK-OIDC-login/pom.xml index 574f821..57c703d 100644 --- a/CX-SDK-OIDC-login/pom.xml +++ b/CX-SDK-OIDC-login/pom.xml @@ -31,7 +31,7 @@ UTF-8 - 7.9 + 7.5 6.23 From 0d8aad4da96e773172c4a982f73255bc3fade02b Mon Sep 17 00:00:00 2001 From: MuhammedS Date: Sun, 20 Sep 2020 16:50:54 +0300 Subject: [PATCH 6/6] handle large expiration time --- CX-SDK-API/pom.xml | 6 +++--- CX-SDK-Application-Contracts/pom.xml | 4 ++-- CX-SDK-Application/pom.xml | 6 +++--- CX-SDK-Domain/pom.xml | 2 +- CX-SDK-Infrastructure/pom.xml | 8 ++++---- CX-SDK-OIDC-login/pom.xml | 2 +- .../com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java | 4 +--- pom.xml | 2 +- 8 files changed, 16 insertions(+), 18 deletions(-) diff --git a/CX-SDK-API/pom.xml b/CX-SDK-API/pom.xml index 991a1a1..7b4844b 100644 --- a/CX-SDK-API/pom.xml +++ b/CX-SDK-API/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.6 + 2.7 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Application - 2.6 + 2.7 com.cx.sdk CX-SDK-Infrastructure - 2.6 + 2.7 org.modelmapper diff --git a/CX-SDK-Application-Contracts/pom.xml b/CX-SDK-Application-Contracts/pom.xml index 71a23c3..7ed46a5 100644 --- a/CX-SDK-Application-Contracts/pom.xml +++ b/CX-SDK-Application-Contracts/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.6 + 2.7 @@ -19,7 +19,7 @@ com.cx.sdk CX-SDK-Domain - 2.6 + 2.7 diff --git a/CX-SDK-Application/pom.xml b/CX-SDK-Application/pom.xml index cf58cd1..1ac184c 100644 --- a/CX-SDK-Application/pom.xml +++ b/CX-SDK-Application/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.6 + 2.7 @@ -19,12 +19,12 @@ com.cx.sdk CX-SDK-Domain - 2.6 + 2.7 com.cx.sdk CX-SDK-Application-Contracts - 2.6 + 2.7 org.mockito diff --git a/CX-SDK-Domain/pom.xml b/CX-SDK-Domain/pom.xml index e4eb017..a3e6fca 100644 --- a/CX-SDK-Domain/pom.xml +++ b/CX-SDK-Domain/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.6 + 2.7 diff --git a/CX-SDK-Infrastructure/pom.xml b/CX-SDK-Infrastructure/pom.xml index 6ec7224..fba313c 100644 --- a/CX-SDK-Infrastructure/pom.xml +++ b/CX-SDK-Infrastructure/pom.xml @@ -8,7 +8,7 @@ checkmarx-sdk com.cx.sdk - 2.6 + 2.7 @@ -20,17 +20,17 @@ com.cx.sdk CX-SDK-Domain - 2.6 + 2.7 com.cx.sdk CX-SDK-Application-Contracts - 2.6 + 2.7 com.cx.sdk CX-SDK-OIDC-login - 2.6 + 2.7 diff --git a/CX-SDK-OIDC-login/pom.xml b/CX-SDK-OIDC-login/pom.xml index 57c703d..65678f1 100644 --- a/CX-SDK-OIDC-login/pom.xml +++ b/CX-SDK-OIDC-login/pom.xml @@ -5,7 +5,7 @@ checkmarx-sdk com.cx.sdk - 2.6 + 2.7 4.0.0 CX-SDK-OIDC-login diff --git a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java index f183c67..eaa6fb1 100644 --- a/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java +++ b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/webBrowsing/OIDCWebBrowser.java @@ -106,7 +106,7 @@ private void initBrowser(String restUrl) { addWindowListener(new WindowAdapter() { @Override public void windowClosing(WindowEvent e) { - SwingUtilities.invokeLater(engine::close); + close(); if (response == null) { response = new AuthenticationData(true); } @@ -119,8 +119,6 @@ public void windowClosing(WindowEvent e) { setVisible(true); browser.navigation().loadUrlAndWait(restUrl + "?" + postData); }); - - } private static void close() { diff --git a/pom.xml b/pom.xml index 76ce533..a168aa5 100644 --- a/pom.xml +++ b/pom.xml @@ -6,7 +6,7 @@ com.cx.sdk checkmarx-sdk pom - 2.6 + 2.7 CX-SDK-API