Skip to content

Commit 145426a

Browse files
feat: enable oauth2 as default (#182)
* feat: enable oauth2 as default * fix: menu item name for project scan * feat: add preference to force token auth * fix: update environment correctly * chore: keep token auth as default for now * chore: update Eclipse default URL to https://api.snyk.io * fix: update deps
1 parent 28daa82 commit 145426a

18 files changed

Lines changed: 84 additions & 119 deletions

File tree

plugin/META-INF/MANIFEST.MF

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@ Require-Bundle: org.eclipse.ui,
2626
Automatic-Module-Name: io.snyk.eclipse.plugin.tests
2727
Bundle-ActivationPolicy: lazy
2828
Bundle-ClassPath: .,
29-
target/dependency/commons-codec-1.16.1.jar,
29+
target/dependency/commons-codec-1.17.0.jar,
3030
target/dependency/commons-lang3-3.12.0.jar,
3131
target/dependency/commons-logging-1.2.jar,
3232
target/dependency/httpclient-4.5.14.jar,
3333
target/dependency/httpcore-4.4.16.jar,
34-
target/dependency/jackson-annotations-2.16.1.jar,
35-
target/dependency/jackson-core-2.16.1.jar,
36-
target/dependency/jackson-databind-2.16.1.jar,
34+
target/dependency/jackson-annotations-2.16.2.jar,
35+
target/dependency/jackson-core-2.16.2.jar,
36+
target/dependency/jackson-databind-2.16.2.jar,
3737
target/dependency/javax.inject-1.jar

plugin/OSGI-INF/l10n/bundle.properties

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,8 @@ view.name=Snyk Results
77
page.name=Snyk
88
command.name=Run
99
command.label=Snyk Test
10-
command.label.0=Snyk Test
10+
command.label.0=Snyk Test Project
1111

1212
scanWorkspace.name=snykWorkspaceScan
1313
scanWorkspace.label=Snyk Test Workspace
14-
command.label.0=Snyk Test Workspace
1514

plugin/build.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,14 @@ bin.includes = plugin.xml,\
77
contexts.xml,\
88
OSGI-INF/l10n/bundle.properties,\
99
OSGI-INF/,\
10-
target/dependency/commons-codec-1.16.1.jar,\
10+
target/dependency/commons-codec-1.17.0.jar,\
1111
target/dependency/commons-lang3-3.12.0.jar,\
1212
target/dependency/commons-logging-1.2.jar,\
1313
target/dependency/httpclient-4.5.14.jar,\
1414
target/dependency/httpcore-4.4.16.jar,\
15-
target/dependency/jackson-annotations-2.16.1.jar,\
16-
target/dependency/jackson-core-2.16.1.jar,\
17-
target/dependency/jackson-databind-2.16.1.jar,\
15+
target/dependency/jackson-annotations-2.16.2.jar,\
16+
target/dependency/jackson-core-2.16.2.jar,\
17+
target/dependency/jackson-databind-2.16.2.jar,\
1818
target/dependency/javax.inject-1.jar
1919
src.includes =src/,\
2020
icons/

plugin/io.snyk.eclipse.plugin.eml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@
44
<contentEntry url="file://$MODULE_DIR$">
55
<excludeFolder url="file://$MODULE_DIR$/target"/>
66
</contentEntry>
7-
<lib name="commons-codec-1.16.1.jar" scope="COMPILE">
8-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-codec-1.16.1.jar!/"/>
7+
<lib name="commons-codec-1.17.0.jar" scope="COMPILE">
8+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-codec-1.17.0.jar!/"/>
99
</lib>
1010
<lib name="commons-lang3-3.12.0.jar" scope="COMPILE">
1111
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/commons-lang3-3.12.0.jar!/"/>
@@ -19,27 +19,27 @@
1919
<lib name="httpcore-4.4.16.jar" scope="COMPILE">
2020
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/httpcore-4.4.16.jar!/"/>
2121
</lib>
22-
<lib name="jackson-annotations-2.16.1.jar" scope="COMPILE">
23-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-annotations-2.16.1.jar!/"/>
22+
<lib name="jackson-annotations-2.16.2.jar" scope="COMPILE">
23+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-annotations-2.16.2.jar!/"/>
2424
</lib>
25-
<lib name="jackson-core-2.16.1.jar" scope="COMPILE">
26-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-core-2.16.1.jar!/"/>
25+
<lib name="jackson-core-2.16.2.jar" scope="COMPILE">
26+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-core-2.16.2.jar!/"/>
2727
</lib>
28-
<lib name="jackson-databind-2.16.1.jar" scope="COMPILE">
29-
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-databind-2.16.1.jar!/"/>
28+
<lib name="jackson-databind-2.16.2.jar" scope="COMPILE">
29+
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/jackson-databind-2.16.2.jar!/"/>
3030
</lib>
3131
<lib name="javax.inject-1.jar" scope="COMPILE">
3232
<relative-module-cls project-related="jar://$PROJECT_DIR$/plugin/target/dependency/javax.inject-1.jar!/"/>
3333
</lib>
3434
<levels>
35-
<level name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.16.1" value="project"/>
36-
<level name="Maven: com.fasterxml.jackson.core:jackson-core:2.16.1" value="project"/>
37-
<level name="Maven: com.fasterxml.jackson.core:jackson-databind:2.16.1" value="project"/>
35+
<level name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.16.2" value="project"/>
36+
<level name="Maven: com.fasterxml.jackson.core:jackson-core:2.16.2" value="project"/>
37+
<level name="Maven: com.fasterxml.jackson.core:jackson-databind:2.16.2" value="project"/>
3838
<level name="Maven: org.apache.commons:commons-lang3:3.12.0" value="project"/>
3939
<level name="Maven: org.apache.httpcomponents:httpcore:4.4.16" value="project"/>
4040
<level name="Maven: org.apache.httpcomponents:httpclient:4.5.14" value="project"/>
4141
<level name="Maven: commons-logging:commons-logging:1.2" value="project"/>
42-
<level name="Maven: commons-codec:commons-codec:1.16.1" value="project"/>
42+
<level name="Maven: commons-codec:commons-codec:1.17.0" value="project"/>
4343
<level name="Maven: javax.inject:javax.inject:1" value="project"/>
4444
</levels>
4545
</component>

plugin/pom.xml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,19 @@
1717
<dependency>
1818
<groupId>com.fasterxml.jackson.core</groupId>
1919
<artifactId>jackson-annotations</artifactId>
20-
<version>2.16.1</version>
20+
<version>2.16.2</version>
2121
<type>jar</type>
2222
</dependency>
2323
<dependency>
2424
<groupId>com.fasterxml.jackson.core</groupId>
2525
<artifactId>jackson-core</artifactId>
26-
<version>2.16.1</version>
26+
<version>2.16.2</version>
2727
<type>jar</type>
2828
</dependency>
2929
<dependency>
3030
<groupId>com.fasterxml.jackson.core</groupId>
3131
<artifactId>jackson-databind</artifactId>
32-
<version>2.16.1</version>
32+
<version>2.16.2</version>
3333
<type>jar</type>
3434
</dependency>
3535
<dependency>
@@ -58,7 +58,7 @@
5858
<dependency>
5959
<groupId>commons-codec</groupId>
6060
<artifactId>commons-codec</artifactId>
61-
<version>1.16.1</version>
61+
<version>1.17.0</version>
6262
</dependency>
6363
<dependency>
6464
<groupId>javax.inject</groupId>

plugin/src/main/java/io/snyk/eclipse/plugin/properties/PreferencesPage.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,14 @@ public void init(IWorkbench workbench) {
3535
protected void createFieldEditors() {
3636
TokenFieldEditor tokenField = new TokenFieldEditor(Preferences.getInstance(), Preferences.AUTH_TOKEN_KEY,
3737
"Snyk API Token:", getFieldEditorParent());
38+
39+
addField(new BooleanFieldEditor(Preferences.USE_TOKEN_AUTH, "Use token authentication. It is recommended to keep this turned off, as the default OAuth2 authentication is more secure.",
40+
getFieldEditorParent()));
41+
3842
addField(tokenField);
39-
addField(new StringFieldEditor(Preferences.PATH_KEY, "Path:", getFieldEditorParent()));
40-
addField(new StringFieldEditor(Preferences.ENDPOINT_KEY, "Custom Endpoint:", getFieldEditorParent()));
41-
addField(new BooleanFieldEditor(Preferences.INSECURE_KEY, "Allow unknown certificate authorities",
43+
addField(new StringFieldEditor(Preferences.PATH_KEY, "Path:", 80, getFieldEditorParent()));
44+
addField(new StringFieldEditor(Preferences.ENDPOINT_KEY, "Custom Endpoint:", 80, getFieldEditorParent()));
45+
addField(new BooleanFieldEditor(Preferences.INSECURE_KEY, "Allow unknown certificate authorities",
4246
getFieldEditorParent()));
4347

4448
addField(space());
@@ -61,11 +65,11 @@ protected void createFieldEditors() {
6165
addField(new BooleanFieldEditor(Preferences.SCANNING_MODE_AUTOMATIC, "Scan automatically on start-up and save", getFieldEditorParent()));
6266
addField(space());
6367
addField(new LabelFieldEditor("Advanced options:", getFieldEditorParent()));
64-
addField(new StringFieldEditor(Preferences.ORGANIZATION_KEY, "Organization:", getFieldEditorParent()));
68+
addField(new StringFieldEditor(Preferences.ORGANIZATION_KEY, "Organization:", 80, getFieldEditorParent()));
6569
addField(
66-
new StringFieldEditor(Preferences.ADDITIONAL_PARAMETERS, "Additional Parameters:", getFieldEditorParent()));
70+
new StringFieldEditor(Preferences.ADDITIONAL_PARAMETERS, "Additional Parameters:", 80, getFieldEditorParent()));
6771
addField(
68-
new StringFieldEditor(Preferences.ADDITIONAL_ENVIRONMENT, "Additional Environment:", getFieldEditorParent()));
72+
new StringFieldEditor(Preferences.ADDITIONAL_ENVIRONMENT, "Additional Environment:", 80, getFieldEditorParent()));
6973

7074
addField(space());
7175
BooleanFieldEditor manageBinaries = new BooleanFieldEditor(Preferences.MANAGE_BINARIES_AUTOMATICALLY,
@@ -74,7 +78,7 @@ protected void createFieldEditors() {
7478
System.out.println("managed bionaries changed");
7579
});
7680
addField(manageBinaries);
77-
addField(new StringFieldEditor(Preferences.CLI_BASE_URL, "Base URL for CLI download:", getFieldEditorParent()));
81+
addField(new StringFieldEditor(Preferences.CLI_BASE_URL, "Base URL for CLI download:", 80, getFieldEditorParent()));
7882
addField(new FileFieldEditor(Preferences.CLI_PATH, "Snyk CLI (incl. Language Server):", getFieldEditorParent()));
7983

8084
addField(space());
@@ -91,7 +95,8 @@ protected void createFieldEditors() {
9195
+ "paths are safe to scan. Every path below a given path is considered safe to scan. \n"
9296
+ "Please separate entries with \"" + File.pathSeparator + "\".",
9397
getFieldEditorParent()));
94-
addField(new StringFieldEditor(Preferences.TRUSTED_FOLDERS, "Trusted Folders:", getFieldEditorParent()));
98+
StringFieldEditor trustedFoldersEditor = new StringFieldEditor(Preferences.TRUSTED_FOLDERS, "Trusted Folders:", 80, getFieldEditorParent());
99+
addField(trustedFoldersEditor);
95100
disableSnykCodeIfOrgDisabled();
96101
}
97102

plugin/src/main/java/io/snyk/eclipse/plugin/properties/TokenFieldEditor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class TokenFieldEditor extends StringFieldEditor {
1111

1212
protected TokenFieldEditor(io.snyk.eclipse.plugin.properties.preferences.Preferences store, String name, String labelText,
1313
Composite parent) {
14-
super(name, labelText, parent);
14+
super(name, labelText, 80, parent);
1515
this.store = store;
1616
getTextControl().setEchoChar('*');
1717
}

plugin/src/main/java/io/snyk/eclipse/plugin/properties/preferences/Preferences.java

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public class Preferences {
1717

1818
public static synchronized Preferences getInstance() {
1919
if (CURRENT_PREFERENCES == null) {
20-
CURRENT_PREFERENCES = new Preferences(new SecurePreferenceStore());
20+
CURRENT_PREFERENCES = new Preferences(new SecurePreferenceStore());
2121
}
2222
return CURRENT_PREFERENCES;
2323
}
@@ -42,15 +42,13 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
4242
public static final String ADDITIONAL_ENVIRONMENT = "ADDITIONAL_ENVIRONMENT";
4343
public static final String SEND_ERROR_REPORTS = "SEND_ERROR_REPORTS";
4444
public static final String LSP_VERSION = "LSP_VERSION";
45+
public static final String USE_TOKEN_AUTH = "useTokenAuth";
4546

4647
// This is a bit confusing - CLI takes DISABLE as env variable, but we ask for ENABLE, so we need to revert it
4748
// when populating the environment
4849
public static final String ENABLE_TELEMETRY = EnvironmentConstants.ENV_DISABLE_ANALYTICS;
4950
public static final String MANAGE_BINARIES_AUTOMATICALLY = "SNYK_CFG_MANAGE_BINARIES_AUTOMATICALLY";
5051
public static final String ORGANIZATION_KEY = EnvironmentConstants.ENV_SNYK_ORG;
51-
public static final String AUTHENTICATION_METHOD = "AUTHENTICATION_METHOD";
52-
public static final String AUTH_METHOD_TOKEN = "token";
53-
public static final String AUTH_METHOD_OAUTH = "oauth";
5452
public static final String SCANNING_MODE_AUTOMATIC = "scanningMode";
5553

5654
private final PreferenceStore store;
@@ -81,38 +79,38 @@ public static synchronized Preferences getInstance(PreferenceStore store) {
8179
if (getPref(LSP_VERSION) == null) {
8280
store(LSP_VERSION, "1");
8381
}
84-
85-
if (getPref(AUTHENTICATION_METHOD) == null || getPref(AUTHENTICATION_METHOD).isBlank()) {
86-
store(AUTHENTICATION_METHOD, AUTH_METHOD_TOKEN);
87-
}
8882

8983
String token = SystemUtils.getEnvironmentVariable(EnvironmentConstants.ENV_SNYK_TOKEN, "");
9084
if (getPref(AUTH_TOKEN_KEY) == null && !"".equals(token)) {
9185
store(AUTH_TOKEN_KEY, token);
9286
}
93-
87+
9488
String endpoint = SystemUtils.getEnvironmentVariable(EnvironmentConstants.ENV_SNYK_API, "");
9589
if (getPref(ENDPOINT_KEY) == null && !"".equals(endpoint)) {
9690
store(ENDPOINT_KEY, endpoint);
9791
}
98-
92+
9993
String org = SystemUtils.getEnvironmentVariable(EnvironmentConstants.ENV_SNYK_ORG, "");
10094
if (getPref(ORGANIZATION_KEY) == null && !"".equals(org)) {
10195
store(ORGANIZATION_KEY, org);
10296
}
103-
97+
10498
String cliPath = getDefaultCliPath();
10599
if (getPref(CLI_PATH) == null && !"".equals(cliPath)) {
106100
store(CLI_PATH, cliPath);
107101
}
108-
102+
109103
if (getPref(CLI_BASE_URL) == null || getPref(CLI_BASE_URL).isBlank()) {
110104
store(CLI_BASE_URL, "https://static.snyk.io");
111105
}
112-
106+
113107
if (getPref(SCANNING_MODE_AUTOMATIC) == null) {
114108
store.put(SCANNING_MODE_AUTOMATIC, "true");
115109
}
110+
111+
if (getPref(USE_TOKEN_AUTH) == null) {
112+
store.put(USE_TOKEN_AUTH, "true");
113+
}
116114
}
117115

118116
private String getDefaultCliPath() {
@@ -176,10 +174,10 @@ public IPreferenceStore getStore() {
176174
public boolean getBooleanPref(String key) {
177175
return store.getBoolean(key, false);
178176
}
179-
177+
180178
public boolean getBooleanPref(String key, boolean defaultValue) {
181179
return store.getBoolean(key, defaultValue);
182180
}
183-
181+
184182
}
185183

plugin/src/main/java/io/snyk/eclipse/plugin/runner/ProcessRunner.java

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -125,20 +125,21 @@ private void setupProcessBuilderBase(ProcessBuilder pb) {
125125
}
126126
}
127127

128-
String authMethod = Preferences.getInstance().getPref(Preferences.AUTHENTICATION_METHOD);
129128
String token = Preferences.getInstance().getAuthToken();
130-
if (token != null && !token.isBlank() && authMethod.equals(Preferences.AUTH_METHOD_OAUTH)) {
131-
try {
132-
ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
133-
var oauthToken = objectMapper.readValue(token, OAuthToken.class);
134-
pb.environment().put(EnvironmentConstants.ENV_OAUTH_ACCESS_TOKEN, oauthToken.getAccessToken());
135-
pb.environment().remove(EnvironmentConstants.ENV_SNYK_TOKEN);
136-
} catch (Exception e) {
137-
SnykLogger.logError(e);
129+
if (token != null && !token.isBlank()) {
130+
if (Preferences.getInstance().getBooleanPref(Preferences.USE_TOKEN_AUTH, true)) {
131+
pb.environment().put(EnvironmentConstants.ENV_SNYK_TOKEN, token);
132+
pb.environment().remove(EnvironmentConstants.ENV_OAUTH_ACCESS_TOKEN);
133+
} else {
134+
try {
135+
ObjectMapper objectMapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
136+
var oauthToken = objectMapper.readValue(token, OAuthToken.class);
137+
pb.environment().put(EnvironmentConstants.ENV_OAUTH_ACCESS_TOKEN, oauthToken.getAccessToken());
138+
pb.environment().remove(EnvironmentConstants.ENV_SNYK_TOKEN);
139+
} catch (Exception e) {
140+
SnykLogger.logInfo(token);
141+
}
138142
}
139-
} else {
140-
pb.environment().put(EnvironmentConstants.ENV_SNYK_TOKEN, token);
141-
pb.environment().remove(EnvironmentConstants.ENV_OAUTH_ACCESS_TOKEN);
142143
}
143144

144145
String insecure = Preferences.getInstance().getPref(Preferences.INSECURE_KEY);

plugin/src/main/java/io/snyk/eclipse/plugin/runner/SnykCliRunner.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private ProcessResult snykRun(List<String> arguments, Optional<File> navigatePat
6767
return ProcessResult.error(e.getMessage());
6868
}
6969
}
70-
70+
7171
private void checkIfTrusted(File file) {
7272
var trustedPaths = Preferences.getInstance().getPref(Preferences.TRUSTED_FOLDERS, "");
7373
if (!trustedPaths.contains(file.getAbsolutePath())) {

0 commit comments

Comments
 (0)