Skip to content

Commit

Permalink
Introducing Verification Code for SSO Login (#450)
Browse files Browse the repository at this point in the history
Verification code added to SSO login process.
  • Loading branch information
noyshabtay authored Dec 11, 2023
1 parent b7c63da commit 6acdbbb
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
</properties>
<border type="none"/>
<children>
<grid id="b0c38" binding="connectionDetails" layout-manager="GridLayoutManager" row-count="15" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<grid id="b0c38" binding="connectionDetails" layout-manager="GridLayoutManager" row-count="17" column-count="4" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
<margin top="0" left="0" bottom="0" right="0"/>
<constraints>
<tabbedpane title="Connection Details"/>
Expand Down Expand Up @@ -126,7 +126,7 @@
</grid>
<component id="27f28" class="javax.swing.JButton" binding="loginButton">
<constraints>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="6" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<horizontalTextPosition value="10"/>
Expand All @@ -135,94 +135,94 @@
</component>
<component id="a71b8" class="javax.swing.JLabel" binding="authenticationMethodTitle">
<constraints>
<grid row="7" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Authentication method"/>
</properties>
</component>
<component id="6f374" class="javax.swing.JRadioButton" binding="usernamePasswordRadioButton" default-binding="true">
<constraints>
<grid row="7" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="9" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Username and password"/>
</properties>
</component>
<component id="aff26" class="javax.swing.JRadioButton" binding="accessTokenRadioButton" default-binding="true">
<constraints>
<grid row="7" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="9" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Access token"/>
</properties>
</component>
<component id="a8f26" class="javax.swing.JLabel" binding="usernameTitle">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Username"/>
</properties>
</component>
<component id="d208" class="com.intellij.ui.components.JBTextField" binding="username">
<constraints>
<grid row="8" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="10" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="59d39" class="javax.swing.JLabel" binding="passwordTitle">
<constraints>
<grid row="9" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Password"/>
</properties>
</component>
<component id="38b32" class="com.intellij.ui.components.JBPasswordField" binding="password">
<constraints>
<grid row="9" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="11" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="0" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="92e18" class="javax.swing.JLabel" binding="accessTokenTitle">
<constraints>
<grid row="10" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
<grid row="12" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Access token"/>
</properties>
</component>
<component id="89090" class="com.intellij.ui.components.JBPasswordField" binding="accessToken" default-binding="true">
<constraints>
<grid row="10" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
<grid row="12" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<vspacer id="d7093">
<constraints>
<grid row="11" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
<grid row="13" column="0" row-span="1" col-span="1" vsize-policy="6" hsize-policy="1" anchor="0" fill="2" indent="0" use-parent-layout="false"/>
</constraints>
</vspacer>
<component id="b81b8" class="com.intellij.ui.TitledSeparator">
<constraints>
<grid row="12" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="14" column="0" row-span="1" col-span="4" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Connection Testing"/>
</properties>
</component>
<component id="62866" class="javax.swing.JButton" binding="testConnectionButton" default-binding="true">
<constraints>
<grid row="13" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="15" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="Test connection"/>
</properties>
</component>
<component id="344ac" class="com.intellij.ui.components.JBLabel" binding="connectionResults">
<constraints>
<grid row="13" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<grid row="15" column="1" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<enabled value="true"/>
Expand All @@ -246,10 +246,28 @@
</component>
<component id="5d973" class="com.intellij.ui.HyperlinkLabel" binding="infoPanel">
<constraints>
<grid row="14" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
<grid row="16" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="9" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
<component id="a319e" class="com.intellij.ui.components.JBTextArea" binding="ssoCode">
<constraints>
<grid row="8" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<editable value="false"/>
<font name="JetBrains Mono" size="28" style="1"/>
<text value="SSOC"/>
</properties>
</component>
<component id="88875" class="com.intellij.ui.components.JBLabel" binding="ssoLoginInstructionsLabel">
<constraints>
<grid row="7" column="0" row-span="1" col-span="2" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="SSO login instructions"/>
</properties>
</component>
</children>
</grid>
<grid id="eca9a" binding="settings" layout-manager="GridLayoutManager" row-count="16" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ public class JFrogGlobalConfiguration implements Configurable, Configurable.NoSc
private JLabel repositoryNameDescJLabel;
private JBLabel pluginResourcesDescJBLabel;
private JBLabel releasesRepoLinkJBLabel;
private JBLabel ssoLoginInstructionsLabel;
private JBTextArea ssoCode;

private int selectedTabIndex;

Expand Down Expand Up @@ -206,9 +208,10 @@ public void reset() {
private void initEnabledComponentSets() {
allUiComponents = Sets.newHashSet(infoPanel, platformUrlTitle, platformUrl, xrayUrlTitle, xrayUrl,
artifactoryUrlTitle, artifactoryUrl, username, password, accessTokenTitle, accessToken, accessTokenRadioButton, usernamePasswordRadioButton,
loginButton, authenticationMethodTitle, usernameTitle, passwordTitle, advancedExpandButton, setSeparately, advancedExpandButton);
loginButton, authenticationMethodTitle, usernameTitle, passwordTitle, advancedExpandButton, setSeparately, advancedExpandButton,
ssoLoginInstructionsLabel, ssoCode);

webLoginEnabledComponents = webLoginVisibleComponents = Sets.newHashSet(infoPanel, platformUrlTitle, platformUrl, loginButton);
webLoginEnabledComponents = webLoginVisibleComponents = Sets.newHashSet(infoPanel, platformUrlTitle, platformUrl, loginButton, ssoLoginInstructionsLabel, ssoCode);

connectionDetailsEnabledComponents = connectionDetailsVisibleComponents = Sets.newHashSet(infoPanel, platformUrlTitle, platformUrl,
authenticationMethodTitle, usernamePasswordRadioButton, accessTokenRadioButton, usernameTitle, username,
Expand Down Expand Up @@ -471,6 +474,8 @@ private void initAdvancedExpandButton() {
* Init the "Login" button that do the SSO login.
*/
private void initLoginViaBrowserButton() {
ssoCode.setText("");
ssoLoginInstructionsLabel.setText("");
loginButton.setIcon(AllIcons.Ide.External_link_arrow);
loginButton.addActionListener(e -> ApplicationManager.getApplication().executeOnPooledThread(() -> {
if (isBlank(platformUrl.getText())) {
Expand All @@ -486,6 +491,9 @@ private void initLoginViaBrowserButton() {
*/
private void doSsoLogin() {
String uuid = UUID.randomUUID().toString();
String code = uuid.substring(uuid.length() - 4);
ssoCode.setText(code);
ssoLoginInstructionsLabel.setText("After logging in via your web browser, please enter the code if prompted: ");

AsyncProcessIcon asyncProcessIcon = new AsyncProcessIcon("Connecting...");
clearText(artifactoryUrl, xrayUrl, accessToken, username, password);
Expand All @@ -503,9 +511,10 @@ private void doSsoLogin() {
SSLContextBuilder.create().loadTrustMaterial(TrustAllStrategy.INSTANCE).build() :
serverConfig.getSslContext());

Thread.sleep(SSO_WAIT_BETWEEN_RETRIES_MILLIS);
accessManager.sendBrowserLoginRequest(uuid);
BrowserUtil.browse(removeEnd(platformUrl.getText(), "/") + "/ui/login?jfClientSession=" + uuid +
"&jfClientName=IDEA");
"&jfClientName=IDEA&jfClientCode=1");

for (int i = 0; i < SSO_RETRIES; i++) {
CreateAccessTokenResponse response = accessManager.getBrowserLoginRequestToken(uuid);
Expand All @@ -527,6 +536,8 @@ private void doSsoLogin() {
loginButton.setText("Login");
loginButton.setIcon(AllIcons.Ide.External_link_arrow);
loginButton.setEnabled(true);
ssoCode.setText("");
ssoLoginInstructionsLabel.setText("");
}
}

Expand Down

0 comments on commit 6acdbbb

Please sign in to comment.