-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathAuthenticator.java
More file actions
43 lines (36 loc) · 1.48 KB
/
Copy pathAuthenticator.java
File metadata and controls
43 lines (36 loc) · 1.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
package com.checkmarx.eclipse.runner;
import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.checkmarx.ast.wrapper.CxConfig;
import com.checkmarx.ast.wrapper.CxException;
import com.checkmarx.ast.wrapper.CxWrapper;
import com.checkmarx.eclipse.utils.CxLogger;
import com.checkmarx.eclipse.utils.PluginConstants;
public class Authenticator {
private final Logger log;
private Authenticator() {
this.log = LoggerFactory.getLogger(Authenticator.class);
}
// for test only
public Authenticator(Logger logger) {
this.log = logger;
}
protected static final String AUTH_STATUS = "Authentication Status: ";
public static final Authenticator INSTANCE = new Authenticator();
public String doAuthentication(String apiKey, String additionalParams) {
CxConfig config = CxConfig.builder()
.apiKey(apiKey)
.additionalParameters(additionalParams)
.build();
try {
CxWrapper wrapper = new CxWrapper(config, log);
String cxValidateOutput = wrapper.authValidate();
CxLogger.info(String.format(PluginConstants.INFO_AUTHENTICATION_STATUS, cxValidateOutput));
return cxValidateOutput;
} catch (IOException | InterruptedException | CxException e) {
CxLogger.error(String.format(PluginConstants.ERROR_AUTHENTICATING_AST, e.getMessage()), e);
return e.getMessage();
}
}
}