use of org.xdi.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method removeSpMetadataFile.
public void removeSpMetadataFile(String spMetadataFileName) {
if (appConfiguration.getShibboleth3IdpRootDir() == null) {
throw new InvalidConfigurationException("Failed to remove SP meta-data file due to undefined IDP root folder");
}
String idpMetadataFolder = getIdpMetadataDir();
File spMetadataFile = new File(idpMetadataFolder + spMetadataFileName);
if (spMetadataFile.exists()) {
spMetadataFile.delete();
}
}
use of org.xdi.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.
the class FilterService method saveFilterCert.
public String saveFilterCert(String filterCertFileName, InputStream input) {
if (appConfiguration.getShibboleth3IdpRootDir() == null) {
IOUtils.closeQuietly(input);
throw new InvalidConfigurationException("Failed to save filter certificate file due to undefined IDP root folder");
}
String idpMetadataFolder = appConfiguration.getShibboleth3IdpRootDir() + File.separator + SHIB3_IDP_METADATA_FOLDER + File.separator + "credentials" + File.separator;
File filterCertFile = new File(idpMetadataFolder + filterCertFileName);
FileOutputStream os = null;
try {
os = FileUtils.openOutputStream(filterCertFile);
IOUtils.copy(input, os);
os.flush();
} catch (IOException ex) {
log.error("Failed to write filter certificate file '{}'", filterCertFile, ex);
ex.printStackTrace();
return null;
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(input);
}
return filterCertFile.getAbsolutePath();
}
use of org.xdi.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.
the class ProfileConfigurationService method saveProfileConfigurationCert.
public String saveProfileConfigurationCert(String profileConfigurationCertFileName, InputStream stream) {
if (appConfiguration.getShibboleth3IdpRootDir() == null) {
IOUtils.closeQuietly(stream);
throw new InvalidConfigurationException("Failed to save Profile Configuration file due to undefined IDP root folder");
}
String idpMetadataFolder = appConfiguration.getShibboleth3IdpRootDir() + File.separator + SHIB3_IDP_METADATA_FOLDER + File.separator + "credentials" + File.separator;
File filterCertFile = new File(idpMetadataFolder + profileConfigurationCertFileName);
FileOutputStream os = null;
try {
os = FileUtils.openOutputStream(filterCertFile);
IOUtils.copy(stream, os);
os.flush();
} catch (IOException ex) {
log.error("Failed to write Profile Configuration certificate file '{}'", filterCertFile, ex);
ex.printStackTrace();
return null;
} finally {
IOUtils.closeQuietly(os);
IOUtils.closeQuietly(stream);
}
return filterCertFile.getAbsolutePath();
}
use of org.xdi.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method isCorrectSpMetadataFile.
public boolean isCorrectSpMetadataFile(String spMetadataFileName) {
if (appConfiguration.getShibboleth3IdpRootDir() == null) {
throw new InvalidConfigurationException("Failed to check SP meta-data file due to undefined IDP root folder");
}
String idpMetadataFolder = getIdpMetadataDir();
File metadataFile = new File(idpMetadataFolder + spMetadataFileName);
List<String> entityId = SAMLMetadataParser.getSpEntityIdFromMetadataFile(metadataFile);
return (entityId != null) && !entityId.isEmpty();
}
use of org.xdi.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method generateMetadataFiles.
/**
* Generate metadata files needed for appliance operations: gluuSP metadata
* and idp metadata.
*/
public boolean generateMetadataFiles(GluuSAMLTrustRelationship gluuSP) {
log.info(">>>>>>>>>> IN Shibboleth3ConfService.generateMetadataFiles()...");
if (appConfiguration.getShibboleth3IdpRootDir() == null) {
throw new InvalidConfigurationException("Failed to update configuration due to undefined IDP root folder");
}
String idpMetadataFolder = getIdpMetadataDir();
// Prepare data for files
VelocityContext context = new VelocityContext();
String idpHost = appConfiguration.getIdpUrl();
context.put("idpHost", idpHost);
String domain = idpHost.replaceAll(":[0-9]*$", "").replaceAll("^.*?//", "");
context.put("domain", domain);
context.put("orgName", appConfiguration.getOrganizationName());
context.put("orgShortName", appConfiguration.getOrganizationName());
try {
String idpSigningCertificate = FileUtils.readFileToString(new File(appConfiguration.getIdp3SigningCert())).replaceAll("-{5}.*?-{5}", "");
context.put("idpSigningCertificate", idpSigningCertificate);
} catch (IOException e) {
log.error("Unable to get IDP 3 signing certificate from " + appConfiguration.getIdp3SigningCert(), e);
e.printStackTrace();
return false;
}
try {
String idpEncryptionCertificate = FileUtils.readFileToString(new File(appConfiguration.getIdp3EncryptionCert())).replaceAll("-{5}.*?-{5}", "");
context.put("idpEncryptionCertificate", idpEncryptionCertificate);
} catch (IOException e) {
log.error("Unable to get IDP 3 encryption certificate from " + appConfiguration.getIdp3EncryptionCert(), e);
e.printStackTrace();
return false;
}
try {
String spCertificate = FileUtils.readFileToString(new File(appConfiguration.getGluuSpCert())).replaceAll("-{5}.*?-{5}", "");
if (gluuSP.getUrl() == null || "".equals(gluuSP.getUrl())) {
gluuSP.setUrl(appConfiguration.getApplianceUrl());
}
generateSpMetadataFile(gluuSP, spCertificate);
} catch (IOException e) {
log.error("Unable to get SP certificate from " + appConfiguration.getGluuSpCert(), e);
e.printStackTrace();
return false;
}
// Generate idp-metadata.xml
String idpMetadata = templateService.generateConfFile(SHIB3_IDP_IDP_METADATA_FILE, context);
boolean result = (idpMetadata != null);
// String idpMetadataName = String.format(SHIB3_IDP_METADATA_FILE_PATTERN, StringHelper.removePunctuation(organizationService.getOrganizationInum()));
// Write idp-metadata.xml
result &= templateService.writeConfFile(idpMetadataFolder + SHIB3_IDP_IDP_METADATA_FILE, idpMetadata);
log.info(">>>>>>>>>> LEAVING Shibboleth3ConfService.generateMetadataFiles()...");
return result;
}
Aggregations