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;
}
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;
}
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());
}
}
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) {
}
}
}
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;
}
}
Aggregations