Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
小 白蛋
Intellij Community
Commits
851666f8
Commit
851666f8
authored
7 years ago
by
Ivan Semenov
Browse files
Options
Download
Email Patches
Plain Diff
[github] Migrate to new auth, deprecate/remove old one
parent
bcb0533a
Changes
15
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
plugins/github/src/META-INF/plugin.xml
+1
-0
plugins/github/src/META-INF/plugin.xml
plugins/github/src/org/jetbrains/plugins/github/api/GithubConnection.java
+0
-5
...rc/org/jetbrains/plugins/github/api/GithubConnection.java
plugins/github/src/org/jetbrains/plugins/github/ui/GithubCredentialsPanel.form
+0
-174
...g/jetbrains/plugins/github/ui/GithubCredentialsPanel.form
plugins/github/src/org/jetbrains/plugins/github/ui/GithubCredentialsPanel.java
+0
-249
...g/jetbrains/plugins/github/ui/GithubCredentialsPanel.java
plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java
+0
-120
...rc/org/jetbrains/plugins/github/ui/GithubLoginDialog.java
plugins/github/src/org/jetbrains/plugins/github/util/AuthLevel.java
+4
-0
...thub/src/org/jetbrains/plugins/github/util/AuthLevel.java
plugins/github/src/org/jetbrains/plugins/github/util/GithubAccountsMigrationHelper.kt
+76
-0
...ains/plugins/github/util/GithubAccountsMigrationHelper.kt
plugins/github/src/org/jetbrains/plugins/github/util/GithubAuthData.java
+2
-5
...src/org/jetbrains/plugins/github/util/GithubAuthData.java
plugins/github/src/org/jetbrains/plugins/github/util/GithubAuthDataHolder.java
+4
-15
...g/jetbrains/plugins/github/util/GithubAuthDataHolder.java
plugins/github/src/org/jetbrains/plugins/github/util/GithubSettings.java
+47
-118
...src/org/jetbrains/plugins/github/util/GithubSettings.java
plugins/github/src/org/jetbrains/plugins/github/util/GithubUrlUtil.java
+28
-105
.../src/org/jetbrains/plugins/github/util/GithubUrlUtil.java
plugins/github/src/org/jetbrains/plugins/github/util/GithubUtil.kt
+143
-391
...ithub/src/org/jetbrains/plugins/github/util/GithubUtil.kt
plugins/github/test/org/jetbrains/plugins/github/GithubCreateGistTestBase.java
+0
-13
...rg/jetbrains/plugins/github/GithubCreateGistTestBase.java
plugins/github/test/org/jetbrains/plugins/github/GithubUrlUtilTest.java
+0
-46
.../test/org/jetbrains/plugins/github/GithubUrlUtilTest.java
plugins/github/test/org/jetbrains/plugins/github/test/GithubTest.java
+7
-29
...ub/test/org/jetbrains/plugins/github/test/GithubTest.java
with
312 additions
and
1270 deletions
+312
-1270
plugins/github/src/META-INF/plugin.xml
+
1
-
0
View file @
851666f8
...
@@ -31,6 +31,7 @@
...
@@ -31,6 +31,7 @@
<projectService
serviceImplementation=
"org.jetbrains.plugins.github.authentication.accounts.GithubProjectDefaultAccountHolder"
/>
<projectService
serviceImplementation=
"org.jetbrains.plugins.github.authentication.accounts.GithubProjectDefaultAccountHolder"
/>
<vcsAnnotationGutterActionProvider
implementation=
"org.jetbrains.plugins.github.extensions.GithubAnnotationGutterActionProvider"
/>
<vcsAnnotationGutterActionProvider
implementation=
"org.jetbrains.plugins.github.extensions.GithubAnnotationGutterActionProvider"
/>
<projectConfigurable
parentId=
"project.propVCSSupport.Mappings"
instance=
"org.jetbrains.plugins.github.ui.GithubSettingsConfigurable"
/>
<projectConfigurable
parentId=
"project.propVCSSupport.Mappings"
instance=
"org.jetbrains.plugins.github.ui.GithubSettingsConfigurable"
/>
<postStartupActivity
implementation=
"org.jetbrains.plugins.github.util.GithubAccountsMigrationHelper"
/>
</extensions>
</extensions>
<extensions
defaultExtensionNs=
"Git4Idea"
>
<extensions
defaultExtensionNs=
"Git4Idea"
>
...
...
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/api/GithubConnection.java
+
0
-
5
View file @
851666f8
...
@@ -57,11 +57,6 @@ public class GithubConnection {
...
@@ -57,11 +57,6 @@ public class GithubConnection {
private
volatile
HttpUriRequest
myRequest
;
private
volatile
HttpUriRequest
myRequest
;
private
volatile
boolean
myAborted
;
private
volatile
boolean
myAborted
;
@TestOnly
public
GithubConnection
(
@NotNull
GithubAuthData
auth
)
{
this
(
auth
,
false
);
}
public
GithubConnection
(
@NotNull
GithubAuthData
auth
,
boolean
reusable
)
{
public
GithubConnection
(
@NotNull
GithubAuthData
auth
,
boolean
reusable
)
{
myApiURL
=
GithubUrlUtil
.
getApiUrl
(
auth
.
getHost
());
myApiURL
=
GithubUrlUtil
.
getApiUrl
(
auth
.
getHost
());
myClient
=
new
GithubConnectionBuilder
(
auth
,
myApiURL
).
createClient
();
myClient
=
new
GithubConnectionBuilder
(
auth
,
myApiURL
).
createClient
();
...
...
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/ui/GithubCredentialsPanel.form
deleted
100644 → 0
+
0
-
174
View file @
bcb0533a
<?xml version="1.0" encoding="UTF-8"?>
<form
xmlns=
"http://www.intellij.com/uidesigner/form/"
version=
"1"
bind-to-class=
"org.jetbrains.plugins.github.ui.GithubCredentialsPanel"
>
<grid
id=
"27dc6"
binding=
"myPane"
layout-manager=
"GridLayoutManager"
row-count=
"4"
column-count=
"5"
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=
"646"
height=
"400"
/>
</constraints>
<properties/>
<clientProperties>
<html.disable
class=
"java.lang.Boolean"
value=
"false"
/>
</clientProperties>
<border
type=
"none"
/>
<children>
<component
id=
"45bab"
class=
"com.intellij.ui.components.JBLabel"
>
<constraints>
<grid
row=
"0"
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>
<anchor
value=
"e4416"
/>
<labelFor
value=
"3352a"
/>
<text
value=
"Host:"
/>
</properties>
</component>
<component
id=
"3352a"
class=
"javax.swing.JTextField"
binding=
"myHostTextField"
>
<constraints>
<grid
row=
"0"
column=
"1"
row-span=
"1"
col-span=
"1"
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=
"b276a"
class=
"com.intellij.ui.components.JBLabel"
binding=
"myAuthTypeLabel"
>
<constraints>
<grid
row=
"0"
column=
"2"
row-span=
"1"
col-span=
"1"
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"0"
indent=
"0"
use-parent-layout=
"false"
/>
</constraints>
<properties>
<labelFor
value=
"5a680"
/>
<text
value=
"Auth Type:"
/>
</properties>
</component>
<component
id=
"5a680"
class=
"com.intellij.openapi.ui.ComboBox"
binding=
"myAuthTypeComboBox"
>
<constraints>
<grid
row=
"0"
column=
"3"
row-span=
"1"
col-span=
"2"
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"1"
indent=
"0"
use-parent-layout=
"false"
>
<preferred-size
width=
"120"
height=
"-1"
/>
</grid>
</constraints>
<properties/>
</component>
<grid
id=
"bda15"
binding=
"myCardPanel"
layout-manager=
"CardLayout"
hgap=
"0"
vgap=
"0"
show=
"6d9fb"
>
<constraints>
<grid
row=
"1"
column=
"0"
row-span=
"1"
col-span=
"5"
vsize-policy=
"3"
hsize-policy=
"3"
anchor=
"0"
fill=
"3"
indent=
"0"
use-parent-layout=
"false"
/>
</constraints>
<properties/>
<border
type=
"none"
/>
<children>
<grid
id=
"e4354"
layout-manager=
"GridLayoutManager"
row-count=
"2"
column-count=
"2"
same-size-horizontally=
"false"
same-size-vertically=
"false"
hgap=
"-1"
vgap=
"-1"
>
<margin
top=
"0"
left=
"0"
bottom=
"0"
right=
"0"
/>
<constraints>
<card
name=
"Password"
/>
</constraints>
<properties/>
<border
type=
"none"
/>
<children>
<component
id=
"c0234"
class=
"com.intellij.ui.components.JBLabel"
>
<constraints>
<grid
row=
"0"
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>
<anchor
value=
"e4416"
/>
<labelFor
value=
"e76ec"
/>
<text
value=
"Login:"
/>
</properties>
</component>
<component
id=
"e76ec"
class=
"javax.swing.JTextField"
binding=
"myLoginTextField"
>
<constraints>
<grid
row=
"0"
column=
"1"
row-span=
"1"
col-span=
"1"
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=
"e4416"
class=
"com.intellij.ui.components.JBLabel"
>
<constraints>
<grid
row=
"1"
column=
"0"
row-span=
"1"
col-span=
"1"
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"0"
indent=
"0"
use-parent-layout=
"false"
/>
</constraints>
<properties>
<labelFor
value=
"9edbd"
/>
<text
value=
"Password:"
/>
</properties>
</component>
<component
id=
"9edbd"
class=
"javax.swing.JPasswordField"
binding=
"myPasswordField"
>
<constraints>
<grid
row=
"1"
column=
"1"
row-span=
"1"
col-span=
"1"
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>
</children>
</grid>
<grid
id=
"6d9fb"
layout-manager=
"GridLayoutManager"
row-count=
"2"
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>
<card
name=
"Token"
/>
</constraints>
<properties/>
<border
type=
"none"
/>
<children>
<component
id=
"3cdb8"
class=
"com.intellij.ui.components.JBLabel"
>
<constraints>
<grid
row=
"0"
column=
"0"
row-span=
"1"
col-span=
"1"
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"0"
indent=
"0"
use-parent-layout=
"false"
/>
</constraints>
<properties>
<anchor
value=
"e4416"
/>
<labelFor
value=
"aac20"
/>
<text
value=
"Token:"
/>
</properties>
</component>
<component
id=
"aac20"
class=
"javax.swing.JPasswordField"
binding=
"myTokenField"
>
<constraints>
<grid
row=
"0"
column=
"1"
row-span=
"1"
col-span=
"1"
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>
<vspacer
id=
"21b9e"
>
<constraints>
<grid
row=
"1"
column=
"1"
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=
"1b2df"
class=
"javax.swing.JButton"
binding=
"myCreateTokenButton"
>
<constraints>
<grid
row=
"0"
column=
"2"
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=
"Create API Token"
/>
</properties>
</component>
</children>
</grid>
</children>
</grid>
<component
id=
"28ddd"
class=
"javax.swing.JTextPane"
binding=
"mySignupTextField"
>
<constraints>
<grid
row=
"2"
column=
"0"
row-span=
"1"
col-span=
"4"
vsize-policy=
"0"
hsize-policy=
"2"
anchor=
"0"
fill=
"1"
indent=
"0"
use-parent-layout=
"false"
>
<preferred-size
width=
"150"
height=
"10"
/>
</grid>
</constraints>
<properties>
<contentType
value=
"text/html"
/>
<editable
value=
"false"
/>
<enabled
value=
"true"
/>
</properties>
<clientProperties>
<JEditorPane.honorDisplayProperties
class=
"java.lang.Boolean"
value=
"true"
/>
</clientProperties>
</component>
<component
id=
"8a6dd"
class=
"javax.swing.JButton"
binding=
"myTestButton"
default-binding=
"true"
>
<constraints>
<grid
row=
"2"
column=
"4"
row-span=
"1"
col-span=
"1"
vsize-policy=
"0"
hsize-policy=
"0"
anchor=
"0"
fill=
"1"
indent=
"0"
use-parent-layout=
"false"
/>
</constraints>
<properties>
<text
value=
"Test"
/>
</properties>
</component>
<vspacer
id=
"6ace"
>
<constraints>
<grid
row=
"3"
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>
</children>
</grid>
</form>
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/ui/GithubCredentialsPanel.java
deleted
100644 → 0
+
0
-
249
View file @
bcb0533a
/*
* Copyright 2000-2016 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package
org.jetbrains.plugins.github.ui
;
import
com.intellij.ide.BrowserUtil
;
import
com.intellij.openapi.diagnostic.Logger
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.openapi.ui.ComboBox
;
import
com.intellij.openapi.util.text.StringUtil
;
import
com.intellij.ui.components.JBLabel
;
import
com.intellij.util.ui.JBUI
;
import
com.intellij.util.ui.UIUtil
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.plugins.github.api.GithubApiUtil
;
import
org.jetbrains.plugins.github.api.data.GithubUser
;
import
org.jetbrains.plugins.github.exceptions.GithubAuthenticationException
;
import
org.jetbrains.plugins.github.util.*
;
import
org.jetbrains.plugins.github.util.GithubAuthData.AuthType
;
import
javax.swing.*
;
import
javax.swing.event.HyperlinkEvent
;
import
javax.swing.event.HyperlinkListener
;
import
java.awt.*
;
import
java.awt.event.ItemEvent
;
import
java.io.IOException
;
public
class
GithubCredentialsPanel
extends
JPanel
{
private
static
final
Logger
LOG
=
GithubUtil
.
LOG
;
private
JTextField
myHostTextField
;
private
JTextField
myLoginTextField
;
private
JPasswordField
myPasswordField
;
private
JPasswordField
myTokenField
;
private
ComboBox
<
Layout
>
myAuthTypeComboBox
;
private
JButton
myCreateTokenButton
;
private
JButton
myTestButton
;
private
JBLabel
myAuthTypeLabel
;
private
JTextPane
mySignupTextField
;
private
JPanel
myPane
;
private
JPanel
myCardPanel
;
public
GithubCredentialsPanel
(
@NotNull
Project
project
)
{
super
(
new
BorderLayout
());
add
(
myPane
,
BorderLayout
.
CENTER
);
mySignupTextField
.
setEditorKit
(
UIUtil
.
getHTMLEditorKit
());
mySignupTextField
.
setText
(
"<html><body>Do not have an account at github.com? <a href=\"https://github.com\">Sign up</a></body></html>"
);
mySignupTextField
.
setOpaque
(
false
);
mySignupTextField
.
setMargin
(
JBUI
.
insetsTop
(
5
));
mySignupTextField
.
addHyperlinkListener
(
new
HyperlinkListener
()
{
@Override
public
void
hyperlinkUpdate
(
HyperlinkEvent
e
)
{
if
(
e
.
getEventType
()
==
HyperlinkEvent
.
EventType
.
ACTIVATED
)
{
BrowserUtil
.
browse
(
e
.
getURL
());
}
else
{
mySignupTextField
.
setCursor
(
e
.
getEventType
()
==
HyperlinkEvent
.
EventType
.
ENTERED
?
new
Cursor
(
Cursor
.
HAND_CURSOR
)
:
new
Cursor
(
Cursor
.
DEFAULT_CURSOR
));
}
}
});
myAuthTypeLabel
.
setBorder
(
JBUI
.
Borders
.
emptyLeft
(
10
));
myAuthTypeComboBox
.
addItem
(
Layout
.
TOKEN
);
myAuthTypeComboBox
.
addItem
(
Layout
.
PASSWORD
);
myTestButton
.
addActionListener
(
e
->
testAuthData
(
project
));
myCreateTokenButton
.
addActionListener
(
e
->
generateToken
(
project
));
myAuthTypeComboBox
.
addItemListener
(
e
->
{
if
(
e
.
getStateChange
()
==
ItemEvent
.
SELECTED
)
{
Layout
item
=
(
Layout
)
e
.
getItem
();
CardLayout
cardLayout
=
(
CardLayout
)
myCardPanel
.
getLayout
();
cardLayout
.
show
(
myCardPanel
,
item
.
getCard
());
}
});
}
@NotNull
public
String
getHost
()
{
return
myHostTextField
.
getText
().
trim
();
}
@NotNull
public
String
getLogin
()
{
return
myLoginTextField
.
getText
().
trim
();
}
@NotNull
private
String
getPassword
()
{
return
String
.
valueOf
(
myPasswordField
.
getPassword
());
}
@NotNull
private
String
getToken
()
{
return
String
.
valueOf
(
myTokenField
.
getPassword
());
}
@NotNull
public
AuthType
getAuthType
()
{
Layout
selected
=
(
Layout
)
myAuthTypeComboBox
.
getSelectedItem
();
if
(
selected
==
Layout
.
PASSWORD
)
return
AuthType
.
BASIC
;
if
(
selected
==
Layout
.
TOKEN
)
return
AuthType
.
TOKEN
;
LOG
.
error
(
"GithubSettingsPanel: illegal selection - "
+
selected
);
return
AuthType
.
TOKEN
;
}
@NotNull
public
GithubAuthData
getAuthData
()
{
AuthType
type
=
getAuthType
();
switch
(
type
)
{
case
BASIC:
return
GithubAuthData
.
createBasicAuth
(
getHost
(),
getLogin
(),
getPassword
());
case
TOKEN:
return
GithubAuthData
.
createTokenAuth
(
getHost
(),
StringUtil
.
trim
(
getToken
()));
default
:
throw
new
IllegalStateException
();
}
}
public
void
setHost
(
@NotNull
String
host
)
{
myHostTextField
.
setText
(
host
);
}
public
void
setLogin
(
@Nullable
String
login
)
{
myLoginTextField
.
setText
(
login
);
}
public
void
setPassword
(
@NotNull
String
password
)
{
myPasswordField
.
setText
(
password
);
}
public
void
setToken
(
@NotNull
String
token
)
{
myTokenField
.
setText
(
token
);
}
public
void
setAuthType
(
@NotNull
GithubAuthData
.
AuthType
type
)
{
if
(
type
==
GithubAuthData
.
AuthType
.
BASIC
)
{
myAuthTypeComboBox
.
setSelectedItem
(
Layout
.
PASSWORD
);
}
else
{
myAuthTypeComboBox
.
setSelectedItem
(
Layout
.
TOKEN
);
}
}
public
void
setAuthData
(
@NotNull
GithubAuthData
authData
)
{
AuthType
type
=
authData
.
getAuthType
();
setAuthType
(
type
);
setHost
(
authData
.
getHost
());
if
(
type
==
AuthType
.
BASIC
)
{
GithubAuthData
.
BasicAuth
basicAuth
=
authData
.
getBasicAuth
();
assert
basicAuth
!=
null
;
setLogin
(
basicAuth
.
getLogin
());
setPassword
(
basicAuth
.
getPassword
());
}
if
(
type
==
AuthType
.
TOKEN
)
{
GithubAuthData
.
TokenAuth
tokenAuth
=
authData
.
getTokenAuth
();
assert
tokenAuth
!=
null
;
setToken
(
tokenAuth
.
getToken
());
}
}
public
void
lockAuthType
(
@NotNull
AuthType
type
)
{
setAuthType
(
type
);
myAuthTypeComboBox
.
setEnabled
(
false
);
}
public
void
lockHost
(
@NotNull
String
host
)
{
setHost
(
host
);
myHostTextField
.
setEnabled
(
false
);
}
public
void
setTestButtonVisible
(
boolean
visible
)
{
myTestButton
.
setVisible
(
visible
);
}
private
void
testAuthData
(
@NotNull
Project
project
)
{
try
{
GithubAuthData
auth
=
getAuthData
();
GithubUser
user
=
GithubUtil
.
computeValueInModalIO
(
project
,
"Access to GitHub"
,
indicator
->
GithubUtil
.
checkAuthData
(
project
,
new
GithubAuthDataHolder
(
auth
),
indicator
));
if
(
AuthType
.
TOKEN
.
equals
(
auth
.
getAuthType
()))
{
GithubNotifications
.
showInfoDialog
(
myPane
,
"Success"
,
"Connection successful for user "
+
user
.
getLogin
());
}
else
{
GithubNotifications
.
showInfoDialog
(
myPane
,
"Success"
,
"Connection successful"
);
}
}
catch
(
GithubAuthenticationException
ex
)
{
GithubNotifications
.
showErrorDialog
(
myPane
,
"Login Failure"
,
"Can't login using given credentials: "
,
ex
);
}
catch
(
IOException
ex
)
{
GithubNotifications
.
showErrorDialog
(
myPane
,
"Login Failure"
,
"Can't login: "
,
ex
);
}
}
private
void
generateToken
(
@NotNull
Project
project
)
{
try
{
String
newToken
=
GithubUtil
.
computeValueInModalIO
(
project
,
"Access to GitHub"
,
indicator
->
GithubUtil
.
runTask
(
project
,
GithubAuthDataHolder
.
createFromSettings
(),
indicator
,
AuthLevel
.
basicOnetime
(
getHost
()),
connection
->
GithubApiUtil
.
getMasterToken
(
connection
,
"IntelliJ plugin"
)));
myTokenField
.
setText
(
newToken
);
}
catch
(
IOException
ex
)
{
GithubNotifications
.
showErrorDialog
(
myPane
,
"Can't Create API Token"
,
ex
);
}
}
private
enum
Layout
{
PASSWORD
(
"Password"
),
TOKEN
(
"Token"
);
@NotNull
private
final
String
myCard
;
Layout
(
@NotNull
String
card
)
{
myCard
=
card
;
}
@NotNull
public
String
getCard
()
{
return
myCard
;
}
@Override
public
String
toString
()
{
return
myCard
;
}
}
}
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/ui/GithubLoginDialog.java
deleted
100644 → 0
+
0
-
120
View file @
bcb0533a
package
org.jetbrains.plugins.github.ui
;
import
com.intellij.openapi.diagnostic.Logger
;
import
com.intellij.openapi.project.Project
;
import
com.intellij.openapi.ui.DialogWrapper
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.plugins.github.util.*
;
import
javax.swing.*
;
import
java.io.IOException
;
public
class
GithubLoginDialog
extends
DialogWrapper
{
private
static
final
Logger
LOG
=
GithubUtil
.
LOG
;
private
final
GithubCredentialsPanel
myCredentialsPanel
;
@NotNull
private
final
Project
myProject
;
@NotNull
private
final
AuthLevel
myAuthLevel
;
private
GithubAuthData
myAuthData
;
private
boolean
mySavePassword
;
public
GithubLoginDialog
(
@NotNull
Project
project
,
@NotNull
GithubAuthData
oldAuthData
,
@NotNull
AuthLevel
authLevel
)
{
super
(
project
,
true
);
myProject
=
project
;
myAuthLevel
=
authLevel
;
myCredentialsPanel
=
new
GithubCredentialsPanel
(
project
);
myCredentialsPanel
.
setTestButtonVisible
(
false
);
myCredentialsPanel
.
setHost
(
oldAuthData
.
getHost
());
myCredentialsPanel
.
setAuthType
(
oldAuthData
.
getAuthType
());
GithubAuthData
.
BasicAuth
basicAuth
=
oldAuthData
.
getBasicAuth
();
if
(
basicAuth
!=
null
)
{
myCredentialsPanel
.
setLogin
(
basicAuth
.
getLogin
());
}
if
(
authLevel
.
getHost
()
!=
null
)
myCredentialsPanel
.
lockHost
(
authLevel
.
getHost
());
if
(
authLevel
.
getAuthType
()
!=
null
)
myCredentialsPanel
.
lockAuthType
(
authLevel
.
getAuthType
());
if
(!
authLevel
.
isOnetime
())
setDoNotAskOption
(
new
MyRememberPasswordOption
());
setTitle
(
"Login to GitHub"
);
setOKButtonText
(
"Login"
);
init
();
}
@NotNull
protected
Action
[]
createActions
()
{
return
new
Action
[]{
getOKAction
(),
getCancelAction
(),
getHelpAction
()};
}
@Override
protected
JComponent
createCenterPanel
()
{
return
myCredentialsPanel
;
}
@Override
protected
String
getHelpId
()
{
return
"login_to_github"
;
}
@Override
protected
void
doOKAction
()
{
GithubAuthDataHolder
authHolder
=
new
GithubAuthDataHolder
(
myCredentialsPanel
.
getAuthData
());
try
{
GithubUtil
.
computeValueInModalIO
(
myProject
,
"Access to GitHub"
,
indicator
->
GithubUtil
.
checkAuthData
(
myProject
,
authHolder
,
indicator
));
myAuthData
=
authHolder
.
getAuthData
();
super
.
doOKAction
();
}
catch
(
IOException
e
)
{
LOG
.
info
(
e
);
setErrorText
(
"Can't login: "
+
GithubUtil
.
getErrorTextFromException
(
e
),
myCredentialsPanel
);
}
}
public
boolean
isSavePasswordSelected
()
{
return
mySavePassword
;
}
@NotNull
public
GithubAuthData
getAuthData
()
{
if
(
myAuthData
==
null
)
{
throw
new
IllegalStateException
(
"AuthData is not set"
);
}
return
myAuthData
;
}
private
class
MyRememberPasswordOption
implements
DoNotAskOption
{
@Override
public
boolean
isToBeShown
()
{
return
!
GithubSettings
.
getInstance
().
isSavePassword
();
}
@Override
public
void
setToBeShown
(
boolean
toBeShown
,
int
exitCode
)
{
mySavePassword
=
!
toBeShown
;
GithubSettings
.
getInstance
().
setSavePassword
(!
toBeShown
);
}
@Override
public
boolean
canBeHidden
()
{
return
GithubSettings
.
getInstance
().
isSavePasswordMakesSense
();
}
@Override
public
boolean
shouldSaveOptionsOnCancel
()
{
return
false
;
}
@NotNull
@Override
public
String
getDoNotShowMessage
()
{
return
"Save credentials"
;
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/util/AuthLevel.java
+
4
-
0
View file @
851666f8
...
@@ -19,6 +19,10 @@ import com.google.common.base.MoreObjects;
...
@@ -19,6 +19,10 @@ import com.google.common.base.MoreObjects;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.annotations.Nullable
;
/**
* @deprecated {@link org.jetbrains.plugins.github.authentication.GithubAuthenticationManager}
*/
@Deprecated
public
class
AuthLevel
{
public
class
AuthLevel
{
public
static
final
AuthLevel
ANY
=
new
AuthLevel
(
null
,
null
);
public
static
final
AuthLevel
ANY
=
new
AuthLevel
(
null
,
null
);
public
static
final
AuthLevel
TOKEN
=
new
AuthLevel
(
null
,
GithubAuthData
.
AuthType
.
TOKEN
);
public
static
final
AuthLevel
TOKEN
=
new
AuthLevel
(
null
,
GithubAuthData
.
AuthType
.
TOKEN
);
...
...
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/util/GithubAccountsMigrationHelper.kt
0 → 100644
+
76
-
0
View file @
851666f8
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.github.util
import
com.intellij.ide.passwordSafe.PasswordSafe
import
com.intellij.openapi.progress.ProgressIndicator
import
com.intellij.openapi.progress.Task
import
com.intellij.openapi.project.Project
import
com.intellij.openapi.startup.StartupActivity
import
org.jetbrains.plugins.github.api.GithubApiTaskExecutor
import
org.jetbrains.plugins.github.api.GithubApiUtil
import
org.jetbrains.plugins.github.api.GithubServerPath
import
org.jetbrains.plugins.github.api.GithubTask
import
org.jetbrains.plugins.github.authentication.accounts.GithubAccount
import
org.jetbrains.plugins.github.authentication.accounts.GithubAccountManager
internal
const
val
GITHUB_SETTINGS_PASSWORD_KEY
=
"GITHUB_SETTINGS_PASSWORD_KEY"
/**
* Temporary helper
* Will move single-account authorization data to accounts list if it was a token-based auth and clear old settings
*/
class
GithubAccountsMigrationHelper
internal
constructor
(
private
val
settings
:
GithubSettings
,
private
val
accountManager
:
GithubAccountManager
,
private
val
passwordSafe
:
PasswordSafe
)
:
StartupActivity
{
override
fun
runActivity
(
project
:
Project
)
{
val
login
=
settings
.
login
val
host
=
settings
.
host
?:
GithubApiUtil
.
DEFAULT_GITHUB_HOST
val
authType
=
settings
.
authType
if
(
accountManager
.
accounts
.
isEmpty
()
&&
login
!=
null
&&
authType
!=
null
)
{
when
(
authType
)
{
GithubAuthData
.
AuthType
.
BASIC
->
{
passwordSafe
.
getPassword
(
GithubSettings
::
class
.
java
,
GITHUB_SETTINGS_PASSWORD_KEY
)
?.
let
{
password
->
object
:
Task
.
Backgroundable
(
project
,
"Acquiring Github Token"
)
{
private
lateinit
var
token
:
String
override
fun
run
(
indicator
:
ProgressIndicator
)
{
token
=
GithubApiTaskExecutor
.
execute
(
indicator
,
GithubServerPath
.
from
(
host
),
login
,
password
.
toCharArray
(),
GithubTask
{
GithubApiUtil
.
getMasterToken
(
it
,
GithubUtil
.
DEFAULT_TOKEN_NOTE
)
})
}
override
fun
onSuccess
()
{
addAccount
(
login
,
host
,
token
)
}
override
fun
onThrowable
(
error
:
Throwable
)
{
GithubNotifications
.
showWarning
(
project
,
"Cannot Migrate Github Account $login"
,
"Cannot acquire token for $host.\n${error.message}"
,
GithubNotifications
.
getConfigureAction
(
project
))
}
}.
queue
()
}
}
GithubAuthData
.
AuthType
.
TOKEN
->
{
passwordSafe
.
getPassword
(
GithubSettings
::
class
.
java
,
GITHUB_SETTINGS_PASSWORD_KEY
)
?.
let
{
addAccount
(
login
,
host
,
it
)
}
}
else
->
{
}
}
}
clearOldAuth
()
}
private
fun
addAccount
(
login
:
String
,
host
:
String
,
token
:
String
)
{
val
account
=
GithubAccount
(
login
,
GithubServerPath
.
from
(
host
))
accountManager
.
accounts
+=
account
accountManager
.
updateAccountToken
(
account
,
token
)
}
private
fun
clearOldAuth
()
{
settings
.
clearAuth
()
passwordSafe
.
setPassword
(
GithubSettings
::
class
.
java
,
GITHUB_SETTINGS_PASSWORD_KEY
,
null
)
}
}
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/util/GithubAuthData.java
+
2
-
5
View file @
851666f8
...
@@ -52,12 +52,9 @@ public class GithubAuthData {
...
@@ -52,12 +52,9 @@ public class GithubAuthData {
myUseProxy
=
useProxy
;
myUseProxy
=
useProxy
;
}
}
public
static
GithubAuthData
createFromSettings
()
{
@Deprecated
return
GithubSettings
.
getInstance
().
getAuthData
();
}
public
static
GithubAuthData
createAnonymous
()
{
public
static
GithubAuthData
createAnonymous
()
{
return
createAnonymous
(
GithubSettings
.
getInstance
().
getHost
());
return
createAnonymous
(
StringUtil
.
notNullize
(
GithubSettings
.
getInstance
().
getHost
())
)
;
}
}
public
static
GithubAuthData
createAnonymous
(
@NotNull
String
host
)
{
public
static
GithubAuthData
createAnonymous
(
@NotNull
String
host
)
{
...
...
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/util/GithubAuthDataHolder.java
+
4
-
15
View file @
851666f8
...
@@ -15,10 +15,12 @@
...
@@ -15,10 +15,12 @@
*/
*/
package
org.jetbrains.plugins.github.util
;
package
org.jetbrains.plugins.github.util
;
import
com.intellij.openapi.util.ThrowableComputable
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
/**
* @deprecated {@link org.jetbrains.plugins.github.authentication.GithubAuthenticationManager}
*/
@Deprecated
public
class
GithubAuthDataHolder
{
public
class
GithubAuthDataHolder
{
@NotNull
private
GithubAuthData
myAuthData
;
@NotNull
private
GithubAuthData
myAuthData
;
...
@@ -30,17 +32,4 @@ public class GithubAuthDataHolder {
...
@@ -30,17 +32,4 @@ public class GithubAuthDataHolder {
public
synchronized
GithubAuthData
getAuthData
()
{
public
synchronized
GithubAuthData
getAuthData
()
{
return
myAuthData
;
return
myAuthData
;
}
}
public
synchronized
<
T
extends
Throwable
>
void
runTransaction
(
@NotNull
GithubAuthData
expected
,
@NotNull
ThrowableComputable
<
GithubAuthData
,
T
>
task
)
throws
T
{
if
(
expected
!=
myAuthData
)
{
return
;
}
myAuthData
=
task
.
compute
();
}
public
static
GithubAuthDataHolder
createFromSettings
()
{
return
new
GithubAuthDataHolder
(
GithubSettings
.
getInstance
().
getAuthData
());
}
}
}
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/util/GithubSettings.java
+
47
-
118
View file @
851666f8
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package
org.jetbrains.plugins.github.util
;
package
org.jetbrains.plugins.github.util
;
import
com.intellij.ide.passwordSafe.PasswordSafe
;
import
com.intellij.openapi.components.PersistentStateComponent
;
import
com.intellij.openapi.components.PersistentStateComponent
;
import
com.intellij.openapi.components.ServiceManager
;
import
com.intellij.openapi.components.ServiceManager
;
import
com.intellij.openapi.components.State
;
import
com.intellij.openapi.components.State
;
import
com.intellij.openapi.components.Storage
;
import
com.intellij.openapi.components.Storage
;
import
com.intellij.openapi.util.text.StringUtil
;
import
com.intellij.util.ThreeState
;
import
com.intellij.util.ThreeState
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.annotations.Nullable
;
import
org.jetbrains.plugins.github.a
pi.GithubApiUtil
;
import
org.jetbrains.plugins.github.a
uthentication.GithubAuthenticationManager
;
import
static
org
.
jetbrains
.
plugins
.
github
.
util
.
GithubAuthData
.
AuthType
;
import
static
org
.
jetbrains
.
plugins
.
github
.
util
.
GithubAuthData
.
AuthType
;
/**
* @author oleg
*/
@SuppressWarnings
(
"MethodMayBeStatic"
)
@SuppressWarnings
(
"MethodMayBeStatic"
)
@State
(
name
=
"GithubSettings"
,
storages
=
@Storage
(
"github_settings.xml"
))
@State
(
name
=
"GithubSettings"
,
storages
=
@Storage
(
"github_settings.xml"
))
public
class
GithubSettings
implements
PersistentStateComponent
<
GithubSettings
.
State
>
{
public
class
GithubSettings
implements
PersistentStateComponent
<
GithubSettings
.
State
>
{
private
static
final
String
GITHUB_SETTINGS_PASSWORD_KEY
=
"GITHUB_SETTINGS_PASSWORD_KEY"
;
private
State
myState
=
new
State
();
private
State
myState
=
new
State
();
public
State
getState
()
{
public
State
getState
()
{
...
@@ -34,14 +27,13 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
...
@@ -34,14 +27,13 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
public
static
class
State
{
public
static
class
State
{
@Nullable
public
String
LOGIN
=
null
;
@Nullable
public
String
LOGIN
=
null
;
@NotNull
public
String
HOST
=
GithubApiUtil
.
DEFAULT_GITHUB_HOST
;
@Nullable
public
String
HOST
=
null
;
@NotNull
public
AuthType
AUTH_TYPE
=
AuthType
.
ANONYMOUS
;
@Nullable
public
AuthType
AUTH_TYPE
=
null
;
public
boolean
OPEN_IN_BROWSER_GIST
=
true
;
public
boolean
OPEN_IN_BROWSER_GIST
=
true
;
// "Secret" in UI, "Public" in API. "Private" here to preserve user settings after refactoring
// "Secret" in UI, "Public" in API. "Private" here to preserve user settings after refactoring
public
boolean
PRIVATE_GIST
=
true
;
public
boolean
PRIVATE_GIST
=
true
;
public
boolean
SAVE_PASSWORD
=
true
;
public
int
CONNECTION_TIMEOUT
=
5000
;
public
int
CONNECTION_TIMEOUT
=
5000
;
public
boolean
VALID_GIT_AUTH
=
true
;
public
ThreeState
CREATE_PULL_REQUEST_CREATE_REMOTE
=
ThreeState
.
UNSURE
;
public
ThreeState
CREATE_PULL_REQUEST_CREATE_REMOTE
=
ThreeState
.
UNSURE
;
public
boolean
CLONE_GIT_USING_SSH
=
false
;
public
boolean
CLONE_GIT_USING_SSH
=
false
;
}
}
...
@@ -58,37 +50,6 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
...
@@ -58,37 +50,6 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
myState
.
CONNECTION_TIMEOUT
=
timeout
;
myState
.
CONNECTION_TIMEOUT
=
timeout
;
}
}
@NotNull
public
String
getHost
()
{
return
myState
.
HOST
;
}
@Nullable
public
String
getLogin
()
{
return
myState
.
LOGIN
;
}
@NotNull
public
AuthType
getAuthType
()
{
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
(
@Nullable
String
login
)
{
myState
.
LOGIN
=
login
;
}
private
void
setAuthType
(
@NotNull
AuthType
authType
)
{
myState
.
AUTH_TYPE
=
authType
;
}
public
boolean
isOpenInBrowserGist
()
{
public
boolean
isOpenInBrowserGist
()
{
return
myState
.
OPEN_IN_BROWSER_GIST
;
return
myState
.
OPEN_IN_BROWSER_GIST
;
}
}
...
@@ -97,18 +58,6 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
...
@@ -97,18 +58,6 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
return
myState
.
PRIVATE_GIST
;
return
myState
.
PRIVATE_GIST
;
}
}
public
boolean
isSavePassword
()
{
return
myState
.
SAVE_PASSWORD
;
}
public
boolean
isValidGitAuth
()
{
return
myState
.
VALID_GIT_AUTH
;
}
public
boolean
isSavePasswordMakesSense
()
{
return
!
PasswordSafe
.
getInstance
().
isMemoryOnly
();
}
public
boolean
isCloneGitUsingSsh
()
{
public
boolean
isCloneGitUsingSsh
()
{
return
myState
.
CLONE_GIT_USING_SSH
;
return
myState
.
CLONE_GIT_USING_SSH
;
}
}
...
@@ -126,14 +75,6 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
...
@@ -126,14 +75,6 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
myState
.
PRIVATE_GIST
=
secretGist
;
myState
.
PRIVATE_GIST
=
secretGist
;
}
}
public
void
setSavePassword
(
final
boolean
savePassword
)
{
myState
.
SAVE_PASSWORD
=
savePassword
;
}
public
void
setValidGitAuth
(
final
boolean
validGitAuth
)
{
myState
.
VALID_GIT_AUTH
=
validGitAuth
;
}
public
void
setOpenInBrowserGist
(
final
boolean
openInBrowserGist
)
{
public
void
setOpenInBrowserGist
(
final
boolean
openInBrowserGist
)
{
myState
.
OPEN_IN_BROWSER_GIST
=
openInBrowserGist
;
myState
.
OPEN_IN_BROWSER_GIST
=
openInBrowserGist
;
}
}
...
@@ -142,68 +83,56 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
...
@@ -142,68 +83,56 @@ public class GithubSettings implements PersistentStateComponent<GithubSettings.S
myState
.
CLONE_GIT_USING_SSH
=
value
;
myState
.
CLONE_GIT_USING_SSH
=
value
;
}
}
@NotNull
//region Deprecated auth
private
String
getPassword
()
{
return
StringUtil
.
notNullize
(
PasswordSafe
.
getInstance
().
getPassword
(
GithubSettings
.
class
,
GITHUB_SETTINGS_PASSWORD_KEY
));
/**
* @deprecated {@link GithubAuthenticationManager}
*/
@Deprecated
@Nullable
public
String
getHost
()
{
return
myState
.
HOST
;
}
}
private
void
setPassword
(
@NotNull
String
password
,
boolean
rememberPassword
)
{
/**
if
(!
rememberPassword
)
return
;
* @deprecated {@link GithubAuthenticationManager}
PasswordSafe
.
getInstance
().
setPassword
(
GithubSettings
.
class
,
GITHUB_SETTINGS_PASSWORD_KEY
,
password
);
*/
@Deprecated
@Nullable
public
String
getLogin
()
{
return
myState
.
LOGIN
;
}
}
private
static
boolean
isValidGitAuth
(
@NotNull
GithubAuthData
auth
)
{
/**
switch
(
auth
.
getAuthType
())
{
* @deprecated {@link GithubAuthenticationManager}
case
BASIC:
*/
assert
auth
.
getBasicAuth
()
!=
null
;
@Deprecated
return
auth
.
getBasicAuth
().
getCode
()
==
null
;
@Nullable
case
TOKEN:
public
AuthType
getAuthType
()
{
return
true
;
return
myState
.
AUTH_TYPE
;
case
ANONYMOUS:
}
return
false
;
default
:
/**
throw
new
IllegalStateException
(
"GithubSettings: setAuthData - wrong AuthType: "
+
auth
.
getAuthType
());
* @deprecated {@link GithubAuthenticationManager}
}
*/
@Deprecated
public
boolean
isAuthConfigured
()
{
return
GithubAuthenticationManager
.
getInstance
().
hasAccounts
();
}
}
/**
* @deprecated {@link GithubAuthenticationManager}
*/
@Deprecated
@NotNull
@NotNull
public
GithubAuthData
getAuthData
()
{
public
GithubAuthData
getAuthData
()
{
switch
(
getAuthType
())
{
throw
new
IllegalStateException
(
"Single account auth is deprecated"
);
case
BASIC:
}
//noinspection ConstantConditions
return
GithubAuthData
.
createBasicAuth
(
getHost
(),
getLogin
(),
getPassword
());
public
void
clearAuth
()
{
case
TOKEN:
myState
.
HOST
=
null
;
return
GithubAuthData
.
createTokenAuth
(
getHost
(),
getPassword
());
myState
.
LOGIN
=
null
;
case
ANONYMOUS:
myState
.
AUTH_TYPE
=
null
;
return
GithubAuthData
.
createAnonymous
(
getHost
());
default
:
throw
new
IllegalStateException
(
"GithubSettings: getAuthData - wrong AuthType: "
+
getAuthType
());
}
}
public
void
setAuthData
(
@NotNull
GithubAuthData
auth
,
boolean
rememberPassword
)
{
setValidGitAuth
(
isValidGitAuth
(
auth
));
setAuthType
(
auth
.
getAuthType
());
setHost
(
auth
.
getHost
());
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
:
throw
new
IllegalStateException
(
"GithubSettings: setAuthData - wrong AuthType: "
+
auth
.
getAuthType
());
}
}
}
//endregion
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/util/GithubUrlUtil.java
+
28
-
105
View file @
851666f8
...
@@ -70,67 +70,12 @@ public class GithubUrlUtil {
...
@@ -70,67 +70,12 @@ public class GithubUrlUtil {
return
getApiProtocolFromUrl
(
urlFromSettings
)
+
getApiUrlWithoutProtocol
(
urlFromSettings
);
return
getApiProtocolFromUrl
(
urlFromSettings
)
+
getApiUrlWithoutProtocol
(
urlFromSettings
);
}
}
@NotNull
public
static
String
getApiProtocol
()
{
return
getApiProtocolFromUrl
(
GithubSettings
.
getInstance
().
getHost
());
}
@NotNull
@NotNull
public
static
String
getApiProtocolFromUrl
(
@NotNull
String
urlFromSettings
)
{
public
static
String
getApiProtocolFromUrl
(
@NotNull
String
urlFromSettings
)
{
if
(
StringUtil
.
startsWithIgnoreCase
(
urlFromSettings
.
trim
(),
"http://"
))
return
"http://"
;
if
(
StringUtil
.
startsWithIgnoreCase
(
urlFromSettings
.
trim
(),
"http://"
))
return
"http://"
;
return
"https://"
;
return
"https://"
;
}
}
/**
* E.g.: https://api.github.com
* https://my.company.url/api/v3
*/
@NotNull
public
static
String
getApiUrl
()
{
return
getApiUrl
(
GithubSettings
.
getInstance
().
getHost
());
}
/**
* Returns the "host" part of Github URLs.
* E.g.: https://github.com
* https://my.company.url
* Note: there is no trailing slash in the returned url.
*/
@NotNull
public
static
String
getGithubHost
()
{
return
getApiProtocol
()
+
getGitHostWithoutProtocol
();
}
/**
* E.g.: https://github.com/suffix/ -> github.com
* github.com:8080/ -> github.com
*/
@NotNull
public
static
String
getHostFromUrl
(
@NotNull
String
url
)
{
String
path
=
removeProtocolPrefix
(
url
).
replace
(
':'
,
'/'
);
int
index
=
path
.
indexOf
(
'/'
);
if
(
index
==
-
1
)
{
return
path
;
}
else
{
return
path
.
substring
(
0
,
index
);
}
}
/**
* E.g.: github.com
* my.company.url
*/
@NotNull
public
static
String
getGitHostWithoutProtocol
()
{
return
getGitHostWithoutProtocol
(
GithubSettings
.
getInstance
().
getHost
());
}
@NotNull
public
static
String
getGitHostWithoutProtocol
(
@NotNull
String
host
)
{
return
removeTrailingSlash
(
removeProtocolPrefix
(
host
));
}
/*
/*
All API access is over HTTPS, and accessed from the api.github.com domain
All API access is over HTTPS, and accessed from the api.github.com domain
(or through yourdomain.com/api/v3/ for enterprise).
(or through yourdomain.com/api/v3/ for enterprise).
...
@@ -156,25 +101,9 @@ public class GithubUrlUtil {
...
@@ -156,25 +101,9 @@ public class GithubUrlUtil {
}
}
}
}
public
static
boolean
isGithubUrl
(
@NotNull
String
url
)
{
return
isGithubUrl
(
url
,
GithubSettings
.
getInstance
().
getHost
());
}
public
static
boolean
isGithubUrl
(
@NotNull
String
url
,
@NotNull
String
host
)
{
host
=
getHostFromUrl
(
host
);
url
=
removeProtocolPrefix
(
url
);
if
(
StringUtil
.
startsWithIgnoreCase
(
url
,
host
))
{
if
(
url
.
length
()
>
host
.
length
()
&&
":/"
.
indexOf
(
url
.
charAt
(
host
.
length
()))
==
-
1
)
{
return
false
;
}
return
true
;
}
return
false
;
}
/**
/**
* assumed isGithubUrl(remoteUrl)
* assumed isGithubUrl(remoteUrl)
*
*
<p>
* git@github.com:user/repo.git -> user/repo
* git@github.com:user/repo.git -> user/repo
*/
*/
@Nullable
@Nullable
...
@@ -197,25 +126,6 @@ public class GithubUrlUtil {
...
@@ -197,25 +126,6 @@ public class GithubUrlUtil {
return
new
GithubFullPath
(
username
,
reponame
);
return
new
GithubFullPath
(
username
,
reponame
);
}
}
/**
* assumed isGithubUrl(remoteUrl)
*
* git@github.com:user/repo -> https://github.com/user/repo
*/
@Nullable
public
static
String
makeGithubRepoUrlFromRemoteUrl
(
@NotNull
String
remoteUrl
)
{
return
makeGithubRepoUrlFromRemoteUrl
(
remoteUrl
,
getGithubHost
());
}
@Nullable
public
static
String
makeGithubRepoUrlFromRemoteUrl
(
@NotNull
String
remoteUrl
,
@NotNull
String
host
)
{
GithubFullPath
repo
=
getUserAndRepositoryFromRemoteUrl
(
remoteUrl
);
if
(
repo
==
null
)
{
return
null
;
}
return
host
+
'/'
+
repo
.
getUser
()
+
'/'
+
repo
.
getRepository
();
}
@NotNull
@NotNull
private
static
String
removeEndingDotGit
(
@NotNull
String
url
)
{
private
static
String
removeEndingDotGit
(
@NotNull
String
url
)
{
url
=
removeTrailingSlash
(
url
);
url
=
removeTrailingSlash
(
url
);
...
@@ -226,23 +136,36 @@ public class GithubUrlUtil {
...
@@ -226,23 +136,36 @@ public class GithubUrlUtil {
return
url
;
return
url
;
}
}
//region Deprecated
/**
* E.g.: https://github.com/suffix/ -> github.com
* github.com:8080/ -> github.com
*
* @deprecated {@link org.jetbrains.plugins.github.api.GithubRepositoryPath}
*/
@NotNull
@NotNull
public
static
String
getCloneUrl
(
@NotNull
GithubFullPath
path
)
{
public
static
String
getHostFromUrl
(
@NotNull
String
url
)
{
return
getCloneUrl
(
path
.
getUser
(),
path
.
getRepository
());
String
path
=
removeProtocolPrefix
(
url
).
replace
(
':'
,
'/'
);
}
int
index
=
path
.
indexOf
(
'/'
);
if
(
index
==
-
1
)
{
@NotNull
return
path
;
public
static
String
getCloneUrl
(
@NotNull
String
user
,
@NotNull
String
repo
)
{
return
getCloneUrl
(
getGitHostWithoutProtocol
(),
user
,
repo
);
}
@NotNull
public
static
String
getCloneUrl
(
@NotNull
String
host
,
@NotNull
String
user
,
@NotNull
String
repo
)
{
if
(
GithubSettings
.
getInstance
().
isCloneGitUsingSsh
())
{
return
"git@"
+
host
+
":"
+
user
+
"/"
+
repo
+
".git"
;
}
}
else
{
else
{
return
getApiProtocol
()
+
host
+
"/"
+
user
+
"/"
+
repo
+
".git"
;
return
path
.
substring
(
0
,
index
)
;
}
}
}
}
/**
* @deprecated {@link org.jetbrains.plugins.github.api.GithubRepositoryPath}
*/
@Deprecated
@Nullable
public
static
String
makeGithubRepoUrlFromRemoteUrl
(
@NotNull
String
remoteUrl
,
@NotNull
String
host
)
{
GithubFullPath
repo
=
getUserAndRepositoryFromRemoteUrl
(
remoteUrl
);
if
(
repo
==
null
)
{
return
null
;
}
return
host
+
'/'
+
repo
.
getUser
()
+
'/'
+
repo
.
getRepository
();
}
//endregion
}
}
This diff is collapsed.
Click to expand it.
plugins/github/src/org/jetbrains/plugins/github/util/GithubUtil.kt
+
143
-
391
View file @
851666f8
This diff is collapsed.
Click to expand it.
plugins/github/test/org/jetbrains/plugins/github/GithubCreateGistTestBase.java
+
0
-
13
View file @
851666f8
...
@@ -15,18 +15,14 @@
...
@@ -15,18 +15,14 @@
*/
*/
package
org.jetbrains.plugins.github
;
package
org.jetbrains.plugins.github
;
import
com.intellij.openapi.ui.DialogWrapper
;
import
com.intellij.openapi.util.Clock
;
import
com.intellij.openapi.util.Clock
;
import
com.intellij.openapi.util.Comparing
;
import
com.intellij.openapi.util.Comparing
;
import
com.intellij.util.text.DateFormatUtil
;
import
com.intellij.util.text.DateFormatUtil
;
import
git4idea.test.TestDialogHandler
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.annotations.NotNull
;
import
org.jetbrains.plugins.github.api.GithubApiUtil
;
import
org.jetbrains.plugins.github.api.GithubApiUtil
;
import
org.jetbrains.plugins.github.api.data.GithubGist
;
import
org.jetbrains.plugins.github.api.data.GithubGist
;
import
org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent
;
import
org.jetbrains.plugins.github.api.requests.GithubGistRequest.FileContent
;
import
org.jetbrains.plugins.github.test.GithubTest
;
import
org.jetbrains.plugins.github.test.GithubTest
;
import
org.jetbrains.plugins.github.ui.GithubLoginDialog
;
import
org.jetbrains.plugins.github.util.GithubAuthDataHolder
;
import
java.io.IOException
;
import
java.io.IOException
;
import
java.util.ArrayList
;
import
java.util.ArrayList
;
...
@@ -128,13 +124,4 @@ public abstract class GithubCreateGistTestBase extends GithubTest {
...
@@ -128,13 +124,4 @@ public abstract class GithubCreateGistTestBase extends GithubTest {
assertTrue
(
"Gist content differs from sample"
,
Comparing
.
haveEqualElements
(
files
,
expected
));
assertTrue
(
"Gist content differs from sample"
,
Comparing
.
haveEqualElements
(
files
,
expected
));
}
}
protected
void
registerCancelingLoginDialogHandler
()
{
dialogManager
.
registerDialogHandler
(
GithubLoginDialog
.
class
,
new
TestDialogHandler
<
GithubLoginDialog
>()
{
@Override
public
int
handleDialog
(
GithubLoginDialog
dialog
)
{
return
DialogWrapper
.
CANCEL_EXIT_CODE
;
}
});
}
}
}
This diff is collapsed.
Click to expand it.
plugins/github/test/org/jetbrains/plugins/github/GithubUrlUtilTest.java
+
0
-
46
View file @
851666f8
...
@@ -95,52 +95,6 @@ public class GithubUrlUtilTest extends TestCase {
...
@@ -95,52 +95,6 @@ public class GithubUrlUtilTest extends TestCase {
runTestCase
(
tests
,
in
->
removePort
(
in
));
runTestCase
(
tests
,
in
->
removePort
(
in
));
}
}
public
void
testIsGithubUrl1
()
{
TestCase
<
Boolean
>
tests
=
new
TestCase
<>();
tests
.
add
(
"http://github.com/user/repo"
,
true
);
tests
.
add
(
"https://github.com/user/repo"
,
true
);
tests
.
add
(
"git://github.com/user/repo"
,
true
);
tests
.
add
(
"git@github.com:user/repo"
,
true
);
tests
.
add
(
"https://github.com/"
,
true
);
tests
.
add
(
"github.com"
,
true
);
tests
.
add
(
"https://user@github.com/user/repo"
,
true
);
tests
.
add
(
"https://user:password@github.com/user/repo"
,
true
);
tests
.
add
(
"git@github.com:user/repo"
,
true
);
tests
.
add
(
"https://github.com:2233/"
,
true
);
tests
.
add
(
"HTTPS://GitHub.com:2233/"
,
true
);
tests
.
add
(
"google.com"
,
false
);
tests
.
add
(
"github.com.site.ua"
,
false
);
tests
.
add
(
"sf@hskfh../.#fwenj 32#$"
,
false
);
tests
.
add
(
"api.github.com"
,
false
);
tests
.
add
(
"site.com//github.com"
,
false
);
runTestCase
(
tests
,
in
->
isGithubUrl
(
in
,
"https://github.com/"
));
runTestCase
(
tests
,
in
->
isGithubUrl
(
in
,
"http://GitHub.com"
));
}
public
void
testIsGithubUrl2
()
{
TestCase
<
Boolean
>
tests
=
new
TestCase
<>();
tests
.
add
(
"http://git.code.example.co.jp/user/repo"
,
true
);
tests
.
add
(
"https://git.code.example.co.jp/user/repo"
,
true
);
tests
.
add
(
"git://git.code.example.co.jp/user/repo"
,
true
);
tests
.
add
(
"git@git.code.example.co.jp:user/repo"
,
true
);
tests
.
add
(
"http://git.code.example.co/user/repo"
,
false
);
tests
.
add
(
"http://code.example.co.jp/user/repo"
,
false
);
runTestCase
(
tests
,
in
->
isGithubUrl
(
in
,
"git.code.example.co.jp"
));
runTestCase
(
tests
,
in
->
isGithubUrl
(
in
,
"http://git.code.example.co.jp"
));
runTestCase
(
tests
,
in
->
isGithubUrl
(
in
,
"https://git.code.example.co.jp/github/server"
));
runTestCase
(
tests
,
in
->
isGithubUrl
(
in
,
"git.code.example.co.jp/api"
));
}
public
void
testGetApiUrlWithoutProtocol
()
{
public
void
testGetApiUrlWithoutProtocol
()
{
TestCase
<
String
>
tests
=
new
TestCase
<>();
TestCase
<
String
>
tests
=
new
TestCase
<>();
...
...
This diff is collapsed.
Click to expand it.
plugins/github/test/org/jetbrains/plugins/github/test/GithubTest.java
+
7
-
29
View file @
851666f8
...
@@ -34,7 +34,6 @@ import org.jetbrains.plugins.github.api.GithubApiTaskExecutor;
...
@@ -34,7 +34,6 @@ import org.jetbrains.plugins.github.api.GithubApiTaskExecutor;
import
org.jetbrains.plugins.github.api.GithubApiUtil
;
import
org.jetbrains.plugins.github.api.GithubApiUtil
;
import
org.jetbrains.plugins.github.authentication.GithubAuthenticationManager
;
import
org.jetbrains.plugins.github.authentication.GithubAuthenticationManager
;
import
org.jetbrains.plugins.github.authentication.accounts.GithubAccount
;
import
org.jetbrains.plugins.github.authentication.accounts.GithubAccount
;
import
org.jetbrains.plugins.github.util.GithubAuthData
;
import
org.jetbrains.plugins.github.util.GithubGitHelper
;
import
org.jetbrains.plugins.github.util.GithubGitHelper
;
import
org.jetbrains.plugins.github.util.GithubSettings
;
import
org.jetbrains.plugins.github.util.GithubSettings
;
import
org.jetbrains.plugins.github.util.GithubUtil
;
import
org.jetbrains.plugins.github.util.GithubUtil
;
...
@@ -49,19 +48,17 @@ import static org.junit.Assume.assumeTrue;
...
@@ -49,19 +48,17 @@ import static org.junit.Assume.assumeTrue;
* <li>This is a "platform test case", which means that IDEA [almost] production platform is set up before the test starts.</li>
* <li>This is a "platform test case", which means that IDEA [almost] production platform is set up before the test starts.</li>
* <li>Project base directory is the root of everything. </li>
* <li>Project base directory is the root of everything. </li>
* </ul></p>
* </ul></p>
* <p>All tests inherited from this class are required to have a
login and a password
to access the Github server.
* <p>All tests inherited from this class are required to have a
token
to access the Github server.
* They are set up in Environment variables: <br/>
* They are set up in Environment variables: <br/>
* <code>idea.test.github.host=myHost<br/>
* <code>idea.test.github.host<br/>
* idea.test.github.login1=mylogin1<br/> // test user
* idea.test.github.token1<br/> // token test user
* idea.test.github.login2=mylogin2<br/> // user with configured test repositories
* idea.test.github.token2</code> // token user with configured test repositories
* idea.test.github.password=mypassword</code> // password for test user
* </p>
* </p>
*/
*/
public
abstract
class
GithubTest
extends
GitPlatformTest
{
public
abstract
class
GithubTest
extends
GitPlatformTest
{
@Nullable
protected
GitRepository
myRepository
;
@Nullable
protected
GitRepository
myRepository
;
@NotNull
protected
GithubSettings
myGitHubSettings
;
@NotNull
private
GitHttpAuthTestService
myHttpAuthService
;
@NotNull
private
GitHttpAuthTestService
myHttpAuthService
;
@NotNull
protected
GithubAuthenticationManager
myAuthenticationManager
;
@NotNull
protected
GithubAuthenticationManager
myAuthenticationManager
;
@NotNull
protected
GithubApiTaskExecutor
myApiTaskExecutor
;
@NotNull
protected
GithubApiTaskExecutor
myApiTaskExecutor
;
...
@@ -74,15 +71,6 @@ public abstract class GithubTest extends GitPlatformTest {
...
@@ -74,15 +71,6 @@ public abstract class GithubTest extends GitPlatformTest {
@Nullable
private
String
myToken
;
@Nullable
private
String
myToken
;
@Deprecated
@NotNull
protected
GithubAuthData
myAuth
;
@Deprecated
@NotNull
protected
String
myLogin1
;
@Deprecated
@NotNull
protected
String
myLogin2
;
@Deprecated
@NotNull
protected
String
myPassword
;
protected
void
createProjectFiles
()
{
protected
void
createProjectFiles
()
{
VfsTestUtil
.
createFile
(
projectRoot
,
"file.txt"
,
"file.txt content"
);
VfsTestUtil
.
createFile
(
projectRoot
,
"file.txt"
,
"file.txt content"
);
VfsTestUtil
.
createFile
(
projectRoot
,
"file"
,
"file content"
);
VfsTestUtil
.
createFile
(
projectRoot
,
"file"
,
"file content"
);
...
@@ -117,13 +105,13 @@ public abstract class GithubTest extends GitPlatformTest {
...
@@ -117,13 +105,13 @@ public abstract class GithubTest extends GitPlatformTest {
@NotNull
@NotNull
@Override
@Override
public
String
askPassword
(
@NotNull
String
url
)
{
public
String
askPassword
(
@NotNull
String
url
)
{
return
myAccount
==
null
?
myPassword
:
GithubUtil
.
GIT_AUTH_PASSWORD_SUBSTITUTE
;
return
GithubUtil
.
GIT_AUTH_PASSWORD_SUBSTITUTE
;
}
}
@NotNull
@NotNull
@Override
@Override
public
String
askUsername
(
@NotNull
String
url
)
{
public
String
askUsername
(
@NotNull
String
url
)
{
return
myAccount
==
null
?
myLogin1
:
myToken
;
return
myToken
;
}
}
@Override
@Override
...
@@ -179,19 +167,12 @@ public abstract class GithubTest extends GitPlatformTest {
...
@@ -179,19 +167,12 @@ public abstract class GithubTest extends GitPlatformTest {
super
.
setUp
();
super
.
setUp
();
final
String
host
=
System
.
getenv
(
"idea.test.github.host"
);
final
String
host
=
System
.
getenv
(
"idea.test.github.host"
);
final
String
login1
=
System
.
getenv
(
"idea.test.github.login1"
);
final
String
login2
=
System
.
getenv
(
"idea.test.github.login2"
);
final
String
password
=
System
.
getenv
(
"idea.test.github.password1"
);
final
String
token1
=
System
.
getenv
(
"idea.test.github.token1"
);
final
String
token1
=
System
.
getenv
(
"idea.test.github.token1"
);
final
String
token2
=
System
.
getenv
(
"idea.test.github.token2"
);
final
String
token2
=
System
.
getenv
(
"idea.test.github.token2"
);
// TODO change to assert when a stable Github testing server is ready
// TODO change to assert when a stable Github testing server is ready
assumeNotNull
(
host
);
assumeNotNull
(
host
);
assumeTrue
((
login1
!=
null
&&
password
!=
null
)
||
(
token1
!=
null
&&
token2
!=
null
));
assumeTrue
(
token1
!=
null
&&
token2
!=
null
);
myLogin1
=
login1
;
myLogin2
=
login2
;
myPassword
=
password
;
myAuth
=
GithubAuthData
.
createBasicAuth
(
host
,
login1
,
password
);
myAuthenticationManager
=
GithubAuthenticationManager
.
getInstance
();
myAuthenticationManager
=
GithubAuthenticationManager
.
getInstance
();
myApiTaskExecutor
=
GithubApiTaskExecutor
.
getInstance
();
myApiTaskExecutor
=
GithubApiTaskExecutor
.
getInstance
();
myAccount
=
myAuthenticationManager
.
registerAccount
(
"account1"
,
host
,
token1
);
myAccount
=
myAuthenticationManager
.
registerAccount
(
"account1"
,
host
,
token1
);
...
@@ -201,9 +182,6 @@ public abstract class GithubTest extends GitPlatformTest {
...
@@ -201,9 +182,6 @@ public abstract class GithubTest extends GitPlatformTest {
myUsername
=
myApiTaskExecutor
.
execute
(
myAccount
,
c
->
GithubApiUtil
.
getCurrentUser
(
c
).
getLogin
());
myUsername
=
myApiTaskExecutor
.
execute
(
myAccount
,
c
->
GithubApiUtil
.
getCurrentUser
(
c
).
getLogin
());
myUsername2
=
myApiTaskExecutor
.
execute
(
myAccount2
,
c
->
GithubApiUtil
.
getCurrentUser
(
c
).
getLogin
());
myUsername2
=
myApiTaskExecutor
.
execute
(
myAccount2
,
c
->
GithubApiUtil
.
getCurrentUser
(
c
).
getLogin
());
myGitHubSettings
=
GithubSettings
.
getInstance
();
myGitHubSettings
.
setAuthData
(
myAuth
,
true
);
myHttpAuthService
=
(
GitHttpAuthTestService
)
ServiceManager
.
getService
(
GitHttpAuthService
.
class
);
myHttpAuthService
=
(
GitHttpAuthTestService
)
ServiceManager
.
getService
(
GitHttpAuthService
.
class
);
try
{
try
{
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment