added support for encrypted server passwords

This commit is contained in:
Brian Long 2024-01-23 09:06:17 -05:00
parent a856f9580b
commit 8d634670e1
13 changed files with 52 additions and 52 deletions

View File

@ -17,8 +17,12 @@ package com.inteligr8.maven.aps.modeling.goal;
import java.util.List;
import org.apache.maven.execution.MavenSession;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Component;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.settings.Server;
import org.apache.maven.settings.crypto.DefaultSettingsDecryptionRequest;
import org.apache.maven.settings.crypto.SettingsDecrypter;
import com.inteligr8.alfresco.activiti.ApsClientJerseyConfiguration;
import com.inteligr8.alfresco.activiti.ApsClientJerseyImpl;
@ -58,6 +62,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
@Parameter( property = "aps-model.oauth.tokenUrl", required = false )
protected String oauthTokenUrl;
@Component
private SettingsDecrypter decrypter;
private ApsPublicRestApiJerseyImpl api;
@ -69,10 +76,11 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
*
* @return An APS client configuration.
*/
public ApsClientJerseyConfiguration getApsClientConfiguration() {
public ApsClientJerseyConfiguration getApsClientConfiguration() throws MojoExecutionException {
this.getLog().debug("Configuring APS to URL: " + this.activitiAppBaseUrl);
ApsClientJerseyConfiguration config = new ApsClientJerseyConfiguration();
config.setBaseUrl(this.activitiAppBaseUrl);
switch (this.activitiAppAuthType.toUpperCase()) {
case "BASIC":
this.getLog().info("Configuring APS with BASIC authentication");
@ -82,6 +90,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
this.getLog().warn("The Maven configuration has no server '" + this.activitiAppAuthBasicServerId + "'; continuing with default credentials");
if (creds != null) {
creds = this.decrypter.decrypt(new DefaultSettingsDecryptionRequest(creds))
.getServer();
this.getLog().debug("Username: " + creds.getUsername());
config.setBasicAuthUsername(creds.getUsername());
config.setBasicAuthPassword(creds.getPassword());
@ -95,16 +106,24 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
if ((this.oauthClientServerId != null || this.oauthServerId != null) && clientCreds == null && oauthCreds == null)
this.getLog().warn("The Maven configuration has no server '" + this.oauthClientServerId + "' or '" + this.oauthServerId + "'; continuing without credentials");
this.getLog().debug("OAuth Code: " + this.oauthCode);
config.setOAuthAuthCode(this.oauthCode);
if (this.oauthCode != null) {
this.getLog().debug("OAuth Code: " + this.oauthCode);
config.setOAuthAuthCode(this.oauthCode);
}
if (clientCreds != null) {
creds = this.decrypter.decrypt(new DefaultSettingsDecryptionRequest(clientCreds))
.getServer();
this.getLog().debug("OAuth Client ID: " + clientCreds.getUsername());
config.setOAuthClientId(clientCreds.getUsername());
config.setOAuthClientSecret(clientCreds.getPassword());
}
if (oauthCreds != null) {
creds = this.decrypter.decrypt(new DefaultSettingsDecryptionRequest(oauthCreds))
.getServer();
this.getLog().debug("OAuth Username: " + oauthCreds.getUsername());
config.setOAuthUsername(oauthCreds.getUsername());
config.setOAuthPassword(oauthCreds.getPassword());
@ -123,8 +142,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
* This method constructs and caches the APS API accessor.
*
* @return An APS API instance.
* @throws MojoExecutionException The APS API failed to initialize.
*/
public synchronized ApsPublicRestApiJerseyImpl getApsApi() {
public synchronized ApsPublicRestApiJerseyImpl getApsApi() throws MojoExecutionException {
if (this.api == null) {
ApsClientJerseyConfiguration config = this.getApsClientConfiguration();
ApsClientJerseyImpl apsClient = new ApsClientJerseyImpl(config);
@ -141,8 +161,9 @@ public abstract class ApsAddressibleGoal extends DisablableGoal {
* This method does not cache the result.
*
* @return An APS tenant ID; null only if there are no tenants.
* @throws MojoExecutionException The APS API failed to initialize.
*/
protected Long findTenantId() {
protected Long findTenantId() throws MojoExecutionException {
List<Tenant> tenants = this.getApsApi().getAdminApi().getTenants();
if (tenants == null || tenants.isEmpty())
return null;

View File

@ -15,19 +15,15 @@
package com.inteligr8.maven.aps.modeling.goal;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import com.inteligr8.activiti.model.Datum;
import com.inteligr8.activiti.model.ResultList;
import com.inteligr8.alfresco.activiti.ApsPublicRestApiJerseyImpl;
import com.inteligr8.alfresco.activiti.api.ModelsApi.ModelType;
import com.inteligr8.alfresco.activiti.model.ModelRepresentation;
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
import com.inteligr8.alfresco.activiti.model.Tenant;
/**
* This class adds the APS App name to APS addressibility to extending goals.
@ -43,21 +39,6 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal {
@Parameter( property = "aps-model.appName", required = true )
protected String apsAppName;
/**
* This method makes the appropriate service calls to find the first APS
* tenant ID from the configured APS service.
*
* This method does not cache the result.
*
* @return An APS tenant ID; null only if there are no tenants.
*/
protected Long findTenantId() {
List<Tenant> tenants = this.getApsApi().getAdminApi().getTenants();
if (tenants == null || tenants.isEmpty())
return null;
return tenants.iterator().next().getId();
}
/**
* This method makes the appropriate service calls to find all the APS
* Apps, returning them as a map of names to models.
@ -65,8 +46,9 @@ public abstract class ApsAppAddressibleGoal extends ApsAddressibleGoal {
* This method does not cache the result.
*
* @return A map of APS App names to their model; may be empty; never null.
* @throws MojoExecutionException The APS API failed to initialize.
*/
protected Map<String, ModelRepresentation> buildAppNameMap() {
protected Map<String, ModelRepresentation> buildAppNameMap() throws MojoExecutionException {
ApsPublicRestApiJerseyImpl api = this.getApsApi();
Map<String, ModelRepresentation> apps = new HashMap<>(16);

View File

@ -26,14 +26,12 @@ import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.codehaus.plexus.component.annotations.Component;
import com.inteligr8.activiti.model.Datum;
import com.inteligr8.activiti.model.ResultList;
import com.inteligr8.alfresco.activiti.api.ModelsApi;
import com.inteligr8.alfresco.activiti.model.GroupLight;
import com.inteligr8.alfresco.activiti.model.ModelRepresentation;
import com.inteligr8.alfresco.activiti.model.PermissionLevel;
import com.inteligr8.alfresco.activiti.model.PermissionLight;
import com.inteligr8.alfresco.activiti.model.ResultListDataRepresentation;
import com.inteligr8.alfresco.activiti.model.ShareInfoRequest;
import com.inteligr8.alfresco.activiti.model.SharePermission;
import com.inteligr8.alfresco.activiti.model.Tenant;
@ -108,7 +106,7 @@ public class ApsShareGoal extends ApsAddressibleGoal {
this.shareModels(ModelsApi.ModelType.Form, this.formReaderSet, this.formEditorSet);
}
private void shareModels(ModelsApi.ModelType modelType, Set<String> readers, Set<String> editors) {
private void shareModels(ModelsApi.ModelType modelType, Set<String> readers, Set<String> editors) throws MojoExecutionException {
ResultList<ModelRepresentation> models = this.getApsApi().getModelsApi().get(null, null, modelType.getId(), null);
if (models.getData() == null)
return;
@ -220,7 +218,7 @@ public class ApsShareGoal extends ApsAddressibleGoal {
return params;
}
protected void buildIdentityIndex() {
protected void buildIdentityIndex() throws MojoExecutionException {
List<Tenant> tenants = this.getApsApi().getAdminApi().getTenants();
for (Tenant tenant : tenants) {
List<GroupLight> groups = this.getApsApi().getAdminApi().getGroups(tenant.getId(), true, true);

View File

@ -21,6 +21,7 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugins.annotations.Parameter;
import com.inteligr8.activiti.model.ResultList;
@ -52,12 +53,12 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
@Parameter( property = "aps-model.customEmailTemplateNames", defaultValue = ".*" )
protected String apsCustomEmailTemplateNames;
protected Map<TemplateType, Map<String, ? extends BaseTemplateLight>> findTemplates() {
protected Map<TemplateType, Map<String, ? extends BaseTemplateLight>> findTemplates() throws MojoExecutionException {
Long tenantId = this.findTenantId();
return this.findTemplates(tenantId);
}
protected Map<TemplateType, Map<String, ? extends BaseTemplateLight>> findTemplates(Long tenantId) {
protected Map<TemplateType, Map<String, ? extends BaseTemplateLight>> findTemplates(Long tenantId) throws MojoExecutionException {
Map<TemplateType, Map<String, ? extends BaseTemplateLight>> templates = new HashMap<>(32);
Map<String, ? extends BaseTemplateLight> systemEmailTemplateNames = this.findSystemEmailTemplates(tenantId);
@ -75,7 +76,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
return templates;
}
protected Map<String, ? extends BaseTemplateLight> findSystemEmailTemplates(Long tenantId) {
protected Map<String, ? extends BaseTemplateLight> findSystemEmailTemplates(Long tenantId) throws MojoExecutionException {
this.getLog().debug("Searching for all APS System Email Templates");
List<Pattern> matchingPatterns = this.buildPatterns(this.apsSystemEmailTemplateNames);
@ -94,7 +95,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
return map;
}
protected Map<String, ? extends BaseTemplateLight> findCustomEmailTemplates(Long tenantId) {
protected Map<String, ? extends BaseTemplateLight> findCustomEmailTemplates(Long tenantId) throws MojoExecutionException {
this.getLog().debug("Searching for all APS Custom Email Templates");
List<Pattern> matchingPatterns = this.buildPatterns(this.apsCustomEmailTemplateNames);
@ -120,7 +121,7 @@ public abstract class ApsTemplateAddressibleGoal extends ApsAddressibleGoal {
return map;
}
protected Map<String, ? extends BaseTemplateLight> findDocumentTemplates(Long tenantId) {
protected Map<String, ? extends BaseTemplateLight> findDocumentTemplates(Long tenantId) throws MojoExecutionException {
List<Pattern> matchingPatterns = this.buildPatterns(this.apsDocumentTemplateNames);
Map<String, DocumentTemplateLight> map = new HashMap<>();
int pageSize = 50;

View File

@ -56,7 +56,7 @@ public class DownloadAppGoal extends ApsAppAddressibleGoal {
try {
FileUtils.copyFile(appZip, toAppZip);
} catch (IOException ie) {
throw new MojoExecutionException("The downloaded APS App could not be saved", ie);
throw new MojoFailureException("The downloaded APS App could not be saved", ie);
}
}
@ -69,7 +69,7 @@ public class DownloadAppGoal extends ApsAppAddressibleGoal {
}
}
private File downloadApp(long appId) {
private File downloadApp(long appId) throws MojoExecutionException {
ApsPublicRestApiJerseyImpl api = this.getApsApi();
this.getLog().debug("Downloading APS App: " + appId);
return api.getAppDefinitionsApi().export(appId);

View File

@ -31,7 +31,6 @@ import org.codehaus.plexus.component.annotations.Component;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.inteligr8.alfresco.activiti.model.BaseTemplateLight;
import com.inteligr8.alfresco.activiti.model.DocumentTemplateLight;
import com.inteligr8.alfresco.activiti.model.EmailTemplate;
import com.inteligr8.maven.aps.modeling.normalizer.ApsTemplateJsonNormalizer;
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
@ -119,7 +118,7 @@ public class DownloadTemplateGoal extends ApsTemplateAddressibleGoal {
}
}
} catch (IOException ie) {
throw new MojoExecutionException("The downloaded APS templates could not be saved", ie);
throw new MojoFailureException("The downloaded APS templates could not be saved", ie);
}
}

View File

@ -63,7 +63,7 @@ public class PackAppGoal extends ApsAppGoal {
try {
this.pack(appDirectory, targetFile);
} catch (IOException ie) {
throw new MojoExecutionException("The APS App could not be packed", ie);
throw new MojoFailureException("The APS App could not be packed", ie);
}
}

View File

@ -50,7 +50,7 @@ public class PublishAppGoal extends ApsAppAddressibleGoal {
try {
this.publishApp(appId);
} catch (IOException ie) {
throw new MojoExecutionException("The APS App could not be published", ie);
throw new MojoFailureException("The APS App could not be published", ie);
}
}

View File

@ -74,7 +74,7 @@ public class TranslateAppGoal extends ApsAppAddressibleGoal {
ApsAppCrawler crawler = new ApsAppCrawler(this.apsAppName, apsAppDirectory, true);
crawler.execute(translator);
} catch (IOException ie) {
throw new MojoExecutionException("An I/O issue occurred", ie);
throw new MojoFailureException("An I/O issue occurred", ie);
} catch (IllegalArgumentException iae) {
throw new MojoExecutionException("The input is not supported", iae);
} catch (IllegalStateException ise) {

View File

@ -69,7 +69,7 @@ public class TranslateTemplateGoal extends ApsAddressibleGoal {
ApsTemplateCrawler crawler = new ApsTemplateCrawler(this.finalDirectory, true);
crawler.execute(translator);
} catch (IOException ie) {
throw new MojoExecutionException("An I/O issue occurred", ie);
throw new MojoFailureException("An I/O issue occurred", ie);
} catch (IllegalArgumentException iae) {
throw new MojoExecutionException("The input is not supported", iae);
} catch (IllegalStateException ise) {

View File

@ -90,7 +90,7 @@ public class UnpackAppGoal extends ApsAppGoal {
try {
this.unpack(sourceFile, appDirectory);
} catch (IOException ie) {
throw new MojoExecutionException("The downloaded APS App could not be unpacked", ie);
throw new MojoFailureException("The downloaded APS App could not be unpacked", ie);
}
if (this.reformat)
@ -101,7 +101,7 @@ public class UnpackAppGoal extends ApsAppGoal {
ApsAppCrawler crawler = new ApsAppCrawler(this.apsAppName, appDirectory, true);
crawler.execute(normalizer);
} catch (IOException ie) {
throw new MojoExecutionException("An I/O issue occurred", ie);
throw new MojoFailureException("An I/O issue occurred", ie);
}
}
}
@ -223,7 +223,7 @@ public class UnpackAppGoal extends ApsAppGoal {
file.delete();
}
} catch (TransformerException | SAXException | IOException e) {
throw new MojoFailureException("The following file faild to be reformatted: " + file, e);
throw new MojoFailureException("The following file failed to be reformatted: " + file, e);
}
}
}

View File

@ -65,7 +65,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
try {
this.uploadApp(appModel, sourceFile);
} catch (IOException ie) {
throw new MojoExecutionException("The APS App could not be uploaded", ie);
throw new MojoFailureException("The APS App could not be uploaded", ie);
}
}
@ -87,7 +87,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
return sourceFile;
}
private void uploadApp(ModelRepresentation appModel, File appZip) throws IOException, MojoExecutionException {
private void uploadApp(ModelRepresentation appModel, File appZip) throws IOException, MojoExecutionException, MojoFailureException {
ApsPublicRestApiJerseyImpl api = this.getApsApi();
FileInputStream fistream = new FileInputStream(appZip);
@ -103,7 +103,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
this.getLog().info("Uploading & publishing new APS App: " + this.apsAppName);
AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(multipart);
if (Boolean.TRUE.equals(appDefUpdate.getError()))
throw new MojoExecutionException(appDefUpdate.getErrorDescription());
throw new MojoFailureException(appDefUpdate.getErrorDescription());
}
} else {
if (this.dryRun) {
@ -121,7 +121,7 @@ public class UploadAppGoal extends ApsAppAddressibleGoal {
this.getLog().info("Uploading, versioning, & publishing APS App: " + this.apsAppName + " (" + appModel.getId() + ")");
AppDefinitionUpdateResultRepresentation appDefUpdate = api.getAppDefinitionsJerseyApi().publishApp(appModel.getId(), multipart);
if (Boolean.TRUE.equals(appDefUpdate.getError()))
throw new MojoExecutionException(appDefUpdate.getErrorDescription());
throw new MojoFailureException(appDefUpdate.getErrorDescription());
}
} else {
if (this.dryRun) {

View File

@ -30,7 +30,6 @@ import org.codehaus.plexus.component.annotations.Component;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.inteligr8.alfresco.activiti.model.DocumentTemplateLight;
import com.inteligr8.alfresco.activiti.model.EmailTemplate;
import com.inteligr8.alfresco.activiti.model.EmailTemplateLight;
import com.inteligr8.alfresco.activiti.model.FileMultipartJersey;
import com.inteligr8.maven.aps.modeling.util.ModelUtil;
@ -153,9 +152,9 @@ public class UploadTemplateGoal extends ApsAddressibleGoal {
}
}
} catch (JsonProcessingException jpe) {
throw new MojoExecutionException("The APS templates JSON files could not be parsed", jpe);
throw new MojoFailureException("The APS templates JSON files could not be parsed", jpe);
} catch (IOException ie) {
throw new MojoExecutionException("The APS templates could not be uploaded", ie);
throw new MojoFailureException("The APS templates could not be uploaded", ie);
} catch (ParseException pe) {
throw new MojoFailureException("This should never happen", pe);
}