Search in sources :

Example 31 with GluuSAMLTrustRelationship

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

Example 32 with GluuSAMLTrustRelationship

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

the class TrustRelationshipWebService method convertTRtoTRShort.

private static List<SAMLTrustRelationshipShort> convertTRtoTRShort(List<GluuSAMLTrustRelationship> trustRelationships) {
    ArrayList<SAMLTrustRelationshipShort> trustRelationshipsShort = new ArrayList<SAMLTrustRelationshipShort>();
    trustRelationshipsShort.ensureCapacity(trustRelationships.size());
    for (GluuSAMLTrustRelationship tr : trustRelationships) {
        trustRelationshipsShort.add(new SAMLTrustRelationshipShort(tr));
    }
    return trustRelationshipsShort;
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) ArrayList(java.util.ArrayList)

Example 33 with GluuSAMLTrustRelationship

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

the class TrustRelationshipWebService method saveTR.

private void saveTR(GluuSAMLTrustRelationship trustRelationship, boolean isUpdate) {
    logger.trace("Saving Trust Relationship");
    if (isUpdate) {
        String oldLogoutRedirectUri = trustService.getRelationshipByDn(trustRelationship.getDn()).getSpLogoutURL();
        String newLogoutRedirectUri = trustRelationship.getSpLogoutURL();
        boolean oxClientUpdateNeeded = (oldLogoutRedirectUri != null) && (newLogoutRedirectUri != null) && !newLogoutRedirectUri.equals(oldLogoutRedirectUri);
        boolean parentInactive = trustRelationship.getStatus().equals(GluuStatus.INACTIVE);
        // if(! federatedSites.isEmpty()){
        // for (GluuSAMLTrustRelationship trust : federatedSites) {
        // if (parentInactive) {
        // trust.setStatus(GluuStatus.INACTIVE);
        // }
        // trustService.updateReleasedAttributes(trust);
        // trustService.updateTrustRelationship(trust);
        // svnSyncTimer.updateTrustRelationship(trust, identity.getCredentials().getUsername());
        // }
        // }
        trustService.updateTrustRelationship(trustRelationship);
        if (oxClientUpdateNeeded) {
            OxAuthClient client = clientService.getClientByInum(appConfiguration.getOxAuthClientId());
            Set<String> updatedLogoutRedirectUris = new HashSet<String>();
            List<GluuSAMLTrustRelationship> trs = trustService.getAllTrustRelationships();
            if (trs != null && !trs.isEmpty()) {
                for (GluuSAMLTrustRelationship tr : trs) {
                    String logoutRedirectUri = tr.getSpLogoutURL();
                    if (logoutRedirectUri != null && !logoutRedirectUri.isEmpty()) {
                        updatedLogoutRedirectUris.add(logoutRedirectUri);
                    }
                }
            }
            if (updatedLogoutRedirectUris.isEmpty()) {
                client.setPostLogoutRedirectUris(null);
            } else {
                client.setPostLogoutRedirectUris(updatedLogoutRedirectUris.toArray(new String[0]));
            }
            clientService.updateClient(client);
        }
        svnSyncTimer.updateTrustRelationship(trustRelationship, identity.getCredentials().getUsername());
    } else {
        trustService.addTrustRelationship(trustRelationship);
        svnSyncTimer.addTrustRelationship(trustRelationship, identity.getCredentials().getUsername());
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) OxAuthClient(org.gluu.oxtrust.model.OxAuthClient) HashSet(java.util.HashSet)

Example 34 with GluuSAMLTrustRelationship

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

the class TrustRelationshipWebService method delete.

@DELETE
@Path("/delete/{inum}")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(value = "delete TrustRelationship", notes = "Delete GluuSAMLTrustRelationship.")
@ApiResponses(value = { @ApiResponse(code = 200, message = "OK"), @ApiResponse(code = 500, message = "Server error") })
public void delete(@PathParam("inum") @NotNull String inum, @Context HttpServletResponse response) {
    logger.trace("Delete Trust Relationship");
    try {
        GluuSAMLTrustRelationship trustRelationship = trustService.getRelationshipByInum(inum);
        trustService.removeTrustRelationship(trustRelationship);
    } catch (Exception e) {
        logger.error("delete() Exception", e);
        try {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR");
        } catch (Exception ex) {
        }
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) CertificateEncodingException(java.security.cert.CertificateEncodingException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) IOException(java.io.IOException) Path(javax.ws.rs.Path) DELETE(javax.ws.rs.DELETE) Produces(javax.ws.rs.Produces) ApiOperation(com.wordnik.swagger.annotations.ApiOperation) ApiResponses(com.wordnik.swagger.annotations.ApiResponses)

Example 35 with GluuSAMLTrustRelationship

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

the class TrustRelationshipWebService method getContacts.

@GET
@Path("/get_contacts/{inum}")
@Produces(MediaType.TEXT_PLAIN)
public String getContacts(@PathParam("inum") String trustRelationshipInum, @Context HttpServletResponse response) {
    try {
        GluuSAMLTrustRelationship trustRelationship = trustService.getRelationshipByInum(trustRelationshipInum);
        List<TrustContact> list = trustService.getContacts(trustRelationship);
        // convert to JSON
        return objectMapper.writeValueAsString(list);
    } catch (Exception e) {
        logger.error("getContacts() Exception", e);
        try {
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "INTERNAL SERVER ERROR");
        } catch (Exception ex) {
        }
        return OxTrustConstants.RESULT_FAILURE;
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) TrustContact(org.xdi.model.TrustContact) CertificateEncodingException(java.security.cert.CertificateEncodingException) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) IOException(java.io.IOException) Path(javax.ws.rs.Path) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

GluuSAMLTrustRelationship (org.gluu.oxtrust.model.GluuSAMLTrustRelationship)51 ArrayList (java.util.ArrayList)17 IOException (java.io.IOException)15 CertificateEncodingException (java.security.cert.CertificateEncodingException)11 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)10 Path (javax.ws.rs.Path)7 Produces (javax.ws.rs.Produces)7 ApiResponses (com.wordnik.swagger.annotations.ApiResponses)6 List (java.util.List)6 File (java.io.File)5 HashSet (java.util.HashSet)5 Consumes (javax.ws.rs.Consumes)4 POST (javax.ws.rs.POST)4 VelocityContext (org.apache.velocity.VelocityContext)4 SubversionFile (org.gluu.oxtrust.model.SubversionFile)4 ApiOperation (com.wordnik.swagger.annotations.ApiOperation)3 HashMap (java.util.HashMap)3 Set (java.util.Set)3 TreeSet (java.util.TreeSet)3 GluuAttribute (org.gluu.model.GluuAttribute)3