Search in sources :

Example 1 with SubversionFile

use of org.gluu.oxtrust.model.SubversionFile in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method getConfigurationFilesForSubversion.

public List<SubversionFile> getConfigurationFilesForSubversion(List<GluuSAMLTrustRelationship> trustRelationships) {
    if (appConfiguration.getShibboleth3IdpRootDir() == null) {
        throw new InvalidConfigurationException("Failed to create SubversionFile file due to undefined IDP root folder");
    }
    String idpConfFolder = getIdpConfDir();
    String idpMetadataFolder = appConfiguration.getShibboleth3IdpRootDir() + File.separator + SHIB3_IDP_METADATA_FOLDER + File.separator;
    String idpMetadataCredentialsFolder = appConfiguration.getShibboleth3IdpRootDir() + File.separator + SHIB3_IDP_METADATA_CREDENTIALS_FOLDER + File.separator;
    String spConfFolder = appConfiguration.getShibboleth3SpConfDir() + File.separator;
    List<SubversionFile> subversionFiles = new ArrayList<SubversionFile>();
    subversionFiles.add(new SubversionFile(SHIB3_IDP, idpConfFolder + SHIB3_IDP_ATTRIBUTE_RESOLVER_FILE));
    subversionFiles.add(new SubversionFile(SHIB3_IDP, idpConfFolder + SHIB3_IDP_ATTRIBUTE_FILTER_FILE));
    subversionFiles.add(new SubversionFile(SHIB3_IDP, idpConfFolder + SHIB3_IDP_RELYING_PARTY_FILE));
    subversionFiles.add(new SubversionFile(SHIB3_SP, spConfFolder + SHIB3_SP_ATTRIBUTE_MAP_FILE));
    subversionFiles.add(new SubversionFile(SHIB3_SP, spConfFolder + SHIB3_SP_SHIBBOLETH2_FILE));
    for (GluuSAMLTrustRelationship trustRelationship : trustRelationships) {
        if (trustRelationship.getContainerFederation() == null) {
            subversionFiles.add(new SubversionFile(SHIB3_IDP + File.separator + SHIB3_IDP_METADATA_FOLDER, idpMetadataFolder + trustRelationship.getSpMetaDataFN()));
        }
        if (trustRelationship.getMetadataFilters().containsKey("signatureValidation")) {
            subversionFiles.add(new SubversionFile(SHIB3_IDP + File.separator + SHIB3_IDP_METADATA_CREDENTIALS_FOLDER, idpMetadataCredentialsFolder + StringHelper.removePunctuation(trustRelationship.getInum())));
        }
    }
    return subversionFiles;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) ArrayList(java.util.ArrayList) SubversionFile(org.gluu.oxtrust.model.SubversionFile) InvalidConfigurationException(org.xdi.util.exception.InvalidConfigurationException)

Example 2 with SubversionFile

use of org.gluu.oxtrust.model.SubversionFile in project oxTrust by GluuFederation.

the class SubversionService method commitShibboleth3ConfigurationFiles.

public boolean commitShibboleth3ConfigurationFiles(GluuOrganization organization, List<SubversionFile> newSubversionFiles, List<SubversionFile> removeSubversionFiles, String svnComment) {
    // Retrieve properties and derive applianceSvnHome
    String svnUrl = appConfiguration.getSvnConfigurationStoreRoot();
    String inumFN = StringHelper.removePunctuation(appConfiguration.getApplianceInum());
    String svnPassword = appConfiguration.getSvnConfigurationStorePassword();
    String applianceSvnHomePath = String.format("%s/%s", baseSvnDir, inumFN);
    if (StringHelper.isEmpty(svnUrl) || StringHelper.isEmpty(inumFN) || StringHelper.isEmpty(svnPassword)) {
        // log.error("Failed to commit files to repository. Please check SVN related properties in gluuAppliance.properties file");
        return false;
    }
    SVNClientManager clientManager = null;
    try {
        // Decrypt password
        svnPassword = encryptionService.decrypt(svnPassword);
        // Create an instance of SVNClientManager
        log.debug("Creating an instance of SVNClientManager");
        SVNURL repositoryURL = SVNURL.parseURIEncoded(svnUrl);
        clientManager = SvnHelper.getSVNClientManager(inumFN, svnPassword);
        // Check root path exists
        boolean result = checkRootSvnPath(clientManager, repositoryURL);
        if (!result) {
            return result;
        }
        File applianceSvnHome = new File(applianceSvnHomePath);
        removeFilesFromLocalRepository(applianceSvnHome, removeSubversionFiles);
        // Copy files to temporary repository folder
        copyFilesToLocalRepository(applianceSvnHome, newSubversionFiles);
        // Add files
        log.debug("Adding files if neccessary");
        SvnHelper.addNewFiles(clientManager, applianceSvnHome);
        // Commit updates to repository
        log.debug("Commiting updates to repository");
        String message = String.format("Automatic update of Shibboleth configuration files for organization %s", organization.getDisplayName());
        message += "\n Changes List:\n" + svnComment;
        SvnHelper.commit(clientManager, applianceSvnHome, false, message);
        return true;
    } catch (Exception ex) {
    // log.error("Failed to commit files to repository", ex);
    } finally {
        if (clientManager != null) {
            clientManager.dispose();
        }
    }
    return false;
}
Also used : SVNURL(org.tmatesoft.svn.core.SVNURL) SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File) SVNClientManager(org.tmatesoft.svn.core.wc.SVNClientManager) SVNException(org.tmatesoft.svn.core.SVNException) IOException(java.io.IOException)

Example 3 with SubversionFile

use of org.gluu.oxtrust.model.SubversionFile in project oxTrust by GluuFederation.

the class SubversionService method removeFilesFromLocalRepository.

private void removeFilesFromLocalRepository(File dir, List<SubversionFile> removeSubversionFiles) throws IOException {
    log.debug("Removing files from temporary repository folder");
    String dirFn = dir.getAbsolutePath();
    for (SubversionFile subversionFile : removeSubversionFiles) {
        String fn = getLocalRepositoryFilePath(dirFn, subversionFile);
        File f = new File(fn);
        try {
            FileUtils.forceDelete(f);
        } catch (IOException ex) {
            log.error("Failed to delete file {} from local repository folder", subversionFile.getLocalFile());
            throw ex;
        }
    }
}
Also used : IOException(java.io.IOException) SubversionFile(org.gluu.oxtrust.model.SubversionFile) SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File)

Example 4 with SubversionFile

use of org.gluu.oxtrust.model.SubversionFile in project oxTrust by GluuFederation.

the class SubversionService method copyFilesToLocalRepository.

private void copyFilesToLocalRepository(File dir, List<SubversionFile> subversionFiles) throws IOException {
    log.debug("Copying files to temporary repository folder");
    String dirFn = dir.getAbsolutePath();
    for (SubversionFile subversionFile : subversionFiles) {
        String fn = getLocalRepositoryFilePath(dirFn, subversionFile);
        File f = new File(fn);
        try {
            FileUtils.copyFile(new File(subversionFile.getLocalFile()), f);
        } catch (IOException ex) {
            log.error("Failed to copy file {} into local repository folder", subversionFile.getLocalFile());
            throw ex;
        }
    }
}
Also used : IOException(java.io.IOException) SubversionFile(org.gluu.oxtrust.model.SubversionFile) SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File)

Example 5 with SubversionFile

use of org.gluu.oxtrust.model.SubversionFile in project oxTrust by GluuFederation.

the class SvnSyncTimer method commitShibboleth3Configuration.

private void commitShibboleth3Configuration(List<GluuSAMLTrustRelationship> trustRelationships) {
    synchronized (this) {
        List<SubversionFile> subversionFiles = new ArrayList<SubversionFile>();
        try {
            subversionFiles = subversionService.getDifferentFiles(shibboleth3ConfService.getConfigurationFilesForSubversion(trustRelationships));
        } catch (IOException e) {
            log.error("Failed to prepare files list to be persisted in svn", e);
        }
        List<SubversionFile> removeSubversionFiles = new ArrayList<SubversionFile>();
        while (!removedTrustRelationship.isEmpty()) {
            Pair<GluuSAMLTrustRelationship, String> removedRelationship = removedTrustRelationship.poll();
            SubversionFile file = shibboleth3ConfService.getConfigurationFileForSubversion(removedRelationship.getValue0());
            if (file != null) {
                removeSubversionFiles.add(file);
            }
        }
        String idpSvnComment = "";
        // Find all TRs modified not by user.
        for (SubversionFile file : subversionFiles) {
            String filename = file.getLocalFile();
            if (filename.matches(".*/DA[0-9A-F]*-sp-metadata\\.xml")) {
                boolean found = false;
                String inum = filename.replaceAll("-sp-metadata\\.xml", "").replaceAll(".*/", "");
                for (Pair<GluuSAMLTrustRelationship, String> trust : alteredTrustRelations) {
                    if (StringHelper.removePunctuation(trust.getValue0().getInum()).equals(inum)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    GluuSAMLTrustRelationship unknownTrust = trustService.getTrustByUnpunctuatedInum(inum);
                    if (unknownTrust != null) {
                        idpSvnComment += "Trust relationship '" + unknownTrust.getDisplayName() + "' was updated automatically\n";
                    } else {
                        idpSvnComment += "Appliance have no information about  '" + filename + "'. Please report this issue to appliance admin.\n";
                    }
                }
            }
        }
        log.debug("Files to be persisted in repository: " + StringHelper.toString(subversionFiles.toArray(new SubversionFile[] {})));
        log.debug("Files to be removed from repository: " + StringHelper.toString(removeSubversionFiles.toArray(new SubversionFile[] {})));
        if (!subversionService.commitShibboleth3ConfigurationFiles(organizationService.getOrganization(), subversionFiles, removeSubversionFiles, svnComment + idpSvnComment)) {
            log.error("Failed to commit Shibboleth3 configuration to SVN repository");
        } else {
            svnComment = "";
            alteredTrustRelations.clear();
            log.info("Shibboleth3 configuration commited successfully to SVN repository");
        }
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SubversionFile(org.gluu.oxtrust.model.SubversionFile)

Aggregations

SubversionFile (org.gluu.oxtrust.model.SubversionFile)6 File (java.io.File)4 IOException (java.io.IOException)4 ArrayList (java.util.ArrayList)3 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)2 SVNException (org.tmatesoft.svn.core.SVNException)1 SVNURL (org.tmatesoft.svn.core.SVNURL)1 SVNClientManager (org.tmatesoft.svn.core.wc.SVNClientManager)1 InvalidConfigurationException (org.xdi.util.exception.InvalidConfigurationException)1