Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up HTTP authentication reference and Update constructors #562

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 26 additions & 40 deletions src/main/java/hudson/plugins/jira/JiraSite.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,7 +263,8 @@ public JiraSite(
boolean updateJiraIssueForAllStatus,
@CheckForNull String groupVisibility,
@CheckForNull String roleVisibility,
boolean useHTTPAuth) {
boolean useHTTPAuth,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's remove all deprecated constructors, it they are there for quite a while.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revision finished, waiting for your review!

boolean useBearerAuth) {
this(
url,
alternativeUrl,
Expand All @@ -275,6 +276,7 @@ public JiraSite(
groupVisibility,
roleVisibility,
useHTTPAuth,
useBearerAuth,
DEFAULT_TIMEOUT,
DEFAULT_READ_TIMEOUT,
DEFAULT_THREAD_EXECUTOR_NUMBER);
Expand All @@ -293,7 +295,8 @@ public JiraSite(
boolean updateJiraIssueForAllStatus,
@CheckForNull String groupVisibility,
@CheckForNull String roleVisibility,
boolean useHTTPAuth) {
boolean useHTTPAuth,
boolean useBearerAuth) {
this(
url,
alternativeUrl,
Expand All @@ -304,7 +307,8 @@ public JiraSite(
updateJiraIssueForAllStatus,
groupVisibility,
roleVisibility,
useHTTPAuth);
useHTTPAuth,
useBearerAuth);
}

// Deprecate the previous constructor but leave it in place for Java-level compatibility.
Expand All @@ -319,7 +323,8 @@ public JiraSite(
boolean updateJiraIssueForAllStatus,
String groupVisibility,
String roleVisibility,
boolean useHTTPAuth) {
boolean useHTTPAuth,
boolean useBearerAuth) {
this(
url,
alternativeUrl,
Expand All @@ -331,6 +336,7 @@ public JiraSite(
groupVisibility,
roleVisibility,
useHTTPAuth,
useBearerAuth,
DEFAULT_TIMEOUT,
DEFAULT_READ_TIMEOUT,
DEFAULT_THREAD_EXECUTOR_NUMBER);
Expand Down Expand Up @@ -359,6 +365,7 @@ public JiraSite(
String groupVisibility,
String roleVisibility,
boolean useHTTPAuth,
boolean useBearerAuth,
int timeout,
int readTimeout,
int threadExecutorNumber) {
Expand All @@ -383,6 +390,7 @@ public JiraSite(
setGroupVisibility(groupVisibility);
setRoleVisibility(roleVisibility);
this.useHTTPAuth = useHTTPAuth;
this.useBearerAuth = useBearerAuth;
this.jiraSession = null;
}

Expand All @@ -408,6 +416,7 @@ public JiraSite(
String groupVisibility,
String roleVisibility,
boolean useHTTPAuth,
boolean useBearerAuth,
int timeout,
int readTimeout,
int threadExecutorNumber) {
Expand All @@ -422,45 +431,12 @@ public JiraSite(
groupVisibility,
roleVisibility,
useHTTPAuth,
useBearerAuth,
timeout,
readTimeout,
threadExecutorNumber);
}

// Deprecate the previous constructor but leave it in place for Java-level compatibility.
@Deprecated
public JiraSite(
URL url,
URL alternativeUrl,
StandardUsernamePasswordCredentials credentials,
boolean supportsWikiStyleComment,
boolean recordScmChanges,
String userPattern,
boolean updateJiraIssueForAllStatus,
String groupVisibility,
String roleVisibility,
boolean useHTTPAuth,
int timeout,
int readTimeout,
int threadExecutorNumber,
boolean useBearerAuth) {
this(
url,
alternativeUrl,
credentials == null ? null : credentials.getId(),
supportsWikiStyleComment,
recordScmChanges,
userPattern,
updateJiraIssueForAllStatus,
groupVisibility,
roleVisibility,
useHTTPAuth,
timeout,
readTimeout,
threadExecutorNumber);
this.useBearerAuth = useBearerAuth;
}

static URL toURL(String url) {
url = Util.fixEmptyAndTrim(url);
if (url == null) {
Expand Down Expand Up @@ -647,7 +623,8 @@ protected Object readResolve() {
updateJiraIssueForAllStatus,
groupVisibility,
roleVisibility,
useHTTPAuth);
useHTTPAuth,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@olamy I think this whole if migration block is there for a long time as well, everyone should have already migrated those credentials so I propose to drop this whole if as well?

useBearerAuth);
} else {
jiraSite = new JiraSite(
url,
Expand All @@ -660,6 +637,7 @@ protected Object readResolve() {
groupVisibility,
roleVisibility,
useHTTPAuth,
useBearerAuth,
timeout,
readTimeout,
threadExecutorNumber);
Expand Down Expand Up @@ -1355,6 +1333,7 @@ public FormValidation doValidate(
.withGroupVisibility(groupVisibility)
.withRoleVisibility(roleVisibility)
.withUseHTTPAuth(useHTTPAuth)
.withUseBearerAuth(useBearerAuth)
.build();

if (threadExecutorNumber < 1) {
Expand Down Expand Up @@ -1417,6 +1396,7 @@ static class Builder {
private String groupVisibility;
private String roleVisibility;
private boolean useHTTPAuth;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Drop this as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Revision finished, waiting for your review!

private boolean useBearerAuth;

public Builder withMainURL(URL mainURL) {
this.mainURL = mainURL;
Expand Down Expand Up @@ -1468,6 +1448,11 @@ public Builder withUseHTTPAuth(boolean useHTTPAuth) {
return this;
}

public Builder withUseBearerAuth(boolean useBearerAuth) {
this.useBearerAuth = useBearerAuth;
return this;
}

public JiraSite build() {
return new JiraSite(
mainURL,
Expand All @@ -1479,7 +1464,8 @@ public JiraSite build() {
updateJiraIssueForAllStatus,
groupVisibility,
roleVisibility,
useHTTPAuth);
useHTTPAuth,
useBearerAuth);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@
<f:entry title="Link URL" field="alternativeUrl" description="${%site.alternativeUrl}">
<f:textbox />
</f:entry>
<f:invisibleEntry>
<f:checkbox title="${%Use HTTP authentication instead of normal login}" field="useHTTPAuth" />
</f:invisibleEntry>
<f:entry description="${%site.useBearerAuth}">
<f:checkbox title="${%Use Bearer authentication instead of Basic authentication}" field="useBearerAuth" />
</f:entry>
Expand Down Expand Up @@ -53,7 +50,7 @@
</f:entry>
<f:entry>
<f:validateButton title="${%Validate Settings}"
method="validate" with="url,credentialsId,groupVisibility,roleVisibility,useHTTPAuth,alternativeUrl,timeout,readTimeout,threadExecutorNumber,useBearerAuth" />
method="validate" with="url,credentialsId,groupVisibility,roleVisibility,alternativeUrl,timeout,readTimeout,threadExecutorNumber,useBearerAuth" />
</f:entry>
<f:entry title="">
<div align="right">
Expand Down
17 changes: 12 additions & 5 deletions src/test/java/hudson/plugins/jira/JiraSiteTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ public void createSessionWithProvidedCredentials() {
false,
null,
null,
true,
true);
site.setTimeout(1);
JiraSession session = site.getSession(null);
Expand All @@ -93,6 +94,7 @@ public void createSessionWithGlobalCredentials() {
false,
null,
null,
true,
true);
site.setTimeout(1);
JiraSession session = site.getSession(mock(Job.class));
Expand All @@ -112,6 +114,7 @@ public void createSessionReturnsNullIfCredentialsIsNull() {
false,
null,
null,
true,
true);
site.setTimeout(1);
JiraSession session = site.getSession(null);
Expand All @@ -122,7 +125,7 @@ public void createSessionReturnsNullIfCredentialsIsNull() {
@Test
public void deserializeMigrateCredentials() throws MalformedURLException {
JiraSiteOld old = new JiraSiteOld(
validPrimaryUrl, null, ANY_USER, ANY_PASSWORD, false, false, null, false, null, null, true);
validPrimaryUrl, null, ANY_USER, ANY_PASSWORD, false, false, null, false, null, null, true, true);

XStream2 xStream2 = new XStream2();
String xml = xStream2.toXML(old);
Expand Down Expand Up @@ -162,7 +165,7 @@ public void deserializeNormal() throws IOException {
new UsernamePasswordCredentialsImpl(CredentialsScope.SYSTEM, null, null, ANY_USER, ANY_PASSWORD);
CredentialsProvider.lookupStores(j.jenkins).iterator().next().addDomain(domain, c);

JiraSite site = new JiraSite(exampleOrg, null, c.getId(), false, false, null, false, null, null, true);
JiraSite site = new JiraSite(exampleOrg, null, c.getId(), false, false, null, false, null, null, true, true);

XStream2 xStream2 = new XStream2();
String xml = xStream2.toXML(site);
Expand All @@ -178,7 +181,8 @@ public void deserializeNormal() throws IOException {
@WithoutJenkins
@Test
public void deserializeWithoutCredentials() {
JiraSite site = new JiraSite(exampleOrg, null, (String) null, false, false, null, false, null, null, true);
JiraSite site =
new JiraSite(exampleOrg, null, (String) null, false, false, null, false, null, null, true, true);

XStream2 xStream2 = new XStream2();
String xml = xStream2.toXML(site);
Expand Down Expand Up @@ -207,7 +211,8 @@ private static class JiraSiteOld extends JiraSite {
boolean updateJiraIssueForAllStatus,
String groupVisibility,
String roleVisibility,
boolean useHTTPAuth) {
boolean useHTTPAuth,
boolean useBearerAuth) {
super(
url,
alternativeUrl,
Expand All @@ -218,7 +223,8 @@ private static class JiraSiteOld extends JiraSite {
updateJiraIssueForAllStatus,
groupVisibility,
roleVisibility,
useHTTPAuth);
useHTTPAuth,
useBearerAuth);
this.userName = userName;
this.password = Secret.fromString(password);
}
Expand All @@ -237,6 +243,7 @@ public void alternativeURLNotNull() {
false,
null,
null,
true,
true);
assertNotNull(site.getAlternativeUrl());
assertEquals(exampleOrg, site.getAlternativeUrl());
Expand Down