Search in sources :

Example 1 with GluuStatus

use of org.gluu.persist.model.base.GluuStatus 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 2 with GluuStatus

use of org.gluu.persist.model.base.GluuStatus in project oxTrust by GluuFederation.

the class UpdateTrustRelationshipAction method saveImpl.

public String saveImpl() {
    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:
                try {
                    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;
                    }
                } catch (IOException ex) {
                    log.error("Failed to download SP certificate", ex);
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to download SP certificate");
                    return OxTrustConstants.RESULT_FAILURE;
                }
                break;
            case FILE:
                try {
                    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;
                    }
                } catch (IOException ex) {
                    log.error("Failed to download SP metadata", ex);
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to download SP metadata");
                    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) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "Unable to download metadata");
                    return "unable_download_metadata";
                }
                break;
            case FEDERATION:
                if (!update) {
                    this.trustRelationship.setStatus(GluuStatus.ACTIVE);
                }
                if (this.trustRelationship.getEntityId() == null) {
                    facesMessages.add(FacesMessage.SEVERITY_ERROR, "EntityID must be set to a value");
                    return "invalid_entity_id";
                }
                break;
            default:
                break;
        }
        trustService.updateReleasedAttributes(this.trustRelationship);
        // We call it from TR validation timer
        if (trustRelationship.getSpMetaDataSourceType().equals(GluuMetadataSourceType.GENERATE) || (trustRelationship.getSpMetaDataSourceType().equals(GluuMetadataSourceType.FEDERATION))) {
            boolean federation = shibboleth3ConfService.isFederation(this.trustRelationship);
            this.trustRelationship.setFederation(federation);
        }
        trustContactsAction.saveContacts();
        if (update) {
            try {
                saveTR(update);
            } catch (BaseMappingException ex) {
                log.error("Failed to update trust relationship {}", inum, ex);
                return OxTrustConstants.RESULT_FAILURE;
            }
        } else {
            String dn = trustService.getDnForTrustRelationShip(this.inum);
            // Save trustRelationship
            this.trustRelationship.setDn(dn);
            try {
                saveTR(update);
            } catch (BaseMappingException ex) {
                log.error("Failed to add new trust relationship {}", this.trustRelationship.getInum(), ex);
                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) 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)

Aggregations

IOException (java.io.IOException)2 CertificateEncodingException (java.security.cert.CertificateEncodingException)2 GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)2 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)2 GluuStatus (org.gluu.persist.model.base.GluuStatus)2