diff --git a/CX-SDK-API/pom.xml b/CX-SDK-API/pom.xml
index fc36667..7b4844b 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.7
@@ -19,12 +19,12 @@
com.cx.sdk
CX-SDK-Application
- 2.2
+ 2.7
com.cx.sdk
CX-SDK-Infrastructure
- 2.2
+ 2.7
org.modelmapper
diff --git a/CX-SDK-Application-Contracts/pom.xml b/CX-SDK-Application-Contracts/pom.xml
index be16594..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.2
+ 2.7
@@ -19,7 +19,7 @@
com.cx.sdk
CX-SDK-Domain
- 2.2
+ 2.7
diff --git a/CX-SDK-Application/pom.xml b/CX-SDK-Application/pom.xml
index d62e375..1ac184c 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.7
@@ -19,12 +19,12 @@
com.cx.sdk
CX-SDK-Domain
- 2.2
+ 2.7
com.cx.sdk
CX-SDK-Application-Contracts
- 2.2
+ 2.7
org.mockito
diff --git a/CX-SDK-Domain/pom.xml b/CX-SDK-Domain/pom.xml
index 61f2402..a3e6fca 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.7
diff --git a/CX-SDK-Infrastructure/pom.xml b/CX-SDK-Infrastructure/pom.xml
index c3fc0cf..fba313c 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.7
UTF-8
1.19.3
- 3.3.6
+ 3.3.7
com.cx.sdk
CX-SDK-Domain
- 2.2
+ 2.7
com.cx.sdk
CX-SDK-Application-Contracts
- 2.2
+ 2.7
com.cx.sdk
CX-SDK-OIDC-login
- 2.2
+ 2.7
diff --git a/CX-SDK-OIDC-login/pom.xml b/CX-SDK-OIDC-login/pom.xml
index 8f7c122..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.2
+ 2.7
4.0.0
CX-SDK-OIDC-login
@@ -55,12 +55,7 @@
${teamdev.version}
provided
-
+
com.teamdev.jxbrowser
jxbrowser-cross-platform
@@ -86,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/CxOIDCConnector.java b/CX-SDK-OIDC-login/src/main/java/com/cx/sdk/oidcLogin/CxOIDCConnector.java
index d6c10e7..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().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/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 60601d3..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
@@ -84,22 +84,25 @@ public String getServerURL() {
return serverURL;
}
- public String getCxVersion() {
+ public String getCxVersion() throws IOException, CxValidateResponseException {
+ return getCxVersion("");
+ }
+
+ public String getCxVersion(String clientName) throws CxValidateResponseException, IOException {
HttpResponse response;
HttpUriRequest request;
String version;
- try {
- request = RequestBuilder
- .get()
- .setUri(versionURL)
- .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;
}
@@ -121,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);
@@ -146,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);
@@ -185,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;
@@ -205,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 2d1d724..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,5 +19,7 @@ public interface ICxServer {
Permissions getPermissionsFromUserInfo(String accessToken) throws CxValidateResponseException;
- String getCxVersion();
+ String getCxVersion() throws IOException, CxValidateResponseException;
+
+ Object getCxVersion(String clientName) throws CxValidateResponseException, IOException;
}
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..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
@@ -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;
@@ -17,6 +18,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 +30,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 +65,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 +89,53 @@ 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();
- if (response == null) {
- response = new AuthenticationData(true);
+
+ 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) {
+ close();
+ if (response == null) {
+ response = new AuthenticationData(true);
+ }
+ notifyAuthenticationFinish();
}
- notifyAuthenticationFinish();
- }
+ });
+ setSize(700, 650);
+ setLocationRelativeTo(null);
+ getContentPane().add(contentPane, BorderLayout.CENTER);
+ setVisible(true);
+ browser.navigation().loadUrlAndWait(restUrl + "?" + postData);
});
- setVisible(true);
+ }
+
+ 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 +176,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 6295c66..a168aa5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -6,7 +6,7 @@
com.cx.sdk
checkmarx-sdk
pom
- 2.2
+ 2.7
CX-SDK-API