Search in sources :

Example 1 with LdapMappingException

use of org.gluu.site.ldap.persistence.exception.LdapMappingException in project oxAuth by GluuFederation.

the class AppInitializer method loadAppliance.

private GluuAppliance loadAppliance(LdapEntryManager localLdapEntryManager, String... ldapReturnAttributes) {
    String baseDn = configurationFactory.getBaseDn().getAppliance();
    String applianceInum = configurationFactory.getAppConfiguration().getApplianceInum();
    if (StringHelper.isEmpty(baseDn) || StringHelper.isEmpty(applianceInum)) {
        return null;
    }
    String applianceDn = String.format("inum=%s,%s", applianceInum, baseDn);
    GluuAppliance appliance = null;
    try {
        appliance = localLdapEntryManager.find(GluuAppliance.class, applianceDn, ldapReturnAttributes);
    } catch (LdapMappingException ex) {
        log.error("Failed to load appliance entry from Ldap", ex);
        return null;
    }
    return appliance;
}
Also used : GluuAppliance(org.xdi.oxauth.model.appliance.GluuAppliance) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException)

Example 2 with LdapMappingException

use of org.gluu.site.ldap.persistence.exception.LdapMappingException in project oxTrust by GluuFederation.

the class LdifService method exportLDIFFile.

public void exportLDIFFile(List<String> checkedItems, OutputStream output) throws LDAPException {
    List<SearchResultEntry> result = null;
    LDAPConnection connection = ldapEntryManager.getLdapOperationService().getConnection();
    try {
        LdifDataUtility ldifDataUtility = LdifDataUtility.instance();
        result = ldifDataUtility.getAttributeResultEntryLDIF(connection, checkedItems, attributeService.getDnForAttribute(null));
    } catch (Exception ex) {
        log.error("Failed to export ldif file: ", ex);
    } finally {
        ldapEntryManager.getLdapOperationService().releaseConnection(connection);
    }
    if (result != null && result.size() > 0) {
        // Write all of the matching entries to LDIF.
        LDIFWriter ldifWriter;
        try {
            ldifWriter = new LDIFWriter(output);
            for (SearchResultEntry entry : result) {
                ldifWriter.writeEntry(entry);
            }
            ldifWriter.close();
        } catch (IOException e) {
            throw new LdapMappingException("Error writing to file, try again", e);
        }
    }
}
Also used : LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LDIFWriter(com.unboundid.ldif.LDIFWriter) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) IOException(java.io.IOException) LdifDataUtility(org.gluu.site.ldap.persistence.LdifDataUtility) IOException(java.io.IOException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 3 with LdapMappingException

use of org.gluu.site.ldap.persistence.exception.LdapMappingException in project oxTrust by GluuFederation.

the class JsonConfigurationService method loadOxAuthConfig.

private LdapOxAuthConfiguration loadOxAuthConfig(String configurationDn) {
    try {
        configurationDn = configurationDn.replace("ou=oxtrust", "ou=oxauth");
        LdapOxAuthConfiguration conf = ldapEntryManager.find(LdapOxAuthConfiguration.class, configurationDn);
        return conf;
    } catch (LdapMappingException ex) {
        log.error("Failed to load configuration from LDAP");
    }
    return null;
}
Also used : LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LdapOxAuthConfiguration(org.xdi.config.oxtrust.LdapOxAuthConfiguration)

Example 4 with LdapMappingException

use of org.gluu.site.ldap.persistence.exception.LdapMappingException in project oxTrust by GluuFederation.

the class UpdateTrustRelationshipAction method save.

public String save() {
    synchronized (svnSyncTimer) {
        if (StringHelper.isEmpty(this.trustRelationship.getInum())) {
            this.inum = trustService.generateInumForNewTrustRelationship();
            this.trustRelationship.setInum(this.inum);
        } else {
            this.inum = this.trustRelationship.getInum();
            if (this.trustRelationship.getSpMetaDataFN() == null)
                update = true;
        }
        boolean updateShib3Configuration = appConfiguration.isConfigGeneration();
        switch(trustRelationship.getSpMetaDataSourceType()) {
            case GENERATE:
                String certificate = getCertForGeneratedSP();
                GluuStatus status = StringHelper.isNotEmpty(certificate) ? GluuStatus.ACTIVE : GluuStatus.INACTIVE;
                this.trustRelationship.setStatus(status);
                if (generateSpMetaDataFile(certificate)) {
                    setEntityId();
                } else {
                    log.error("Failed to generate SP meta-data file");
                    return OxTrustConstants.RESULT_FAILURE;
                }
                break;
            case FILE:
                if (saveSpMetaDataFileSourceTypeFile()) {
                    //update = true;
                    updateSpMetaDataCert(certWrapper);
                    //					setEntityId();
                    if (!update) {
                        this.trustRelationship.setStatus(GluuStatus.ACTIVE);
                    }
                } else {
                    log.error("Failed to save SP meta-data file {}", fileWrapper);
                    return OxTrustConstants.RESULT_FAILURE;
                }
                break;
            case URI:
                try {
                    //if (saveSpMetaDataFileSourceTypeURI()) {
                    //						setEntityId();
                    boolean result = shibboleth3ConfService.existsResourceUri(trustRelationship.getSpMetaDataURL());
                    if (result) {
                        newThreadSaveSpMetaDataFileSourceTypeURI();
                    } else {
                        log.info("There is no resource found Uri : {}", trustRelationship.getSpMetaDataURL());
                    }
                    if (!update) {
                        this.trustRelationship.setStatus(GluuStatus.ACTIVE);
                    }
                /*} else {
						log.error("Failed to save SP meta-data file {}", fileWrapper);
						return OxTrustConstants.RESULT_FAILURE;
					}*/
                } catch (Exception e) {
                    return "unable_download_metadata";
                }
                break;
            case FEDERATION:
                if (!update) {
                    this.trustRelationship.setStatus(GluuStatus.ACTIVE);
                }
                if (this.trustRelationship.getEntityId() == null) {
                    return "invalid_entity_id";
                }
                break;
            default:
                break;
        }
        trustService.updateReleasedAttributes(this.trustRelationship);
        boolean federation = shibboleth3ConfService.isFederation(this.trustRelationship);
        this.trustRelationship.setFederation(federation);
        trustContactsAction.saveContacts();
        if (update) {
            try {
                saveTR(update);
            } catch (LdapMappingException ex) {
                log.error("Failed to update trust relationship {}", ex, inum);
                return OxTrustConstants.RESULT_FAILURE;
            }
        } else {
            String dn = trustService.getDnForTrustRelationShip(this.inum);
            // Save trustRelationship
            this.trustRelationship.setDn(dn);
            try {
                saveTR(update);
            } catch (LdapMappingException ex) {
                log.error("Failed to add new trust relationship {}", ex, this.trustRelationship.getInum());
                return OxTrustConstants.RESULT_FAILURE;
            }
            this.update = true;
        }
        if (updateShib3Configuration) {
            List<GluuSAMLTrustRelationship> trustRelationships = trustService.getAllActiveTrustRelationships();
            updateShibboleth3Configuration(trustRelationships);
        }
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) GluuStatus(org.xdi.ldap.model.GluuStatus) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) CertificateEncodingException(java.security.cert.CertificateEncodingException) IOException(java.io.IOException)

Example 5 with LdapMappingException

use of org.gluu.site.ldap.persistence.exception.LdapMappingException in project oxTrust by GluuFederation.

the class UpdateTrustRelationshipAction method delete.

public String delete() {
    String result = OxTrustConstants.RESULT_FAILURE;
    if (update) {
        // Remove trust relationship
        try {
            synchronized (svnSyncTimer) {
                for (GluuSAMLTrustRelationship trust : trustService.getDeconstructedTrustRelationships(this.trustRelationship)) {
                    if (GluuStatus.ACTIVE.equals(trust.getStatus())) {
                        log.error("Failed to remove federation trust relationship {}, there are still active federated Trust Relationships left.", this.trustRelationship.getInum());
                        return result;
                    }
                }
                for (GluuSAMLTrustRelationship trust : trustService.getDeconstructedTrustRelationships(this.trustRelationship)) {
                    trustService.removeTrustRelationship(trust);
                    svnSyncTimer.removeTrustRelationship(trust, identity.getCredentials().getUsername());
                }
                shibboleth3ConfService.removeSpMetadataFile(this.trustRelationship.getSpMetaDataFN());
                trustService.removeTrustRelationship(this.trustRelationship);
                svnSyncTimer.removeTrustRelationship(this.trustRelationship, identity.getCredentials().getUsername());
            }
            result = OxTrustConstants.RESULT_SUCCESS;
        } catch (LdapMappingException ex) {
            result = OxTrustConstants.RESULT_FAILURE;
            log.error("Failed to remove trust relationship {}", ex, this.trustRelationship.getInum());
        } catch (InterruptedException e) {
            log.error("Failed to add trust relationship to remove queue. It will be removed during next application restart", e);
        } finally {
            List<GluuSAMLTrustRelationship> trustRelationships = trustService.getAllActiveTrustRelationships();
            updateShibboleth3Configuration(trustRelationships);
        }
    }
    return result;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException)

Aggregations

LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)27 ArrayList (java.util.ArrayList)6 GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)5 IOException (java.io.IOException)4 LdapEntryManager (org.gluu.site.ldap.persistence.LdapEntryManager)4 Date (java.util.Date)3 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)3 CustomScript (org.xdi.model.custom.script.model.CustomScript)3 ParseException (java.text.ParseException)2 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)2 AppConfiguration (org.xdi.config.oxtrust.AppConfiguration)2 SelectableEntity (org.xdi.model.SelectableEntity)2 ScopeDescription (org.xdi.oxauth.model.uma.persistence.ScopeDescription)2 Filter (com.unboundid.ldap.sdk.Filter)1 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 SearchResultEntry (com.unboundid.ldap.sdk.SearchResultEntry)1 LDIFWriter (com.unboundid.ldif.LDIFWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1