Search in sources :

Example 21 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 mailMsg = "";
    for (GluuCustomAttribute customAttribute : trustRelationship.getReleasedCustomAttributes()) {
        if (customAttribute.isNew()) {
            mailMsg += "\nAttribute name: " + customAttribute.getName() + " Display name: " + customAttribute.getMetadata().getDisplayName() + " Attribute value: " + customAttribute.getValue();
            customAttribute.setNew(false);
        }
        releasedAttributes.add(customAttribute.getMetadata().getDn());
    }
    if (!StringUtils.isEmpty(mailMsg)) {
        try {
            String preMsg = "Trust RelationShip name: " + trustRelationship.getDisplayName() + " (inum:" + trustRelationship.getInum() + ")\n\n";
            GluuAppliance appliance = applianceService.getAppliance();
            String subj = "Attributes with Privacy level 5 are released in a Trust Relationaship";
            MailUtils mail = new MailUtils(appliance.getSmtpHost(), appliance.getSmtpPort(), appliance.isRequiresSsl(), appliance.isRequiresAuthentication(), appliance.getSmtpUserName(), applianceService.getDecryptedSmtpPassword(appliance));
            mail.sendMail(appliance.getSmtpFromName() + " <" + appliance.getSmtpFromEmailAddress() + ">", appliance.getContactEmail(), subj, preMsg + mailMsg);
        } catch (AuthenticationFailedException ex) {
            log.error("SMTP Authentication Error: ", ex);
        } catch (MessagingException ex) {
            log.error("SMTP Host Connection Error", ex);
        } 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) AuthenticationFailedException(javax.mail.AuthenticationFailedException) MessagingException(javax.mail.MessagingException) ArrayList(java.util.ArrayList) MessagingException(javax.mail.MessagingException) AuthenticationFailedException(javax.mail.AuthenticationFailedException) MailUtils(org.gluu.oxtrust.util.MailUtils)

Example 22 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 23 with GluuAppliance

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

the class CacheRefreshTimer method processInt.

public void processInt() {
    if (this.isActive.get()) {
        log.debug("Another process is active");
        return;
    }
    CacheRefreshConfiguration cacheRefreshConfiguration = configurationFactory.getCacheRefreshConfiguration();
    if (!this.isActive.compareAndSet(false, true)) {
        log.debug("Failed to start process exclusively");
        return;
    }
    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);
    } finally {
        log.debug("Allowing to run new process exclusively");
        this.isActive.set(false);
    }
}
Also used : GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) CacheRefreshConfiguration(org.xdi.config.oxtrust.CacheRefreshConfiguration)

Example 24 with GluuAppliance

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

the class CacheRefreshTimer method updateApplianceStatus.

private void updateApplianceStatus(GluuAppliance currentAppliance, long lastRun) {
    GluuAppliance appliance = applianceService.getAppliance();
    Date currentDateTime = new Date();
    appliance.setVdsCacheRefreshLastUpdate(currentDateTime);
    appliance.setVdsCacheRefreshLastUpdateCount(currentAppliance.getVdsCacheRefreshLastUpdateCount());
    appliance.setVdsCacheRefreshProblemCount(currentAppliance.getVdsCacheRefreshProblemCount());
    applianceService.updateAppliance(appliance);
}
Also used : GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) Date(java.util.Date)

Example 25 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)

Aggregations

GluuAppliance (org.gluu.oxtrust.model.GluuAppliance)36 Date (java.util.Date)8 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)7 IOException (java.io.IOException)5 GluuCustomPerson (org.gluu.oxtrust.model.GluuCustomPerson)5 GluuCustomAttribute (org.gluu.oxtrust.model.GluuCustomAttribute)4 File (java.io.File)3 SimpleDateFormat (java.text.SimpleDateFormat)3 ArrayList (java.util.ArrayList)3 BaseTest (org.gluu.oxtrust.action.test.BaseTest)3 PasswordResetRequest (org.gluu.oxtrust.model.PasswordResetRequest)3 TrustStoreCertificate (org.gluu.oxtrust.model.cert.TrustStoreCertificate)3 Test (org.testng.annotations.Test)3 ParseException (java.text.ParseException)2 Calendar (java.util.Calendar)2 AuthenticationFailedException (javax.mail.AuthenticationFailedException)2 MessagingException (javax.mail.MessagingException)2 OxIDPAuthConf (org.gluu.oxtrust.model.OxIDPAuthConf)2 TrustStoreConfiguration (org.gluu.oxtrust.model.cert.TrustStoreConfiguration)2 MailUtils (org.gluu.oxtrust.util.MailUtils)2