Search in sources :

Example 36 with GluuAppliance

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);
    }
}
Also used : GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) CacheRefreshConfiguration(org.xdi.config.oxtrust.CacheRefreshConfiguration)

Example 37 with GluuAppliance

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;
}
Also used : GluuAppliance(org.gluu.oxtrust.model.GluuAppliance)

Example 38 with GluuAppliance

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.");
    }
}
Also used : GluuSAMLTrustRelationship(org.gluu.oxtrust.model.GluuSAMLTrustRelationship) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) ArrayList(java.util.ArrayList) IOException(java.io.IOException) GluuAttribute(org.xdi.model.GluuAttribute) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) SubversionFile(org.gluu.oxtrust.model.SubversionFile) File(java.io.File)

Example 39 with GluuAppliance

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");
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) AppConfiguration(org.xdi.config.oxtrust.AppConfiguration) BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) ParseException(java.text.ParseException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Date(java.util.Date)

Example 40 with GluuAppliance

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);
    }
}
Also used : GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) ArrayList(java.util.ArrayList)

Aggregations

GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)40 Date (java.util.Date)8 IOException (java.io.IOException)7 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)7 BaseMappingException (org.gluu.persist.exception.mapping.BaseMappingException)7 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)5 PasswordResetRequest (org.gluu.oxtrust.model.PasswordResetRequest)5 SimpleDateFormat (java.text.SimpleDateFormat)4 File (java.io.File)3 ArrayList (java.util.ArrayList)3 Calendar (java.util.Calendar)3 BaseTest (org.gluu.oxtrust.action.test.BaseTest)3 TrustStoreCertificate (org.gluu.oxtrust.model.cert.TrustStoreCertificate)3 Test (org.testng.annotations.Test)3 SmtpConfiguration (org.xdi.model.SmtpConfiguration)3 ParseException (java.text.ParseException)2 ExternalContext (javax.faces.context.ExternalContext)2 FacesContext (javax.faces.context.FacesContext)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 JsonGenerationException (org.codehaus.jackson.JsonGenerationException)2