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