Search in sources :

Example 6 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.

the class InumService method containsTrustRelationship.

public boolean containsTrustRelationship(String inum, String gluuInum) {
    GluuSAMLTrustRelationship tRelation = new GluuSAMLTrustRelationship();
    tRelation.setBaseDn(String.format("inum=%s,ou=trustRelationships,inum=%s,o=gluu", inum, gluuInum));
    return ldapEntryManager.contains(tRelation);
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship)

Example 7 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship 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 8 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship 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)

Example 9 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.

the class UpdateTrustRelationshipAction method markAsInactive.

private void markAsInactive() {
    // files in meta-data folder
    if (update) {
        try {
            GluuSAMLTrustRelationship tmpTrustRelationship = trustService.getRelationshipByInum(this.trustRelationship.getInum());
            tmpTrustRelationship.setStatus(GluuStatus.INACTIVE);
            saveTR(update);
        } catch (LdapMappingException ex) {
            log.error("Failed to update trust relationship {}", ex, inum);
        }
    } else {
        // Remove file name to generate new one during new save attempt.
        // Cover case when somebody else added new one simultaneously
        this.trustRelationship.setSpMetaDataFN(null);
        this.trustRelationship.setInum(null);
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException)

Example 10 with GluuSAMLTrustRelationship

use of org.gluu.oxtrust.model.GluuSAMLTrustRelationship in project oxTrust by GluuFederation.

the class UpdateTrustRelationshipAction method add.

public String add() {
    if (this.trustRelationship != null) {
        return OxTrustConstants.RESULT_SUCCESS;
    }
    this.update = false;
    this.trustRelationship = new GluuSAMLTrustRelationship();
    this.trustRelationship.setMaxRefreshDelay("PT8H");
    this.fileWrapper = new FileUploadWrapper();
    this.trustRelationship.setOwner(organizationService.getOrganization().getDn());
    boolean initActionsResult = initActions();
    if (!initActionsResult) {
        return OxTrustConstants.RESULT_FAILURE;
    }
    return OxTrustConstants.RESULT_SUCCESS;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) FileUploadWrapper(org.xdi.util.io.FileUploadWrapper)

Aggregations

GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)28 ArrayList (java.util.ArrayList)10 GluuAttribute (org.xdi.model.GluuAttribute)5 File (java.io.File)4 IOException (java.io.IOException)4 SubversionFile (org.gluu.oxtrust.model.SubversionFile)4 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 List (java.util.List)2 TreeSet (java.util.TreeSet)2 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)2 OrganizationalUnit (org.gluu.oxtrust.model.OrganizationalUnit)2 InvalidConfigurationException (org.xdi.util.exception.InvalidConfigurationException)2 Filter (com.unboundid.ldap.sdk.Filter)1 AttributeTypeDefinition (com.unboundid.ldap.sdk.schema.AttributeTypeDefinition)1 FileInputStream (java.io.FileInputStream)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 CertificateEncodingException (java.security.cert.CertificateEncodingException)1 LinkedList (java.util.LinkedList)1