mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Github: IDEA-111654 IDEA-111653 Remove login field for token authentication
This commit is contained in:
@@ -71,7 +71,7 @@ public class GithubCreatePullRequestAction extends DumbAwareAction {
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringUtil.isEmptyOrSpaces(GithubSettings.getInstance().getLogin())) {
|
||||
if (!GithubSettings.getInstance().isAuthConfigured()) {
|
||||
setVisibleEnabled(e, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,7 +23,6 @@ import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.Task;
|
||||
import com.intellij.openapi.project.DumbAwareAction;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ThrowableConvertor;
|
||||
@@ -42,7 +41,9 @@ import git4idea.util.GitPreservingProcess;
|
||||
import icons.GithubIcons;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.github.api.*;
|
||||
import org.jetbrains.plugins.github.api.GithubApiUtil;
|
||||
import org.jetbrains.plugins.github.api.GithubFullPath;
|
||||
import org.jetbrains.plugins.github.api.GithubRepoDetailed;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Collections;
|
||||
@@ -71,7 +72,7 @@ public class GithubRebaseAction extends DumbAwareAction {
|
||||
return;
|
||||
}
|
||||
|
||||
if (StringUtil.isEmptyOrSpaces(GithubSettings.getInstance().getLogin())) {
|
||||
if (!GithubSettings.getInstance().isAuthConfigured()) {
|
||||
setVisibleEnabled(e, false, false);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -23,9 +23,11 @@ import com.intellij.openapi.components.*;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.github.api.GithubApiUtil;
|
||||
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
||||
import static org.jetbrains.plugins.github.GithubAuthData.AuthType;
|
||||
|
||||
@@ -52,15 +54,15 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
}
|
||||
|
||||
public static class State {
|
||||
public String LOGIN = "";
|
||||
public String HOST = GithubApiUtil.DEFAULT_GITHUB_HOST;
|
||||
public AuthType AUTH_TYPE = AuthType.ANONYMOUS;
|
||||
@Nullable public String LOGIN = null;
|
||||
@NotNull public String HOST = GithubApiUtil.DEFAULT_GITHUB_HOST;
|
||||
@NotNull public AuthType AUTH_TYPE = AuthType.ANONYMOUS;
|
||||
public boolean ANONYMOUS_GIST = false;
|
||||
public boolean OPEN_IN_BROWSER_GIST = true;
|
||||
public boolean PRIVATE_GIST = true;
|
||||
public boolean SAVE_PASSWORD = true;
|
||||
public Collection<String> TRUSTED_HOSTS = new ArrayList<String>();
|
||||
public String CREATE_PULL_REQUEST_DEFAULT_BRANCH = "";
|
||||
@NotNull public Collection<String> TRUSTED_HOSTS = new ArrayList<String>();
|
||||
@NotNull public String CREATE_PULL_REQUEST_DEFAULT_BRANCH = "";
|
||||
}
|
||||
|
||||
public static GithubSettings getInstance() {
|
||||
@@ -72,8 +74,7 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
return myState.HOST;
|
||||
}
|
||||
|
||||
// TODO return null if no login instead of empty string
|
||||
@NotNull
|
||||
@Nullable
|
||||
public String getLogin() {
|
||||
return StringUtil.notNullize(myState.LOGIN);
|
||||
}
|
||||
@@ -83,11 +84,15 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
return myState.AUTH_TYPE;
|
||||
}
|
||||
|
||||
public boolean isAuthConfigured() {
|
||||
return !myState.AUTH_TYPE.equals(AuthType.ANONYMOUS);
|
||||
}
|
||||
|
||||
private void setHost(@NotNull String host) {
|
||||
myState.HOST = StringUtil.notNullize(host, GithubApiUtil.DEFAULT_GITHUB_HOST);
|
||||
}
|
||||
|
||||
private void setLogin(@NotNull String login) {
|
||||
private void setLogin(@Nullable String login) {
|
||||
myState.LOGIN = login;
|
||||
}
|
||||
|
||||
@@ -203,13 +208,16 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
switch (auth.getAuthType()) {
|
||||
case BASIC:
|
||||
assert auth.getBasicAuth() != null;
|
||||
setLogin(auth.getBasicAuth().getLogin());
|
||||
setPassword(auth.getBasicAuth().getPassword(), rememberPassword);
|
||||
break;
|
||||
case TOKEN:
|
||||
assert auth.getTokenAuth() != null;
|
||||
setLogin(null);
|
||||
setPassword(auth.getTokenAuth().getToken(), rememberPassword);
|
||||
break;
|
||||
case ANONYMOUS:
|
||||
setLogin(null);
|
||||
setPassword("", rememberPassword);
|
||||
break;
|
||||
default:
|
||||
@@ -217,9 +225,8 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
|
||||
}
|
||||
}
|
||||
|
||||
public void setCredentials(@NotNull String host, @NotNull String login, @NotNull GithubAuthData auth, boolean rememberPassword) {
|
||||
public void setCredentials(@NotNull String host, @NotNull GithubAuthData auth, boolean rememberPassword) {
|
||||
setHost(host);
|
||||
setLogin(login);
|
||||
setAuthData(auth, rememberPassword);
|
||||
}
|
||||
}
|
||||
@@ -34,8 +34,7 @@ public class GithubBasicLoginDialog extends GithubLoginDialog {
|
||||
protected void saveCredentials(GithubAuthData auth) {
|
||||
final GithubSettings settings = GithubSettings.getInstance();
|
||||
if (settings.getAuthType() != GithubAuthData.AuthType.TOKEN) {
|
||||
settings
|
||||
.setCredentials(myGithubLoginPanel.getHost(), myGithubLoginPanel.getLogin(), auth, myGithubLoginPanel.isSavePasswordSelected());
|
||||
settings.setCredentials(myGithubLoginPanel.getHost(), auth, myGithubLoginPanel.isSavePasswordSelected());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,6 @@ import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.github.GithubAuthData;
|
||||
import org.jetbrains.plugins.github.GithubSettings;
|
||||
import org.jetbrains.plugins.github.GithubUtil;
|
||||
import org.jetbrains.plugins.github.api.GithubUserDetailed;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.IOException;
|
||||
@@ -69,12 +68,7 @@ public class GithubLoginDialog extends DialogWrapper {
|
||||
protected void doOKAction() {
|
||||
final GithubAuthData auth = myGithubLoginPanel.getAuthData();
|
||||
try {
|
||||
GithubUserDetailed user = GithubUtil.checkAuthData(auth);
|
||||
if (!myGithubLoginPanel.getLogin().equalsIgnoreCase(user.getLogin())) {
|
||||
myGithubLoginPanel.setLogin(user.getLogin());
|
||||
setErrorText("Login doesn't match credentials. Fixed");
|
||||
return;
|
||||
}
|
||||
GithubUtil.checkAuthData(auth);
|
||||
|
||||
saveCredentials(auth);
|
||||
if (mySettings.isSavePasswordMakesSense()) {
|
||||
@@ -90,7 +84,7 @@ public class GithubLoginDialog extends DialogWrapper {
|
||||
|
||||
protected void saveCredentials(GithubAuthData auth) {
|
||||
final GithubSettings settings = GithubSettings.getInstance();
|
||||
settings.setCredentials(myGithubLoginPanel.getHost(), myGithubLoginPanel.getLogin(), auth, myGithubLoginPanel.isSavePasswordSelected());
|
||||
settings.setCredentials(myGithubLoginPanel.getHost(), auth, myGithubLoginPanel.isSavePasswordSelected());
|
||||
}
|
||||
|
||||
public void clearErrors() {
|
||||
|
||||
@@ -3,29 +3,13 @@
|
||||
<grid id="27dc6" binding="myPane" layout-manager="GridLayoutManager" row-count="6" column-count="3" same-size-horizontally="false" same-size-vertically="false" hgap="-1" vgap="-1">
|
||||
<margin top="0" left="0" bottom="0" right="0"/>
|
||||
<constraints>
|
||||
<xy x="20" y="20" width="500" height="168"/>
|
||||
<xy x="20" y="20" width="500" height="174"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<focusable value="false"/>
|
||||
</properties>
|
||||
<border type="none"/>
|
||||
<children>
|
||||
<component id="e76ec" class="javax.swing.JTextField" binding="myLoginTextField">
|
||||
<constraints>
|
||||
<grid row="1" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c0234" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="1" 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="Login:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="28ddd" class="javax.swing.JTextPane" binding="mySignupTextField">
|
||||
<constraints>
|
||||
<grid row="4" column="0" row-span="1" col-span="3" vsize-policy="0" hsize-policy="6" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
|
||||
@@ -71,7 +55,7 @@
|
||||
</component>
|
||||
<component id="f851a" class="javax.swing.JComboBox" binding="myAuthTypeComboBox">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
<grid row="1" column="1" row-span="1" col-span="1" vsize-policy="0" hsize-policy="7" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
|
||||
</constraints>
|
||||
<properties>
|
||||
<model/>
|
||||
@@ -80,7 +64,7 @@
|
||||
</component>
|
||||
<component id="b466f" class="javax.swing.JCheckBox" binding="mySavePasswordCheckBox">
|
||||
<constraints>
|
||||
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<grid row="1" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="0" anchor="8" fill="0" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="120" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
@@ -91,7 +75,7 @@
|
||||
</component>
|
||||
<component id="325bb" class="javax.swing.JLabel">
|
||||
<constraints>
|
||||
<grid row="2" 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="1" 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="Auth type:"/>
|
||||
@@ -105,6 +89,22 @@
|
||||
<text value="Password:"/>
|
||||
</properties>
|
||||
</component>
|
||||
<component id="e76ec" class="javax.swing.JTextField" binding="myLoginTextField">
|
||||
<constraints>
|
||||
<grid row="2" column="1" row-span="1" col-span="2" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false">
|
||||
<preferred-size width="150" height="-1"/>
|
||||
</grid>
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c0234" class="javax.swing.JLabel" binding="myLoginLabel">
|
||||
<constraints>
|
||||
<grid row="2" 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="Login:"/>
|
||||
</properties>
|
||||
</component>
|
||||
</children>
|
||||
</grid>
|
||||
</form>
|
||||
|
||||
@@ -21,6 +21,7 @@ import com.intellij.ui.HyperlinkAdapter;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import com.intellij.util.ui.table.ComponentsListFocusTraversalPolicy;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.github.GithubAuthData;
|
||||
import org.jetbrains.plugins.github.GithubUtil;
|
||||
|
||||
@@ -47,6 +48,7 @@ public class GithubLoginPanel {
|
||||
private JCheckBox mySavePasswordCheckBox;
|
||||
private JComboBox myAuthTypeComboBox;
|
||||
private JLabel myPasswordLabel;
|
||||
private JLabel myLoginLabel;
|
||||
|
||||
private final static String AUTH_PASSWORD = "Password";
|
||||
private final static String AUTH_TOKEN = "Token";
|
||||
@@ -79,8 +81,21 @@ public class GithubLoginPanel {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
String item = e.getItem().toString();
|
||||
myPasswordLabel.setText(item + ":");
|
||||
mySavePasswordCheckBox.setText("Save " + item.toLowerCase());
|
||||
if (AUTH_PASSWORD.equals(item)) {
|
||||
myPasswordLabel.setText("Password:");
|
||||
mySavePasswordCheckBox.setText("Save password");
|
||||
myLoginLabel.setVisible(true);
|
||||
myLoginTextField.setVisible(true);
|
||||
}
|
||||
if (AUTH_TOKEN.equals(item)) {
|
||||
myPasswordLabel.setText("Token:");
|
||||
mySavePasswordCheckBox.setText("Save token");
|
||||
myLoginLabel.setVisible(false);
|
||||
myLoginTextField.setVisible(false);
|
||||
}
|
||||
if (dialog.isShowing()) {
|
||||
dialog.pack();
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -103,7 +118,7 @@ public class GithubLoginPanel {
|
||||
myHostTextField.setText(host);
|
||||
}
|
||||
|
||||
public void setLogin(@NotNull String login) {
|
||||
public void setLogin(@Nullable String login) {
|
||||
myLoginTextField.setText(login);
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,7 @@ public class GithubSettingsConfigurable implements SearchableConfigurable, VcsCo
|
||||
|
||||
public void apply() throws ConfigurationException {
|
||||
if (mySettingsPane != null) {
|
||||
mySettings.setCredentials(mySettingsPane.getHost(), mySettingsPane.getLogin(), mySettingsPane.getAuthData(), true);
|
||||
mySettings.setCredentials(mySettingsPane.getHost(), mySettingsPane.getAuthData(), true);
|
||||
mySettingsPane.resetCredentialsModification();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
</constraints>
|
||||
<properties/>
|
||||
</component>
|
||||
<component id="c0234" class="javax.swing.JLabel">
|
||||
<component id="c0234" class="javax.swing.JLabel" binding="myLoginLabel">
|
||||
<constraints>
|
||||
<grid row="1" 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>
|
||||
|
||||
@@ -22,8 +22,11 @@ import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.ui.HyperlinkAdapter;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.plugins.github.*;
|
||||
import org.jetbrains.plugins.github.api.GithubUserDetailed;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.plugins.github.GithubAuthData;
|
||||
import org.jetbrains.plugins.github.GithubAuthenticationException;
|
||||
import org.jetbrains.plugins.github.GithubSettings;
|
||||
import org.jetbrains.plugins.github.GithubUtil;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.DocumentEvent;
|
||||
@@ -53,6 +56,7 @@ public class GithubSettingsPanel {
|
||||
private JButton myTestButton;
|
||||
private JTextField myHostTextField;
|
||||
private JComboBox myAuthTypeComboBox;
|
||||
private JLabel myLoginLabel;
|
||||
|
||||
private boolean myCredentialsModified;
|
||||
|
||||
@@ -71,18 +75,11 @@ public class GithubSettingsPanel {
|
||||
myAuthTypeComboBox.addItem(AUTH_PASSWORD);
|
||||
myAuthTypeComboBox.addItem(AUTH_TOKEN);
|
||||
|
||||
reset();
|
||||
|
||||
myTestButton.addActionListener(new ActionListener() {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
try {
|
||||
GithubUserDetailed user = GithubUtil.checkAuthData(getAuthData());
|
||||
if (!getLogin().equalsIgnoreCase(user.getLogin())) {
|
||||
setLogin(user.getLogin());
|
||||
Messages.showInfoMessage(myPane, "Login doesn't match credentials. Fixed", "Success");
|
||||
return;
|
||||
}
|
||||
GithubUtil.checkAuthData(getAuthData());
|
||||
Messages.showInfoMessage(myPane, "Connection successful", "Success");
|
||||
}
|
||||
catch (GithubAuthenticationException ex) {
|
||||
@@ -116,24 +113,21 @@ public class GithubSettingsPanel {
|
||||
@Override
|
||||
public void insertUpdate(DocumentEvent e) {
|
||||
if (!myCredentialsModified) {
|
||||
setPassword("");
|
||||
myCredentialsModified = true;
|
||||
erasePassword();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeUpdate(DocumentEvent e) {
|
||||
if (!myCredentialsModified) {
|
||||
setPassword("");
|
||||
myCredentialsModified = true;
|
||||
erasePassword();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void changedUpdate(DocumentEvent e) {
|
||||
if (!myCredentialsModified) {
|
||||
setPassword("");
|
||||
myCredentialsModified = true;
|
||||
erasePassword();
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -145,8 +139,7 @@ public class GithubSettingsPanel {
|
||||
@Override
|
||||
public void focusGained(FocusEvent e) {
|
||||
if (!myCredentialsModified && !getPassword().isEmpty()) {
|
||||
setPassword("");
|
||||
myCredentialsModified = true;
|
||||
erasePassword();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,10 +151,28 @@ public class GithubSettingsPanel {
|
||||
myAuthTypeComboBox.addItemListener(new ItemListener() {
|
||||
@Override
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
setPassword("");
|
||||
myCredentialsModified = true;
|
||||
if (e.getStateChange() == ItemEvent.SELECTED) {
|
||||
String item = e.getItem().toString();
|
||||
if (AUTH_PASSWORD.equals(item)) {
|
||||
myLoginLabel.setVisible(true);
|
||||
myLoginTextField.setVisible(true);
|
||||
}
|
||||
if (AUTH_TOKEN.equals(item)) {
|
||||
myLoginLabel.setVisible(false);
|
||||
myLoginTextField.setVisible(false);
|
||||
}
|
||||
myPane.validate();
|
||||
erasePassword();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
reset();
|
||||
}
|
||||
|
||||
private void erasePassword() {
|
||||
setPassword("");
|
||||
myCredentialsModified = true;
|
||||
}
|
||||
|
||||
public JComponent getPanel() {
|
||||
@@ -182,7 +193,7 @@ public class GithubSettingsPanel {
|
||||
myHostTextField.setText(host);
|
||||
}
|
||||
|
||||
public void setLogin(@NotNull final String login) {
|
||||
public void setLogin(@Nullable final String login) {
|
||||
myLoginTextField.setText(login);
|
||||
}
|
||||
|
||||
@@ -232,18 +243,15 @@ public class GithubSettingsPanel {
|
||||
}
|
||||
|
||||
public void reset() {
|
||||
String login = mySettings.getLogin();
|
||||
setHost(mySettings.getHost());
|
||||
setLogin(login);
|
||||
setPassword(login.isEmpty() ? "" : DEFAULT_PASSWORD_TEXT);
|
||||
setLogin(mySettings.getLogin());
|
||||
setPassword(mySettings.isAuthConfigured() ? DEFAULT_PASSWORD_TEXT : "");
|
||||
setAuthType(mySettings.getAuthType());
|
||||
resetCredentialsModification();
|
||||
}
|
||||
|
||||
public boolean isModified() {
|
||||
return !Comparing.equal(mySettings.getHost(), getHost()) ||
|
||||
!Comparing.equal(mySettings.getLogin(), getLogin()) ||
|
||||
myCredentialsModified;
|
||||
return !Comparing.equal(mySettings.getHost(), getHost()) || myCredentialsModified;
|
||||
}
|
||||
|
||||
public void resetCredentialsModification() {
|
||||
|
||||
@@ -173,7 +173,7 @@ public abstract class GithubTest extends UsefulTestCase {
|
||||
myAuth = GithubAuthData.createBasicAuth(host, login1, password);
|
||||
|
||||
myGitHubSettings = GithubSettings.getInstance();
|
||||
myGitHubSettings.setCredentials(myHost, myLogin1, myAuth, false);
|
||||
myGitHubSettings.setCredentials(myHost, myAuth, false);
|
||||
|
||||
myDialogManager = (TestDialogManager)ServiceManager.getService(DialogManager.class);
|
||||
myNotificator = (TestNotificator)ServiceManager.getService(myProject, Notificator.class);
|
||||
|
||||
Reference in New Issue
Block a user