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;
}
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;
}
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;
}
}
}
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;
}
}
}
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");
}
}
}
Aggregations