-
-
Notifications
You must be signed in to change notification settings - Fork 295
Expand file tree
/
Copy pathJiraSessionFactory.java
More file actions
60 lines (52 loc) · 2.51 KB
/
JiraSessionFactory.java
File metadata and controls
60 lines (52 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package hudson.plugins.jira;
import com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler;
import com.cloudbees.plugins.credentials.common.StandardUsernamePasswordCredentials;
import hudson.plugins.jira.JiraSite.ExtendedAsynchronousJiraRestClientFactory;
import hudson.plugins.jira.auth.BearerHttpAuthenticationHandler;
import hudson.plugins.jira.extension.ExtendedJiraRestClient;
import java.net.URI;
/**
* Jira Session factory implementation
*
* @author Elia Bracci
*/
public class JiraSessionFactory {
/**
* This method takes as parameters the JiraSite class, the jira URI and
* credentials and returns a JiraSession with Basic authentication if
* useBearerAuth is set to false, otherwise it returns a JiraSession with Bearer
* authentication if useBearerAuth is set to true.
*
* @param jiraSite jiraSite class
* @param uri jira uri
* @param credentials Jenkins credentials
* @return JiraSession instance
*/
public static JiraSession create(JiraSite jiraSite, URI uri, StandardUsernamePasswordCredentials credentials) {
ExtendedJiraRestClient jiraRestClient;
JiraRestService jiraRestService;
if (jiraSite.isUseBearerAuth()) {
BearerHttpAuthenticationHandler bearerHttpAuthenticationHandler = new BearerHttpAuthenticationHandler(
credentials.getPassword().getPlainText());
jiraRestClient = new ExtendedAsynchronousJiraRestClientFactory()
.create(uri, bearerHttpAuthenticationHandler, jiraSite.getHttpClientOptions());
jiraRestService = new JiraRestService(
uri, jiraRestClient, credentials.getPassword().getPlainText(), jiraSite.getReadTimeout());
} else {
jiraRestClient = new ExtendedAsynchronousJiraRestClientFactory()
.create(
uri,
new BasicHttpAuthenticationHandler(
credentials.getUsername(),
credentials.getPassword().getPlainText()),
jiraSite.getHttpClientOptions());
jiraRestService = new JiraRestService(
uri,
jiraRestClient,
credentials.getUsername(),
credentials.getPassword().getPlainText(),
jiraSite.getReadTimeout());
}
return new JiraSession(jiraSite, jiraRestService, jiraSite.getMaxIssuesFromJqlSearch());
}
}