Search in sources :

Example 1 with InvalidConfigurationException

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();
    }
}
Also used : SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File) InvalidConfigurationException(org.xdi.util.exception.InvalidConfigurationException)

Example 2 with InvalidConfigurationException

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();
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) InvalidConfigurationException(org.xdi.util.exception.InvalidConfigurationException)

Example 3 with InvalidConfigurationException

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();
}
Also used : FileOutputStream(java.io.FileOutputStream) IOException(java.io.IOException) File(java.io.File) InvalidConfigurationException(org.xdi.util.exception.InvalidConfigurationException)

Example 4 with InvalidConfigurationException

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();
}
Also used : SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File) InvalidConfigurationException(org.xdi.util.exception.InvalidConfigurationException)

Example 5 with InvalidConfigurationException

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;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) IOException(java.io.IOException) SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File) InvalidConfigurationException(org.xdi.util.exception.InvalidConfigurationException)

Aggregations

InvalidConfigurationException (org.xdi.util.exception.InvalidConfigurationException)13 File (java.io.File)10 SubversionFile (org.gluu.oxtrust.model.SubversionFile)9 IOException (java.io.IOException)5 FileOutputStream (java.io.FileOutputStream)4 VelocityContext (org.apache.velocity.VelocityContext)3 ArrayList (java.util.ArrayList)1 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)1 EncryptionException (org.xdi.util.security.StringEncrypter.EncryptionException)1