use of org.gluu.oxtrust.model.GluuAppliance in project oxTrust by GluuFederation.
the class CacheRefreshTimer method processInt.
public void processInt() {
CacheRefreshConfiguration cacheRefreshConfiguration = configurationFactory.getCacheRefreshConfiguration();
try {
GluuAppliance currentAppliance = applianceService.getAppliance();
if (!isStartCacheRefresh(cacheRefreshConfiguration, currentAppliance)) {
log.debug("Starting conditions aren't reached");
return;
}
processImpl(cacheRefreshConfiguration, currentAppliance);
updateApplianceStatus(currentAppliance, System.currentTimeMillis());
this.lastFinishedTime = System.currentTimeMillis();
} catch (Throwable ex) {
log.error("Exception happened while executing cache refresh synchronization", ex);
}
}
use of org.gluu.oxtrust.model.GluuAppliance in project oxTrust by GluuFederation.
the class ApplianceService method getAppliance.
/**
* Get appliance
*
* @return Appliance
* @throws Exception
*/
public GluuAppliance getAppliance(String[] returnAttributes) {
GluuAppliance result = null;
if (ldapEntryManager.contains(GluuAppliance.class, getDnForAppliance(getApplianceInum()))) {
result = ldapEntryManager.find(GluuAppliance.class, getDnForAppliance(getApplianceInum()), returnAttributes);
} else {
result = new GluuAppliance();
result.setInum(getApplianceInum());
result.setDn(getDnForAppliance(getApplianceInum()));
ldapEntryManager.persist(result);
}
return result;
}
use of org.gluu.oxtrust.model.GluuAppliance in project oxTrust by GluuFederation.
the class Shibboleth3ConfService method addGluuSP.
/**
* Adds Trust relationship for own shibboleth SP and restarts services after
* done.
*
* @author �Oleksiy Tataryn�
*/
public void addGluuSP() {
String gluuSPInum = trustService.generateInumForNewTrustRelationship();
String metadataFN = getSpNewMetadataFileName(gluuSPInum);
GluuSAMLTrustRelationship gluuSP = new GluuSAMLTrustRelationship();
gluuSP.setInum(gluuSPInum);
gluuSP.setDisplayName("gluu SP on appliance");
gluuSP.setDescription("Trust Relationship for the SP");
gluuSP.setSpMetaDataSourceType(GluuMetadataSourceType.FILE);
gluuSP.setSpMetaDataFN(metadataFN);
// TODO:
gluuSP.setEntityId(StringHelper.removePunctuation(gluuSP.getInum()));
gluuSP.setUrl(appConfiguration.getApplianceUrl());
String certificate = "";
boolean result = false;
try {
certificate = FileUtils.readFileToString(new File(appConfiguration.getGluuSpCert())).replaceAll("-{5}.*?-{5}", "");
generateSpMetadataFile(gluuSP, certificate);
result = isCorrectSpMetadataFile(gluuSP.getSpMetaDataFN());
} catch (IOException e) {
log.error("Failed to gluu SP read certificate file.", e);
}
GluuAppliance appliance = null;
if (result) {
gluuSP.setStatus(GluuStatus.ACTIVE);
String inum = gluuSP.getInum();
String dn = trustService.getDnForTrustRelationShip(inum);
gluuSP.setDn(dn);
List<GluuCustomAttribute> customAttributes = new ArrayList<GluuCustomAttribute>();
List<GluuAttribute> attributes = attributeService.getAllPersonAttributes(GluuUserRole.ADMIN);
HashMap<String, GluuAttribute> attributesByDNs = attributeService.getAttributeMapByDNs(attributes);
List<String> customAttributeDNs = new ArrayList<String>();
List<String> attributeNames = new ArrayList<String>();
for (String attributeName : appConfiguration.getGluuSpAttributes()) {
GluuAttribute attribute = attributeService.getAttributeByName(attributeName, attributes);
if (attribute != null) {
customAttributeDNs.add(attribute.getDn());
}
}
customAttributes.addAll(attributeService.getCustomAttributesByAttributeDNs(customAttributeDNs, attributesByDNs));
gluuSP.setReleasedCustomAttributes(customAttributes);
gluuSP.setReleasedAttributes(attributeNames);
trustService.updateReleasedAttributes(gluuSP);
trustService.addTrustRelationship(gluuSP);
appliance = applianceService.getAppliance();
appliance.setGluuSPTR(gluuSP.getInum());
}
if (result) {
applianceService.updateAppliance(appliance);
log.warn("gluuSP EntityID set to " + StringHelper.removePunctuation(gluuSP.getInum()) + ". Shibboleth3 configuration should be updated.");
// applianceService.restartServices();
} else {
log.error("IDP configuration update failed. GluuSP was not generated.");
}
}
use of org.gluu.oxtrust.model.GluuAppliance in project oxTrust by GluuFederation.
the class StatusCheckerTimer method processInt.
/**
* Gather periodically site and server status
*
* @param when
* Date
* @param interval
* Interval
*/
private void processInt() {
log.debug("Starting update of appliance status");
AppConfiguration appConfiguration = configurationFactory.getAppConfiguration();
if (!appConfiguration.isUpdateApplianceStatus()) {
return;
}
GluuAppliance appliance;
try {
appliance = applianceService.getAppliance();
} catch (BaseMappingException ex) {
log.error("Failed to load current appliance", ex);
return;
}
// Execute facter and update appliance attributes
setFactorAttributes(appliance);
// Execute df and update appliance attributes
setDfAttributes(appliance);
// Set HTTPD attributes
setHttpdAttributes(appliance);
try {
setCertificateExpiryAttributes(appliance);
} catch (Exception ex) {
log.error("Failed to check certificate expiration", ex);
}
// setVDSAttributes(appliance);
Date currentDateTime = new Date();
appliance.setLastUpdate(currentDateTime);
try {
applianceService.updateAppliance(appliance);
} catch (BaseMappingException ex) {
log.error("Failed to update current appliance", ex);
return;
}
if (centralLdapService.isUseCentralServer()) {
try {
GluuAppliance tmpAppliance = new GluuAppliance();
tmpAppliance.setDn(appliance.getDn());
boolean existAppliance = centralLdapService.containsAppliance(tmpAppliance);
if (existAppliance) {
centralLdapService.updateAppliance(appliance);
} else {
centralLdapService.addAppliance(appliance);
}
} catch (BaseMappingException ex) {
log.error("Failed to update appliance at central server", ex);
return;
}
}
log.debug("Appliance status update finished");
}
use of org.gluu.oxtrust.model.GluuAppliance in project oxTrust by GluuFederation.
the class TrustService method updateReleasedAttributes.
public void updateReleasedAttributes(GluuSAMLTrustRelationship trustRelationship) {
List<String> releasedAttributes = new ArrayList<String>();
String mailMsgPlain = "";
String mailMsgHtml = "";
for (GluuCustomAttribute customAttribute : trustRelationship.getReleasedCustomAttributes()) {
if (customAttribute.isNew()) {
rendererParameters.setParameter("attributeName", customAttribute.getName());
rendererParameters.setParameter("attributeDisplayName", customAttribute.getMetadata().getDisplayName());
rendererParameters.setParameter("attributeValue", customAttribute.getValue());
mailMsgPlain += facesMessages.evalResourceAsString("#{msg['mail.trust.released.attribute.plain']}");
mailMsgHtml += facesMessages.evalResourceAsString("#{msg['mail.trust.released.attribute.html']}");
rendererParameters.reset();
customAttribute.setNew(false);
}
releasedAttributes.add(customAttribute.getMetadata().getDn());
}
// send email notification
if (!StringUtils.isEmpty(mailMsgPlain)) {
try {
GluuAppliance appliance = applianceService.getAppliance();
if (appliance.getContactEmail() == null || appliance.getContactEmail().isEmpty())
log.warn("Failed to send the 'Attributes released' notification email: unconfigured contact email");
else if (appliance.getSmtpConfiguration() == null || StringHelper.isEmpty(appliance.getSmtpConfiguration().getHost()))
log.warn("Failed to send the 'Attributes released' notification email: unconfigured SMTP server");
else {
String subj = facesMessages.evalResourceAsString("#{msg['mail.trust.released.subject']}");
rendererParameters.setParameter("trustRelationshipName", trustRelationship.getDisplayName());
rendererParameters.setParameter("trustRelationshipInum", trustRelationship.getInum());
String preMsgPlain = facesMessages.evalResourceAsString("#{msg['mail.trust.released.name.plain']}");
String preMsgHtml = facesMessages.evalResourceAsString("#{msg['mail.trust.released.name.html']}");
// rendererParameters.setParameter("mail_body", preMsgHtml + mailMsgHtml);
// String mailHtml = renderService.renderView("/WEB-INF/mail/trust_relationship.xhtml");
boolean result = mailService.sendMail(appliance.getContactEmail(), null, subj, preMsgPlain + mailMsgPlain, preMsgHtml + mailMsgHtml);
if (!result) {
log.error("Failed to send the notification email");
}
}
} catch (Exception ex) {
log.error("Failed to send the notification email: ", ex);
}
}
if (!releasedAttributes.isEmpty()) {
trustRelationship.setReleasedAttributes(releasedAttributes);
} else {
trustRelationship.setReleasedAttributes(null);
}
}
Aggregations