Skip to content

Commit

Permalink
Us#639004 support PAT in jira server (#60)
Browse files Browse the repository at this point in the history
* US#639004_Support_PAT_in_Jira_Server

* US#639004 remove iml file

* US#639004 correct typo

* US#639004 increase connector version to 3.2

---------

Co-authored-by: Etienne Canaud <[email protected]>
  • Loading branch information
etiennec and Etienne Canaud authored May 30, 2023
1 parent 936de1f commit 9b907d2
Show file tree
Hide file tree
Showing 10 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ public class JIRAConstants {

public static final String KEY_ADMIN_PASSWORD = "adminPassword";

public static final String KEY_ADMIN_PAT = "adminPAT";

public static final String KEY_USE_ADMIN_PASSWORD_TO_MAP_TASKS = "useAdminPasswordToMapTasks";

public static final String KEY_ALLOW_WILDCARD_PROJECT_MAPPING = "allowWildcardProjectMapping";
Expand All @@ -35,6 +37,8 @@ public class JIRAConstants {

public static final String KEY_PASSWORD = "password";

public static final String KEY_PAT = "pat";

public static final String KEY_TASK_STATUS_IN_PLANNING = "statusInPlanning";
public static final String KEY_TASK_STATUS_READY = "statusReady";
public static final String KEY_TASK_STATUS_ACTIVE = "statusActive";
Expand Down Expand Up @@ -66,6 +70,8 @@ public class JIRAConstants {
public static final String LABEL_WORK_PLAN_OPTIONS = "jira_work_plan_options";
public static final String LABEL_REQUEST_AGILE_OPTIONS = "jira_request_agile_options";


public static final String KEY_FORCE_USER_PAT_FOR_WP_AND_TS = "jira_force_user_pat_wp_ts";
public static final String SELECT_USER_DATA_STORY_POINTS = "jira_user_data_story_points";

public static final String SELECT_USER_DATA_AGGREGATED_STORY_POINTS = "jira_user_data_aggregated_story_points";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public String getExternalApplicationVersionIndication() {

@Override
public String getConnectorVersion() {
return "3.1";
return "3.2";
}

@Override
Expand All @@ -50,14 +50,18 @@ public List<Field> getDriverConfigurationFields() {
new PlainText(JIRAConstants.KEY_PROXY_PORT, "PROXY_PORT", "", false),
new LineBreaker(),
new LabelText("", "ADMIN_INFO_FOR_EPIC_AND_AGILE_DATA", "block", false),
new PlainText(JIRAConstants.KEY_ADMIN_USERNAME, "ADMIN_USERNAME", "", true),
new PasswordText(JIRAConstants.KEY_ADMIN_PASSWORD, "ADMIN_PASSWORD", "", true),
new PlainText(JIRAConstants.KEY_ADMIN_USERNAME, "ADMIN_USERNAME", "", false),
new PasswordText(JIRAConstants.KEY_ADMIN_PASSWORD, "ADMIN_PASSWORD", "", false),
new LineBreaker(),
new PasswordText(JIRAConstants.KEY_ADMIN_PAT, "ADMIN_PAT", "", false),
new LineBreaker(),
new LabelText(JIRAConstants.LABEL_REQUEST_AGILE_OPTIONS, "REQUEST_AGILE_OPTIONS","Request Mapping (Request-Agile):", false),
new CheckBox(JIRAConstants.KEY_ALLOW_WILDCARD_PROJECT_MAPPING, "KEY_ALLOW_WILDCARD_PROJECT_MAPPING", false),
new LineBreaker(),
new LabelText(JIRAConstants.LABEL_WORK_PLAN_OPTIONS, "WORK_PLAN_OPTIONS",
"User Data Options:", true),
new CheckBox(JIRAConstants.KEY_FORCE_USER_PAT_FOR_WP_AND_TS, "KEY_FORCE_USER_PAT_FOR_WP_AND_TS", false),
new LineBreaker(),
getUserDataDDL(JIRAConstants.SELECT_USER_DATA_STORY_POINTS, "USER_DATA_STORY_POINTS"),
getUserDataDDL(JIRAConstants.SELECT_USER_DATA_AGGREGATED_STORY_POINTS, "USER_DATA_AGGREGATED_STORY_POINTS"),
new LineBreaker(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
BASE_URL = Base URL
PROXY_HOST = Proxy Host
PROXY_PORT = Proxy Port
ADMIN_INFO_FOR_EPIC_AND_AGILE_DATA = Admin Account information (Portfolio Epics/Agile Data sync/Work plan sync)
ADMIN_INFO_FOR_EPIC_AND_AGILE_DATA = Admin Account information - Must include either Username/Password or Personal Access Token (PAT)
ADMIN_USERNAME = Admin Username
ADMIN_PASSWORD = Admin Password
ADMIN_PAT = Admin PAT (Personal Access Token)
USERNAME = Username
PASSWORD = Password
PAT = PAT (Personal Access Token)
JIRA_PROJECT = Project
IMPORT_SELECTION = Import Selection
IMPORT_SELECTION_DETAILS = Import Selection Details
Expand Down Expand Up @@ -51,6 +53,7 @@ WORK_PLAN_OPTIONS = Work Plan Integration options
USER_DATA_STORY_POINTS = Sync Story Points to (PPM 9.42+ only)
USER_DATA_AGGREGATED_STORY_POINTS = Sync Epic content Story Points to (PPM 9.42+ only)
REQUEST_AGILE_OPTIONS = Request Mapping (Request-Agile):
KEY_FORCE_USER_PAT_FOR_WP_AND_TS = Users must use a PAT (Personal Access Token) instead of username/password on Work plan & Timesheet screens
KEY_USE_ADMIN_PASSWORD_TO_MAP_TASKS = Use Admin Account to map work plan tasks
KEY_IMPORT_ASSIGNED_USERS_TO_TASKS = Import Jira assigned Users to work plan tasks when emails match
KEY_ALLOW_WILDCARD_PROJECT_MAPPING = Enable " * " Jira project mapping in request agile mapping (PPM 10.0.1+ Only)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public static JIRAService get(ValueSet config) {
IRestConfig adminRestConfig = new JIRARestConfig();
adminRestConfig.setProxy(config.get(JIRAConstants.KEY_PROXY_HOST), config.get(JIRAConstants.KEY_PROXY_PORT));
adminRestConfig.setBasicAuthorizationCredentials(config.get(JIRAConstants.KEY_ADMIN_USERNAME),
config.get(JIRAConstants.KEY_ADMIN_PASSWORD));
config.get(JIRAConstants.KEY_ADMIN_PASSWORD), config.get(JIRAConstants.KEY_ADMIN_PAT));
JiraRestWrapper adminWrapper = new JiraRestWrapper(adminRestConfig);

IRestConfig userRestConfig = new JIRARestConfig();
userRestConfig.setProxy(config.get(JIRAConstants.KEY_PROXY_HOST), config.get(JIRAConstants.KEY_PROXY_PORT));
userRestConfig.setBasicAuthorizationCredentials(config.get(JIRAConstants.KEY_USERNAME),
config.get(JIRAConstants.KEY_PASSWORD));
config.get(JIRAConstants.KEY_PASSWORD), config.get(JIRAConstants.KEY_PAT));
JiraRestWrapper userWrapper = new JiraRestWrapper(userRestConfig);

JIRAService service = new JIRAService(config.get(JIRAConstants.KEY_BASE_URL), adminWrapper, userWrapper);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -391,14 +391,24 @@ public List<Field> getMappingConfigurationFields(final ValueSet values) {

final LocalizationProvider lp = Providers.getLocalizationProvider(JIRAIntegrationConnector.class);

return Arrays.asList(new Field[] {new PlainText(JIRAConstants.KEY_USERNAME, "USERNAME", "", true),
new PasswordText(JIRAConstants.KEY_PASSWORD, "PASSWORD", "", true),
List<Field> fields = new ArrayList<>();

final boolean usePat = values.getBoolean(JIRAConstants.KEY_FORCE_USER_PAT_FOR_WP_AND_TS, false);

if (!usePat) {
fields.add(new PlainText(JIRAConstants.KEY_USERNAME, "USERNAME", "", false));
fields.add(new PasswordText(JIRAConstants.KEY_PASSWORD, "PASSWORD", "", false));
} else {
fields.add(new PasswordText(JIRAConstants.KEY_PAT, "PAT", "", false));
}

fields.addAll(Arrays.asList(new Field[] {
new LineBreaker(),
new DynamicDropdown(JIRAConstants.KEY_JIRA_PROJECT, "JIRA_PROJECT", JIRAConstants.TS_ALL_PROJECTS, "", false) {

@Override
public List<String> getDependencies() {
return Arrays.asList(new String[] {JIRAConstants.KEY_USERNAME, JIRAConstants.KEY_PASSWORD});
return Arrays.asList(new String[] {JIRAConstants.KEY_USERNAME, JIRAConstants.KEY_PASSWORD, JIRAConstants.KEY_PAT});
}

@Override
Expand Down Expand Up @@ -541,7 +551,9 @@ public FieldAppearance getFieldAppearance(ValueSet values) {
}
}
}
});
}));

return fields;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,19 @@ public List<Field> getMappingConfigurationFields(WorkPlanIntegrationContext cont

final boolean useAdminPassword = values.getBoolean(JIRAConstants.KEY_USE_ADMIN_PASSWORD_TO_MAP_TASKS, false);

final boolean usePat = values.getBoolean(JIRAConstants.KEY_FORCE_USER_PAT_FOR_WP_AND_TS, false);

List<Field> fields = new ArrayList<Field>();

final JIRAService service = JIRAServiceProvider.get(values).useAdminAccount();

if (!useAdminPassword) {
fields.add(new PlainText(JIRAConstants.KEY_USERNAME, "USERNAME", "", true));
fields.add(new PasswordText(JIRAConstants.KEY_PASSWORD, "PASSWORD", "", true));
if (!usePat) {
fields.add(new PlainText(JIRAConstants.KEY_USERNAME, "USERNAME", "", false));
fields.add(new PasswordText(JIRAConstants.KEY_PASSWORD, "PASSWORD", "", false));
} else {
fields.add(new PasswordText(JIRAConstants.KEY_PAT, "PAT", "", false));
}
fields.add(new LineBreaker());
}

Expand Down Expand Up @@ -84,7 +90,7 @@ public List<Field> getMappingConfigurationFields(WorkPlanIntegrationContext cont

@Override
public List<String> getDependencies() {
return Arrays.asList(new String[] {JIRAConstants.KEY_USERNAME, JIRAConstants.KEY_PASSWORD});
return Arrays.asList(new String[] {JIRAConstants.KEY_USERNAME, JIRAConstants.KEY_PASSWORD, JIRAConstants.KEY_PAT});
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public interface IRestConfig {

ClientConfig setProxy(String proxyHost, String proxyPort);

void setBasicAuthorizationCredentials(String username, String password);
void setBasicAuthorizationCredentials(String username, String password, String pat);

String getBasicAuthorizationToken();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package com.ppm.integration.agilesdk.connector.jira.rest.util;

import org.apache.commons.codec.binary.Base64;
import org.apache.commons.lang.StringUtils;
import org.apache.wink.client.ClientConfig;

public class JIRARestConfig implements IRestConfig {
Expand Down Expand Up @@ -36,10 +37,13 @@ public String getBasicAuthorizationToken() {
}

@Override
public void setBasicAuthorizationCredentials(String username, String password) {

String basicToken = new String(Base64.encodeBase64((username + ":" + password).getBytes()));
basicAuthenticationToken = RestConstants.BASIC_AUTHENTICATION_PREFIX + basicToken;
public void setBasicAuthorizationCredentials(String username, String password, String pat) {
if (!StringUtils.isBlank(pat)) {
basicAuthenticationToken = RestConstants.BEARER_AUTHENTICATION_PREFIX + pat;
} else {
String basicToken = new String(Base64.encodeBase64((username + ":" + password).getBytes()));
basicAuthenticationToken = RestConstants.BASIC_AUTHENTICATION_PREFIX + basicToken;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,6 @@
public class RestConstants {
public static final String BASIC_AUTHENTICATION_PREFIX = "Basic ";

public static final String BEARER_AUTHENTICATION_PREFIX = "Bearer ";

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ public JIRAService resetUserCredentials(ValueSet config) {
IRestConfig userRestConfig = new JIRARestConfig();
userRestConfig.setProxy(config.get(JIRAConstants.KEY_PROXY_HOST), config.get(JIRAConstants.KEY_PROXY_PORT));
userRestConfig.setBasicAuthorizationCredentials(config.get(JIRAConstants.KEY_USERNAME),
config.get(JIRAConstants.KEY_PASSWORD));
config.get(JIRAConstants.KEY_PASSWORD), config.get(JIRAConstants.KEY_PAT));
userWrapper = new JiraRestWrapper(userRestConfig);
return this;
}
Expand Down

0 comments on commit 9b907d2

Please sign in to comment.