Search in sources :

Example 1 with InvalidConfigurationException

use of org.gluu.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method generateConfigurationFiles.

public boolean generateConfigurationFiles(SamlAcr[] acrs) {
    log.info(">>>>>>>>>> IN generateConfigurationFiles(SamlAcr[] acrs)...");
    if (appConfiguration.getShibboleth3IdpRootDir() == null) {
        throw new InvalidConfigurationException("Failed to update configuration due to undefined IDP root folder");
    }
    String idpConfAuthnFolder = getIdpConfAuthnDir();
    List<String> acrs2 = new ArrayList<String>();
    for (SamlAcr acr : acrs) acrs2.add(acr.getClassRef());
    VelocityContext context = new VelocityContext();
    context.put("acrs", acrs2);
    // Generate metadata-providers.xml
    String oxAuthSupportedPrincipals = generateConfFile(GLUU_SAML_OXAUTH_SUPPORTED_PRINCIPALS_FILE, context);
    boolean result = writeConfFile(idpConfAuthnFolder + GLUU_SAML_OXAUTH_SUPPORTED_PRINCIPALS_FILE, oxAuthSupportedPrincipals);
    log.info(">>>>>>>>>> LEAVING generateConfigurationFiles(SamlAcr[] acrs)...");
    return result;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) SamlAcr(org.gluu.oxtrust.model.SamlAcr) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException)

Example 2 with InvalidConfigurationException

use of org.gluu.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method saveMetadataFile.

public boolean saveMetadataFile(String spMetaDataURL, String metadataFileName) {
    if (StringHelper.isEmpty(spMetaDataURL)) {
        return false;
    }
    if (appConfiguration.getShibboleth3FederationRootDir() == null) {
        throw new InvalidConfigurationException("Failed to save meta-data file due to undefined federation root folder");
    }
    HTTPFileDownloader.setEasyhttps(new Protocol("https", new EasyCASSLProtocolSocketFactory(), 443));
    String metadataFileContent = HTTPFileDownloader.getResource(spMetaDataURL, "application/xml, text/xml", null, null);
    if (StringHelper.isEmpty(metadataFileContent)) {
        return false;
    }
    String spMetadataFile = getIdpMetadataDir() + metadataFileName;
    try {
        return documentStoreService.saveDocument(spMetadataFile, metadataFileContent, UTF_8);
    } catch (Exception ex) {
        log.error("Failed to write meta-data file '{}'", spMetadataFile, ex);
    }
    return false;
}
Also used : EasyCASSLProtocolSocketFactory(org.gluu.oxtrust.util.EasyCASSLProtocolSocketFactory) Protocol(org.apache.commons.httpclient.protocol.Protocol) XPathExpressionException(javax.xml.xpath.XPathExpressionException) EncryptionException(org.gluu.util.security.StringEncrypter.EncryptionException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) XMLParserException(org.opensaml.xml.parse.XMLParserException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException)

Example 3 with InvalidConfigurationException

use of org.gluu.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method generateGluuAttributeRulesFile.

public boolean generateGluuAttributeRulesFile(List<GluuAttribute> attributes) {
    boolean ret = false;
    log.info(">>>>>>>>>> IN Shibboleth3ConfService.generateGluuAttributeRulesFile() ...");
    if (appConfiguration.getShibboleth3IdpRootDir() == null) {
        throw new InvalidConfigurationException("Failed to update configuration due to undefined IDP root folder");
    }
    VelocityContext context = new VelocityContext();
    List<String> attributeNames = new ArrayList<String>();
    for (GluuAttribute attribute : attributes) {
        attributeNames.add(attribute.getName());
    }
    SchemaEntry schemaEntry = shemaService.getSchema();
    List<AttributeTypeDefinition> attributeTypes = shemaService.getAttributeTypeDefinitions(schemaEntry, attributeNames);
    Map<String, String> attributeSaml1Strings = new HashMap<String, String>();
    Map<String, String> attributeSaml2Strings = new HashMap<String, String>();
    for (GluuAttribute metadata : attributes) {
        String attributeName = metadata.getName();
        String saml1String = metadata.getSaml1Uri();
        if (StringHelper.isEmpty(saml1String)) {
            boolean standard = metadata.isCustom() || StringHelper.isEmpty(metadata.getUrn()) || (!StringHelper.isEmpty(metadata.getUrn()) && metadata.getUrn().startsWith("urn:gluu:dir:attribute-def:"));
            saml1String = String.format("urn:%s:dir:attribute-def:%s", (standard ? "gluu" : "mace"), attributeName);
        }
        attributeSaml1Strings.put(attributeName, saml1String);
        String saml2String = metadata.getSaml2Uri();
        if (StringHelper.isEmpty(saml2String)) {
            AttributeTypeDefinition attributeTypeDefinition = shemaService.getAttributeTypeDefinition(attributeTypes, attributeName);
            if (attributeTypeDefinition == null) {
                log.error("Failed to get OID for attribute name {}", attributeName);
                return false;
            }
            saml2String = String.format("urn:oid:%s", attributeTypeDefinition.getOID());
        }
        attributeSaml2Strings.put(attributeName, saml2String);
    }
    context.put("attributes", attributes);
    context.put("attributeSaml1Strings", attributeSaml1Strings);
    context.put("attributeSaml2Strings", attributeSaml2Strings);
    String gluuAttributesRules = generateConfFile(SHIB_IDP_GLUU_ATTRIBUTE_RULES_FILE, context);
    log.info("Gluu attributes rules file path is {}", getGluuAttributesRulesFilePath());
    ret = writeConfFile(getGluuAttributesRulesFilePath(), gluuAttributesRules);
    log.info(">>>>>>>>>>> LEAVING Shibboleth3ConfService.generateGluuAttributeRulesFile() ...");
    return ret;
}
Also used : AttributeTypeDefinition(com.unboundid.ldap.sdk.schema.AttributeTypeDefinition) HashMap(java.util.HashMap) VelocityContext(org.apache.velocity.VelocityContext) ArrayList(java.util.ArrayList) SchemaEntry(org.gluu.model.SchemaEntry) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException) GluuAttribute(org.gluu.model.GluuAttribute)

Example 4 with InvalidConfigurationException

use of org.gluu.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method generateIdpConfigurationFiles.

public boolean generateIdpConfigurationFiles() {
    if (appConfiguration.getShibboleth3IdpRootDir() == null) {
        throw new InvalidConfigurationException("Failed to update configuration due to undefined IDP root folder");
    }
    String idpConfFolder = getIdpConfDir();
    // Prepare data for files
    VelocityContext context = new VelocityContext();
    // white spaces or comma
    String regx = "\\s*(=>|,|\\s)\\s*";
    String[] ldapUrls = appConfiguration.getIdpLdapServer().split(regx);
    String ldapUrl = "";
    if (ldapUrls != null) {
        for (String ldapServer : ldapUrls) {
            if (ldapUrl.length() > 1) {
                ldapUrl = ldapUrl + " ";
            }
            ldapUrl = ldapUrl + appConfiguration.getIdpLdapProtocol() + "://" + ldapServer;
        }
    } else {
        ldapUrl = appConfiguration.getIdpLdapProtocol() + "://" + appConfiguration.getIdpLdapServer();
    }
    String host = ldapUrl;
    String base = appConfiguration.getBaseDN();
    String serviceUser = appConfiguration.getIdpBindDn();
    String serviceCredential = "";
    try {
        serviceCredential = encryptionService.decrypt(appConfiguration.getIdpBindPassword());
    } catch (EncryptionException e) {
        log.error("Failed to decrypt bindPassword", e);
        e.printStackTrace();
    }
    String userField = appConfiguration.getIdpUserFields();
    context.put("host", host);
    context.put("base", base);
    context.put("serviceUser", serviceUser);
    context.put("serviceCredential", serviceCredential);
    context.put("userField", userField);
    // Generate login.config
    String loginConfig = generateConfFile(SHIB3_IDP_LOGIN_CONFIG_FILE, context);
    boolean result = (loginConfig != null);
    // Write login.config
    result &= writeConfFile(idpConfFolder + SHIB3_IDP_LOGIN_CONFIG_FILE, loginConfig);
    return result;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) EncryptionException(org.gluu.util.security.StringEncrypter.EncryptionException) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException)

Example 5 with InvalidConfigurationException

use of org.gluu.util.exception.InvalidConfigurationException in project oxTrust by GluuFederation.

the class Shibboleth3ConfService method generateMetadataFiles.

/**
 * Generate metadata files needed for configuration operations: gluuSP metadata
 * and idp metadata.
 */
public boolean generateMetadataFiles() {
    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 signingCert = appConfiguration.getIdp3SigningCert();
        if (DocumentStoreType.LOCAL != documentStoreService.getProviderType()) {
            // If it's not local store we need to check if file exists and put it into repo
            // if needed
            boolean hasSigningCert = documentStoreService.hasDocument(signingCert);
            if (!hasSigningCert) {
                try (InputStream signingCertStream = localDocumentStoreService.readDocumentAsStream(signingCert)) {
                    documentStoreService.saveDocumentStream(signingCert, signingCertStream);
                }
            }
        }
        String idpSigningCertificate = documentStoreService.readDocument(signingCert, UTF_8).replaceAll("-{5}.*?-{5}", "");
        context.put("idpSigningCertificate", idpSigningCertificate);
    } catch (Exception e) {
        log.error("Unable to get IDP 3 signing certificate from " + appConfiguration.getIdp3SigningCert(), e);
        return false;
    }
    try {
        String encryptionCert = appConfiguration.getIdp3EncryptionCert();
        if (DocumentStoreType.LOCAL != documentStoreService.getProviderType()) {
            // If it's not local store we need to check if file exists and put it into repo
            // if needed
            boolean hasSigningCert = documentStoreService.hasDocument(encryptionCert);
            if (!hasSigningCert) {
                try (InputStream encryptionCertStream = localDocumentStoreService.readDocumentAsStream(encryptionCert)) {
                    documentStoreService.saveDocumentStream(encryptionCert, encryptionCertStream);
                }
            }
        }
        String idpEncryptionCertificate = documentStoreService.readDocument(encryptionCert, UTF_8).replaceAll("-{5}.*?-{5}", "");
        context.put("idpEncryptionCertificate", idpEncryptionCertificate);
    } catch (Exception e) {
        log.error("Unable to get IDP 3 encryption certificate from " + appConfiguration.getIdp3EncryptionCert(), e);
        return false;
    }
    // Generate idp-metadata.xml
    String idpMetadata = 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 &= writeConfFile(idpMetadataFolder + SHIB3_IDP_IDP_METADATA_FILE, idpMetadata);
    log.info(">>>>>>>>>> LEAVING Shibboleth3ConfService.generateMetadataFiles()...");
    return result;
}
Also used : VelocityContext(org.apache.velocity.VelocityContext) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) XPathExpressionException(javax.xml.xpath.XPathExpressionException) EncryptionException(org.gluu.util.security.StringEncrypter.EncryptionException) SAXException(org.xml.sax.SAXException) IOException(java.io.IOException) XMLParserException(org.opensaml.xml.parse.XMLParserException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException) InvalidConfigurationException(org.gluu.util.exception.InvalidConfigurationException)

Aggregations

InvalidConfigurationException (org.gluu.util.exception.InvalidConfigurationException)7 VelocityContext (org.apache.velocity.VelocityContext)5 EncryptionException (org.gluu.util.security.StringEncrypter.EncryptionException)4 IOException (java.io.IOException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)3 XPathExpressionException (javax.xml.xpath.XPathExpressionException)3 XMLParserException (org.opensaml.xml.parse.XMLParserException)3 SAXException (org.xml.sax.SAXException)3 ArrayList (java.util.ArrayList)2 Protocol (org.apache.commons.httpclient.protocol.Protocol)2 EasyCASSLProtocolSocketFactory (org.gluu.oxtrust.util.EasyCASSLProtocolSocketFactory)2 AttributeTypeDefinition (com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1 HashMap (java.util.HashMap)1 GluuAttribute (org.gluu.model.GluuAttribute)1 SchemaEntry (org.gluu.model.SchemaEntry)1 SamlAcr (org.gluu.oxtrust.model.SamlAcr)1