Commit 8d634670 authored by Brian Long's avatar Brian Long
Browse files

added support for encrypted server passwords

parent a856f958
Loading
Loading
Loading
Loading
+26 −5
Original line number Diff line number Diff line
@@ -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;
@@ -59,6 +63,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");
				
				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;
+2 −20
Original line number Diff line number Diff line
@@ -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);
+2 −4
Original line number Diff line number Diff line
@@ -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);
+6 −5
Original line number Diff line number Diff line
@@ -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;
+2 −2
Original line number Diff line number Diff line
@@ -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);
Loading