Skip to content

Commit 7edaca3

Browse files
authored
Merge pull request #735 from abhik017/master
Added support for SSO login (AWS Profile)
2 parents 647bde0 + cd48527 commit 7edaca3

File tree

12 files changed

+87
-24
lines changed

12 files changed

+87
-24
lines changed

build.gradle.kts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ plugins {
77
}
88

99
group = "com.devoxx.genie"
10-
version = "0.6.8"
10+
version = "0.6.9"
1111

1212
repositories {
1313
mavenCentral()
@@ -69,6 +69,9 @@ dependencies {
6969
implementation("dev.langchain4j:langchain4j-chroma:$lg4j_version")
7070
// implementation("dev.langchain4j:langchain4j-mcp:$lg4j_version")
7171
implementation("dev.langchain4j:langchain4j-reactor:$lg4j_version")
72+
implementation("software.amazon.awssdk:sts:2.25.6")
73+
implementation("software.amazon.awssdk:sso:2.31.64")
74+
implementation("software.amazon.awssdk:ssooidc:2.31.64")
7275

7376
// Retrofit dependencies
7477
implementation("com.squareup.retrofit2:converter-gson:2.11.0")

core/src/main/java/com/devoxx/genie/service/DevoxxGenieSettingsService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ public interface DevoxxGenieSettingsService {
3232

3333
String getAwsAccessKeyId();
3434

35+
String getAwsProfileName();
36+
3537
String getAwsRegion();
3638

3739
String getMistralKey();

src/main/java/com/devoxx/genie/chatmodel/cloud/bedrock/BedrockModelFactory.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
88
import dev.langchain4j.model.bedrock.BedrockChatModel;
99
import dev.langchain4j.model.chat.request.ChatRequestParameters;
10+
import org.apache.http.impl.client.BasicCredentialsProvider;
11+
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
1012
import software.amazon.awssdk.services.bedrockruntime.BedrockRuntimeClient;
1113
import dev.langchain4j.model.chat.ChatLanguageModel;
1214
import org.apache.commons.lang3.NotImplementedException;
@@ -15,6 +17,7 @@
1517
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
1618
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
1719
import software.amazon.awssdk.regions.Region;
20+
import software.amazon.awssdk.services.sts.auth.StsCredentialsProvider;
1821

1922
import java.util.List;
2023

@@ -174,7 +177,11 @@ public List<LanguageModel> getModels() {
174177
String accessKeyId = DevoxxGenieStateService.getInstance().getAwsAccessKeyId();
175178
String secretKey = DevoxxGenieStateService.getInstance().getAwsSecretKey();
176179

177-
return StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKeyId, secretKey));
180+
boolean shouldPowerFromProfile = DevoxxGenieStateService.getInstance().getShouldPowerFromAWSProfile();
181+
String profileName = DevoxxGenieStateService.getInstance().getAwsProfileName();
182+
183+
return shouldPowerFromProfile ? ProfileCredentialsProvider.create(profileName) :
184+
StaticCredentialsProvider.create(AwsBasicCredentials.create(accessKeyId, secretKey));
178185
}
179186

180187
/**

src/main/java/com/devoxx/genie/chatmodel/cloud/bedrock/BedrockService.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
package com.devoxx.genie.chatmodel.cloud.bedrock;
22

33
import com.devoxx.genie.ui.settings.DevoxxGenieStateService;
4+
import com.google.auth.oauth2.AwsCredentials;
45
import com.intellij.openapi.application.ApplicationManager;
56
import org.jetbrains.annotations.NotNull;
67
import software.amazon.awssdk.auth.credentials.AwsBasicCredentials;
8+
import software.amazon.awssdk.auth.credentials.AwsCredentialsProvider;
9+
import software.amazon.awssdk.auth.credentials.AwsSessionCredentials;
10+
import software.amazon.awssdk.auth.credentials.ProfileCredentialsProvider;
711
import software.amazon.awssdk.auth.credentials.StaticCredentialsProvider;
812
import software.amazon.awssdk.regions.Region;
913
import software.amazon.awssdk.services.bedrock.BedrockClient;
@@ -26,9 +30,11 @@ public static BedrockService getInstance() {
2630
String awsAccessKey = instance.getAwsAccessKeyId();
2731
String awsSecretKey = instance.getAwsSecretKey();
2832

29-
// Given
30-
StaticCredentialsProvider credentialsProvider =
31-
StaticCredentialsProvider.create(AwsBasicCredentials.create(awsAccessKey, awsSecretKey));
33+
boolean shouldPowerFromProfile = instance.getShouldPowerFromAWSProfile();
34+
String profileName = instance.getAwsProfileName();
35+
36+
AwsCredentialsProvider credentialsProvider = shouldPowerFromProfile
37+
? ProfileCredentialsProvider.create(profileName) : StaticCredentialsProvider.create(AwsBasicCredentials.create(awsAccessKey, awsSecretKey));
3238

3339
try (BedrockClient bedrockClient = BedrockClient.builder()
3440
.region(Region.of(awsRegion))

src/main/java/com/devoxx/genie/service/DevoxxGenieSettingsService.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public interface DevoxxGenieSettingsService {
3131

3232
String getAwsAccessKeyId();
3333

34+
String getAwsProfileName();
35+
3436
String getAwsRegion();
3537

3638
String getMistralKey();
@@ -114,8 +116,11 @@ public interface DevoxxGenieSettingsService {
114116
void setAzureOpenAIKey(String key);
115117

116118
void setAwsAccessKeyId(String accessKeyId);
119+
117120
void setAwsSecretKey(String secretKey);
118121

122+
void setAwsProfileName(String profileName);
123+
119124
void setAwsRegion(String region);
120125

121126
void setMistralKey(String key);

src/main/java/com/devoxx/genie/ui/settings/DevoxxGenieStateService.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,6 @@ public static DevoxxGenieStateService getInstance() {
110110
private boolean isDeepSeekEnabled = false;
111111
private boolean isOpenRouterEnabled = false;
112112
private boolean isGrokEnabled = false;
113-
private boolean isAWSEnabled = false;
114113

115114
// LLM API Keys
116115
private String openAIKey = "";
@@ -127,6 +126,7 @@ public static DevoxxGenieStateService getInstance() {
127126
private String azureOpenAIKey = "";
128127
private String awsAccessKeyId = "";
129128
private String awsSecretKey = "";
129+
private String awsProfileName = "";
130130
private String awsRegion = "";
131131

132132
// Search API Keys
@@ -171,6 +171,7 @@ public static DevoxxGenieStateService getInstance() {
171171

172172
private Boolean showAzureOpenAIFields = false;
173173
private Boolean showAwsFields = false;
174+
private Boolean shouldPowerFromAWSProfile = false;
174175

175176
@Setter
176177
private Boolean useGitIgnore = true;
@@ -330,9 +331,9 @@ public boolean isAzureOpenAIEnabled() {
330331

331332
public boolean isAwsEnabled() {
332333
return showAwsFields &&
333-
!awsAccessKeyId.isEmpty() &&
334-
!awsSecretKey.isEmpty() &&
335-
!awsRegion.isEmpty();
334+
((!awsAccessKeyId.isEmpty() && !awsSecretKey.isEmpty())
335+
|| (shouldPowerFromAWSProfile && !awsProfileName.isEmpty()))
336+
&& !awsRegion.isEmpty();
336337
}
337338

338339
public @Nullable String getConfigValue(@NotNull String key) {

src/main/java/com/devoxx/genie/ui/settings/llm/LLMProvidersComponent.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,8 @@ public class LLMProvidersComponent extends AbstractSettingsComponent {
6060
@Getter
6161
private final JPasswordField awsSecretKeyField = new JPasswordField(stateService.getAwsSecretKey());
6262
@Getter
63+
private final JTextField awsProfileName = new JTextField(stateService.getAwsProfileName());
64+
@Getter
6365
private final JPasswordField awsAccessKeyIdField = new JPasswordField(stateService.getAwsAccessKeyId());
6466
@Getter
6567
private final JTextField awsRegion = new JTextField(stateService.getAwsRegion());
@@ -105,10 +107,14 @@ public class LLMProvidersComponent extends AbstractSettingsComponent {
105107
private final JCheckBox enableAzureOpenAICheckBox = new JCheckBox("", stateService.getShowAzureOpenAIFields());
106108
@Getter
107109
private final JCheckBox enableAWSCheckBox = new JCheckBox("", stateService.getShowAwsFields());
110+
@Getter
111+
private final JCheckBox enableAWSProfileCheckBox = new JCheckBox("", stateService.getShouldPowerFromAWSProfile());
108112

109113
private final List<JComponent> azureComponents = new ArrayList<>();
110114

111-
private final List<JComponent> awsComponents = new ArrayList<>();
115+
private final List<JComponent> awsCommonComponents = new ArrayList<>();
116+
private final List<JComponent> awsDirectCredentialsComponents = new ArrayList<>();
117+
private final List<JComponent> awsProfileCredentialsComponents = new ArrayList<>();
112118

113119
public LLMProvidersComponent() {
114120
addListeners();
@@ -189,7 +195,13 @@ public void addListeners() {
189195
setNestedComponentsVisibility(azureComponents, event.getStateChange() == ItemEvent.SELECTED, true);
190196
});
191197
enableAWSCheckBox.addItemListener(event -> {
192-
setNestedComponentsVisibility(awsComponents, event.getStateChange() == ItemEvent.SELECTED, true);
198+
setNestedComponentsVisibility(awsCommonComponents, event.getStateChange() == ItemEvent.SELECTED, true);
199+
setNestedComponentsVisibility(awsDirectCredentialsComponents, event.getStateChange() == ItemEvent.SELECTED && !enableAWSProfileCheckBox.isSelected(), true);
200+
setNestedComponentsVisibility(awsProfileCredentialsComponents, event.getStateChange() == ItemEvent.SELECTED && enableAWSProfileCheckBox.isSelected(), true);
201+
});
202+
enableAWSProfileCheckBox.addItemListener(event -> {
203+
setNestedComponentsVisibility(awsDirectCredentialsComponents, enableAWSCheckBox.isSelected() && event.getStateChange() != ItemEvent.SELECTED, true);
204+
setNestedComponentsVisibility(awsProfileCredentialsComponents, enableAWSCheckBox.isSelected() && event.getStateChange() == ItemEvent.SELECTED, true);
193205
});
194206

195207
// Add new listeners for enable/disable checkboxes
@@ -232,17 +244,22 @@ private void addAzureOpenAIPanel(JPanel panel, GridBagConstraints gbc) {
232244

233245
private void addAWSPanel(JPanel panel, GridBagConstraints gbc) {
234246
final String bedrockURL = "https://docs.aws.amazon.com/bedrock/latest/userguide/getting-started-api.html";
247+
final String awsProfileURL = "https://docs.aws.amazon.com/cli/v1/userguide/cli-configure-files.html";
235248
addSettingRow(panel, gbc, "Enable AWS Bedrock", enableAWSCheckBox);
236249

237-
addNestedSettingsRow(panel, gbc, "AWS Access Key ID",
238-
createTextWithLinkButton(awsAccessKeyIdField, bedrockURL), awsComponents);
239-
addNestedSettingsRow(panel, gbc, "AWS Secret Access Key",
240-
createTextWithLinkButton(awsSecretKeyField, bedrockURL), awsComponents);
241-
addNestedSettingsRow(panel, gbc, "AWS region",
242-
createTextWithPasswordButton(awsRegion, bedrockURL), awsComponents);
250+
addNestedSettingsRow(panel, gbc, "Power from AWS Profile", enableAWSProfileCheckBox, awsCommonComponents);
251+
addNestedSettingsRow(panel, gbc, "AWS region", createTextWithPasswordButton(awsRegion, bedrockURL), awsCommonComponents);
252+
253+
addNestedSettingsRow(panel, gbc, "AWS Access Key ID", createTextWithLinkButton(awsAccessKeyIdField, bedrockURL), awsDirectCredentialsComponents);
254+
addNestedSettingsRow(panel, gbc, "AWS Secret Access Key", createTextWithLinkButton(awsSecretKeyField, bedrockURL), awsDirectCredentialsComponents);
255+
256+
addNestedSettingsRow(panel, gbc, "AWS Profile Name", createTextWithLinkButton(awsProfileName, awsProfileURL), awsProfileCredentialsComponents);
257+
243258

244259
// Set initial visibility
245-
setNestedComponentsVisibility(awsComponents, enableAWSCheckBox.isSelected(), false);
260+
setNestedComponentsVisibility(awsCommonComponents, enableAWSCheckBox.isSelected(), false);
261+
setNestedComponentsVisibility(awsDirectCredentialsComponents, enableAWSCheckBox.isSelected() && !enableAWSProfileCheckBox.isSelected(), false);
262+
setNestedComponentsVisibility(awsProfileCredentialsComponents, enableAWSCheckBox.isSelected() && enableAWSProfileCheckBox.isSelected(), false);
246263
}
247264

248265
/**

src/main/java/com/devoxx/genie/ui/settings/llm/LLMProvidersConfigurable.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ public boolean isModified() {
8585
isModified |= !stateService.getShowAwsFields().equals(llmSettingsComponent.getEnableAWSCheckBox().isSelected());
8686
isModified |= isFieldModified(llmSettingsComponent.getAwsSecretKeyField(), stateService.getAwsSecretKey());
8787
isModified |= isFieldModified(llmSettingsComponent.getAwsAccessKeyIdField(), stateService.getAwsAccessKeyId());
88+
isModified |= !stateService.getShouldPowerFromAWSProfile().equals(llmSettingsComponent.getEnableAWSProfileCheckBox().isSelected());
89+
isModified |= isFieldModified(llmSettingsComponent.getAwsProfileName(), stateService.getAwsProfileName());
8890
isModified |= isFieldModified(llmSettingsComponent.getAwsRegion(), stateService.getAwsRegion());
8991

9092
isModified |= stateService.isOllamaEnabled() != llmSettingsComponent.getOllamaEnabledCheckBox().isSelected();
@@ -153,6 +155,8 @@ public void apply() {
153155
settings.setAwsAccessKeyId(new String(llmSettingsComponent.getAwsAccessKeyIdField().getPassword()));
154156
settings.setAwsSecretKey(new String(llmSettingsComponent.getAwsSecretKeyField().getPassword()));
155157
settings.setAwsRegion(llmSettingsComponent.getAwsRegion().getText());
158+
settings.setShouldPowerFromAWSProfile(llmSettingsComponent.getEnableAWSProfileCheckBox().isSelected());
159+
settings.setAwsProfileName(llmSettingsComponent.getAwsProfileName().getText());
156160

157161
settings.setOllamaEnabled(llmSettingsComponent.getOllamaEnabledCheckBox().isSelected());
158162
settings.setLmStudioEnabled(llmSettingsComponent.getLmStudioEnabledCheckBox().isSelected());
@@ -188,6 +192,7 @@ public void apply() {
188192
(!settings.getMistralKey().isBlank() && settings.isMistralEnabled()) ||
189193
(!settings.getAwsAccessKeyId().isBlank() && !settings.getAwsSecretKey().isBlank() && settings.isAwsEnabled()) ||
190194
(!settings.getAwsAccessKeyId().isBlank() && settings.getShowAwsFields()) ||
195+
(!settings.getAwsProfileName().isBlank() && settings.getShowAwsFields() && settings.getShouldPowerFromAWSProfile()) ||
191196
(!settings.getAwsRegion().isBlank() && settings.getShowAwsFields()) ||
192197
(!settings.getAzureOpenAIKey().isBlank() && settings.getShowAzureOpenAIFields());
193198

src/main/resources/META-INF/plugin.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
]]></description>
3636

3737
<change-notes><![CDATA[
38-
<h2>v0.6.8</h2>
38+
<h2>v0.6.9</h2>
3939
<UL>
4040
<LI>Issue #725: Langchain4J MCP ToolSpecificationHelper fix</LI>
4141
</UL>
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
version=0.6.8
1+
version=0.6.9

0 commit comments

Comments
 (0)