Search in sources :

Example 11 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class TrustRelationshipWebService method saveTR.

/**
 * Save SAML TrustRelationship.
 *
 * @param trustRelationship
 * @param metadata - need for FILE type TR only
 * @param certificate - need for FILE type TR, optional for GENERATE type TR
 * @return
 */
private String saveTR(GluuSAMLTrustRelationship trustRelationship, String metadata, String certificate) {
    String inum;
    boolean update = false;
    synchronized (svnSyncTimer) {
        if (StringHelper.isEmpty(trustRelationship.getInum())) {
            inum = trustService.generateInumForNewTrustRelationship();
            trustRelationship.setInum(inum);
        } else {
            inum = trustRelationship.getInum();
            if (trustRelationship.getSpMetaDataFN() == null)
                update = true;
        }
        boolean updateShib3Configuration = appConfiguration.isConfigGeneration();
        switch(trustRelationship.getSpMetaDataSourceType()) {
            case GENERATE:
                try {
                    if (StringHelper.isEmpty(certificate))
                        certificate = generateCertForGeneratedSP(trustRelationship);
                    GluuStatus status = StringHelper.isNotEmpty(certificate) ? GluuStatus.ACTIVE : GluuStatus.INACTIVE;
                    trustRelationship.setStatus(status);
                    if (generateSpMetaDataFile(trustRelationship, certificate)) {
                        setEntityId(trustRelationship);
                    } else {
                        logger.error("Failed to generate SP meta-data file");
                        return OxTrustConstants.RESULT_FAILURE;
                    }
                } catch (IOException ex) {
                    logger.error("Failed to download SP certificate", ex);
                    return OxTrustConstants.RESULT_FAILURE;
                }
                break;
            case FILE:
                try {
                    if (saveSpMetaDataFileSourceTypeFile(trustRelationship, inum, metadata)) {
                        // update = true;
                        updateTRCertificate(trustRelationship, certificate);
                        // setEntityId();
                        if (!update) {
                            trustRelationship.setStatus(GluuStatus.ACTIVE);
                        }
                    } else {
                        logger.error("Failed to save SP metadata file {}", metadata);
                        return OxTrustConstants.RESULT_FAILURE;
                    }
                } catch (IOException ex) {
                    logger.error("Failed to download SP metadata", ex);
                    return OxTrustConstants.RESULT_FAILURE;
                }
                break;
            case URI:
                try {
                    // if (saveSpMetaDataFileSourceTypeURI()) {
                    // setEntityId();
                    boolean result = shibboleth3ConfService.existsResourceUri(trustRelationship.getSpMetaDataURL());
                    if (result) {
                        saveSpMetaDataFileSourceTypeURI(trustRelationship);
                    } else {
                        logger.info("There is no resource found Uri : {}", trustRelationship.getSpMetaDataURL());
                    }
                    if (!update) {
                        trustRelationship.setStatus(GluuStatus.ACTIVE);
                    }
                /*} else {
                            log.error("Failed to save SP meta-data file {}", fileWrapper);
                            return OxTrustConstants.RESULT_FAILURE;
                    }*/
                } catch (Exception e) {
                    // facesMessages.add(FacesMessage.SEVERITY_ERROR, "Unable to download metadata");
                    return "unable_download_metadata";
                }
                break;
            case FEDERATION:
                if (!update) {
                    trustRelationship.setStatus(GluuStatus.ACTIVE);
                }
                if (trustRelationship.getEntityId() == null) {
                    // facesMessages.add(FacesMessage.SEVERITY_ERROR, "EntityID must be set to a value");
                    return "invalid_entity_id";
                }
                break;
            default:
                break;
        }
        trustService.updateReleasedAttributes(trustRelationship);
        // We call it from TR validation timer
        if (trustRelationship.getSpMetaDataSourceType().equals(GluuMetadataSourceType.GENERATE) || (trustRelationship.getSpMetaDataSourceType().equals(GluuMetadataSourceType.FEDERATION))) {
            boolean federation = shibboleth3ConfService.isFederation(trustRelationship);
            trustRelationship.setFederation(federation);
        }
        trustContactsAction.saveContacts();
        if (update) {
            try {
                saveTR(trustRelationship, update);
            } catch (BaseMappingException ex) {
                logger.error("Failed to update trust relationship {}", inum, ex);
                return OxTrustConstants.RESULT_FAILURE;
            }
        } else {
            String dn = trustService.getDnForTrustRelationShip(inum);
            // Save trustRelationship
            trustRelationship.setDn(dn);
            try {
                saveTR(trustRelationship, update);
            } catch (BaseMappingException ex) {
                logger.error("Failed to add new trust relationship {}", trustRelationship.getInum(), ex);
                return OxTrustConstants.RESULT_FAILURE;
            }
            update = true;
        }
        if (updateShib3Configuration) {
            List<GluuSAMLTrustRelationship> trustRelationships = trustService.getAllActiveTrustRelationships();
            if (!shibboleth3ConfService.generateConfigurationFiles(trustRelationships)) {
                logger.error("Failed to update Shibboleth v3 configuration");
                return "Failed to update Shibboleth v3 configuration";
            } else {
                logger.info("Shibboleth v3 configuration updated successfully");
                return "Shibboleth v3 configuration updated successfully";
            }
        }
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) GluuStatus(org.gluu.persist.model.base.GluuStatus) IOException(java.io.IOException) CertificateEncodingException(java.security.cert.CertificateEncodingException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) IOException(java.io.IOException)

Example 12 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class CacheRefreshTimer method removeTargetEntries.

private Pair<List<String>, List<String>> removeTargetEntries(LdapServerConnection inumDbServerConnection, LdapEntryManager targetLdapEntryManager, List<GluuSimplePerson> removedPersons, HashMap<String, GluuInumMap> inumInumMap) {
    String runDate = ldapEntryManager.encodeGeneralizedTime(new Date(this.lastFinishedTime));
    LdapEntryManager inumDbLdapEntryManager = inumDbServerConnection.getLdapEntryManager();
    List<String> result1 = new ArrayList<String>();
    List<String> result2 = new ArrayList<String>();
    for (GluuSimplePerson removedPerson : removedPersons) {
        String inum = removedPerson.getAttribute(OxTrustConstants.inum);
        // Update GluuInumMap if it exist
        GluuInumMap currentInumMap = inumInumMap.get(inum);
        if (currentInumMap == null) {
            log.warn("Can't find inum entry of person with DN: {}", removedPerson.getDn());
        } else {
            GluuInumMap removedInumMap = getMarkInumMapEntryAsRemoved(currentInumMap, runDate);
            try {
                inumDbLdapEntryManager.merge(removedInumMap);
                result2.add(removedInumMap.getInum());
            } catch (BaseMappingException ex) {
                log.error("Failed to update entry with inum '{}' and DN: {}", currentInumMap.getInum(), currentInumMap.getDn(), ex);
                continue;
            }
        }
        // Remove person from target server
        try {
            targetLdapEntryManager.removeRecursively(removedPerson.getDn());
            result1.add(inum);
        } catch (BaseMappingException ex) {
            log.error("Failed to remove person entry with inum '{}' and DN: {}", inum, removedPerson.getDn(), ex);
            continue;
        }
        log.debug("Person with DN: '{}' removed from target server", removedPerson.getDn());
    }
    return new Pair<List<String>, List<String>>(result1, result2);
}
Also used : GluuSimplePerson(org.gluu.oxtrust.ldap.cache.model.GluuSimplePerson) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) GluuInumMap(org.gluu.oxtrust.ldap.cache.model.GluuInumMap) LdapEntryManager(org.gluu.persist.ldap.impl.LdapEntryManager) ArrayList(java.util.ArrayList) Date(java.util.Date) Pair(org.xdi.util.Pair)

Example 13 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class ManagePersonAuthenticationAction method save.

public String save() throws JsonParseException, JsonMappingException, IOException {
    try {
        // Reload entry to include latest changes
        GluuAppliance appliance = applianceService.getAppliance();
        boolean updateAuthenticationMode = false;
        boolean updateOxTrustAuthenticationMode = false;
        String oldAuthName = getFirstConfigName(appliance.getOxIDPAuthentication());
        if (oldAuthName != null) {
            if (oldAuthName.equals(this.authenticationMode)) {
                updateAuthenticationMode = true;
            }
            if (oldAuthName.equals(this.oxTrustAuthenticationMode)) {
                updateOxTrustAuthenticationMode = true;
            }
        }
        updateAuthConf(appliance);
        String newAuthName = getFirstConfigName(appliance.getOxIDPAuthentication());
        String updatedAuthMode = updateAuthenticationMode ? newAuthName : this.authenticationMode;
        String updatedOxTrustAuthMode = updateOxTrustAuthenticationMode ? newAuthName : this.oxTrustAuthenticationMode;
        appliance.setAuthenticationMode(updatedAuthMode);
        appliance.setOxTrustAuthenticationMode(updatedOxTrustAuthMode);
        appliance.setPassportEnabled(passportEnable);
        applianceService.updateAppliance(appliance);
        ldapOxPassportConfiguration.setPassportConfigurations(ldapPassportConfigurations);
        passportService.updateLdapOxPassportConfiguration(ldapOxPassportConfiguration);
    } catch (BaseMappingException ex) {
        log.error("Failed to update appliance configuration", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update appliance");
        return OxTrustConstants.RESULT_FAILURE;
    }
    reset();
    facesMessages.add(FacesMessage.SEVERITY_INFO, "Person authentication configuration updated successfully");
    conversationService.endConversation();
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance)

Example 14 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException 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.getOperationService().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.getOperationService().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 BaseMappingException("Error writing to file, try again", e);
        }
    }
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDIFWriter(com.unboundid.ldif.LDIFWriter) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) IOException(java.io.IOException) LdifDataUtility(org.gluu.persist.ldap.impl.LdifDataUtility) IOException(java.io.IOException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) LDAPException(com.unboundid.ldap.sdk.LDAPException) SearchResultEntry(com.unboundid.ldap.sdk.SearchResultEntry)

Example 15 with BaseMappingException

use of org.gluu.persist.exception.mapping.BaseMappingException in project oxTrust by GluuFederation.

the class ManageCertificateAction method updateTrustCertificates.

private boolean updateTrustCertificates() {
    try {
        // Reload entry to include latest changes
        GluuAppliance tmpAppliance = applianceService.getAppliance();
        TrustStoreConfiguration currTrustStoreConfiguration = tmpAppliance.getTrustStoreConfiguration();
        List<TrustStoreCertificate> currTrustStoreCertificates = tmpAppliance.getTrustStoreCertificates();
        if (currTrustStoreCertificates == null) {
            currTrustStoreCertificates = new ArrayList<TrustStoreCertificate>(0);
        }
        if (!trustStoreConfiguration.equals(currTrustStoreConfiguration) || !trustStoreCertificates.equals(currTrustStoreCertificates)) {
            this.wereAnyChanges = true;
        }
        tmpAppliance.setTrustStoreConfiguration(trustStoreConfiguration);
        if (trustStoreCertificates.size() == 0) {
            tmpAppliance.setTrustStoreCertificates(null);
        } else {
            tmpAppliance.setTrustStoreCertificates(trustStoreCertificates);
        }
        applianceService.updateAppliance(tmpAppliance);
    } catch (BaseMappingException ex) {
        log.error("Failed to update appliance configuration", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update appliance");
        return false;
    }
    return true;
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) TrustStoreConfiguration(org.gluu.oxtrust.model.cert.TrustStoreConfiguration) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) TrustStoreCertificate(org.gluu.oxtrust.model.cert.TrustStoreCertificate)

Aggregations

BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)29 IOException (java.io.IOException)7 ArrayList (java.util.ArrayList)6 GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)5 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)4 Date (java.util.Date)3 OxAuthClient (org.gluu.oxtrust.model.OxAuthClient)3 LdapEntryManager (org.gluu.persist.ldap.impl.LdapEntryManager)3 CustomScript (org.xdi.model.custom.script.model.CustomScript)3 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 ParseException (java.text.ParseException)2 JsonParseException (org.codehaus.jackson.JsonParseException)2 JsonMappingException (org.codehaus.jackson.map.JsonMappingException)2 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)2 GluuStatus (org.gluu.persist.model.base.GluuStatus)2 AppConfiguration (org.xdi.config.oxtrust.AppConfiguration)2 SelectableEntity (org.xdi.model.SelectableEntity)2 UmaScopeDescription (org.xdi.oxauth.model.uma.persistence.UmaScopeDescription)2 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1