Search in sources :

Example 21 with GluuConfiguration

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

the class ManageCertificateAction method updateTrustCertificates.

private boolean updateTrustCertificates() {
    try {
        GluuConfiguration tmpConfiguration = configurationService.getConfiguration();
        TrustStoreConfiguration currTrustStoreConfiguration = tmpConfiguration.getTrustStoreConfiguration();
        List<TrustStoreCertificate> currTrustStoreCertificates = tmpConfiguration.getTrustStoreCertificates();
        if (currTrustStoreCertificates == null) {
            currTrustStoreCertificates = new ArrayList<TrustStoreCertificate>(0);
        }
        if (!trustStoreConfiguration.equals(currTrustStoreConfiguration) || !trustStoreCertificates.equals(currTrustStoreCertificates)) {
            this.wereAnyChanges = true;
        }
        tmpConfiguration.setTrustStoreConfiguration(trustStoreConfiguration);
        if (trustStoreCertificates.size() == 0) {
            tmpConfiguration.setTrustStoreCertificates(null);
        } else {
            tmpConfiguration.setTrustStoreCertificates(trustStoreCertificates);
        }
        configurationService.updateConfiguration(tmpConfiguration);
    } catch (BasePersistenceException ex) {
        log.error("Failed to update configuration configuration", ex);
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Failed to update configuration");
        return false;
    }
    return true;
}
Also used : TrustStoreConfiguration(org.gluu.oxtrust.model.cert.TrustStoreConfiguration) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) TrustStoreCertificate(org.gluu.oxtrust.model.cert.TrustStoreCertificate) GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration)

Example 22 with GluuConfiguration

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

the class UpdateTrustRelationshipAction 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("#{msgs['mail.trust.released.attribute.plain']}");
            mailMsgHtml += facesMessages.evalResourceAsString("#{msgs['mail.trust.released.attribute.html']}");
            rendererParameters.reset();
            customAttribute.setNew(false);
        }
        releasedAttributes.add(customAttribute.getMetadata().getDn());
    }
    // send email notification
    if (!StringUtils.isEmpty(mailMsgPlain)) {
        try {
            GluuConfiguration configuration = configurationService.getConfiguration();
            if (configuration.getContactEmail() == null || configuration.getContactEmail().isEmpty())
                log.warn("Failed to send the 'Attributes released' notification email: unconfigured contact email");
            else if (configuration.getSmtpConfiguration() == null || StringHelper.isEmpty(configuration.getSmtpConfiguration().getHost()))
                log.warn("Failed to send the 'Attributes released' notification email: unconfigured SMTP server");
            else {
                String subj = facesMessages.evalResourceAsString("#{msgs['mail.trust.released.subject']}");
                rendererParameters.setParameter("trustRelationshipName", trustRelationship.getDisplayName());
                rendererParameters.setParameter("trustRelationshipInum", trustRelationship.getInum());
                String preMsgPlain = facesMessages.evalResourceAsString("#{msgs['mail.trust.released.name.plain']}");
                String preMsgHtml = facesMessages.evalResourceAsString("#{msgs['mail.trust.released.name.html']}");
                boolean result = mailService.sendMail(configuration.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) ArrayList(java.util.ArrayList) GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) CertificateEncodingException(java.security.cert.CertificateEncodingException) BasePersistenceException(org.gluu.persist.exception.BasePersistenceException) IOException(java.io.IOException)

Example 23 with GluuConfiguration

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

the class UpdateOrganizationAction method updateConfiguration.

private void updateConfiguration() {
    GluuConfiguration configurationUpdate = configurationService.getConfiguration();
    configurationUpdate.setPasswordResetAllowed(configuration.isPasswordResetAllowed());
    configurationUpdate.setPassportEnabled(configuration.isPassportEnabled());
    configurationUpdate.setRadiusEnabled(configuration.isRadiusEnabled());
    configurationUpdate.setScimEnabled(configuration.isScimEnabled());
    configurationUpdate.setProfileManagment(configuration.isProfileManagment());
    configurationUpdate.setConfigurationDnsServer(configuration.getConfigurationDnsServer());
    configurationUpdate.setMaxLogSize(configuration.getMaxLogSize());
    configurationUpdate.setContactEmail(configuration.getContactEmail());
    configurationUpdate.setSamlEnabled(configuration.isSamlEnabled());
    configurationUpdate.setSmtpConfiguration(smtpConfiguration);
    configurationService.updateConfiguration(configurationUpdate);
}
Also used : GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration)

Example 24 with GluuConfiguration

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

the class AuthenticationMethodWebResource method updateAuthenticationMethod.

@PUT
@Operation(summary = "Update authentication methods", description = "Update authentication methods")
@ApiResponses(value = { @ApiResponse(responseCode = "200", content = @Content(schema = @Schema(implementation = AuthenticationMethod.class)), description = Constants.RESULT_SUCCESS), @ApiResponse(responseCode = "500", description = "Server error") })
@ProtectedApi(scopes = { WRITE_ACCESS })
public Response updateAuthenticationMethod(AuthenticationMethod method) {
    log(logger, "Processing updateAuthenticationMethod()");
    try {
        Preconditions.checkNotNull(method, "Attempt to update null method");
        GluuConfiguration configuration = configurationService.getConfiguration();
        if (method.getDefaultAcr() != null || method.getOxtrustAcr() != null) {
            configuration.setAuthenticationMode(method.getDefaultAcr());
            configuration.setOxTrustAuthenticationMode(method.getOxtrustAcr());
            configurationService.updateConfiguration(configuration);
            configuration = configurationService.getConfiguration();
            method.setDefaultAcr(configuration.getAuthenticationMode());
            method.setOxtrustAcr(configuration.getOxTrustAuthenticationMode());
            return Response.ok(method).build();
        } else {
            return Response.status(Response.Status.PRECONDITION_FAILED).build();
        }
    } catch (Exception e) {
        log(logger, e);
        return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build();
    }
}
Also used : GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) ProtectedApi(org.gluu.oxtrust.service.filter.ProtectedApi) Operation(io.swagger.v3.oas.annotations.Operation) PUT(javax.ws.rs.PUT) ApiResponses(io.swagger.v3.oas.annotations.responses.ApiResponses)

Example 25 with GluuConfiguration

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

the class CertificatesWebResource method trustStoreCertificates.

private List<X509CertificateShortInfo> trustStoreCertificates() {
    try {
        trustStoreCertificates = new ArrayList<X509CertificateShortInfo>();
        GluuConfiguration configuration = configurationService.getConfiguration();
        List<TrustStoreCertificate> trustStoreCertificatesList = configuration.getTrustStoreCertificates();
        if (trustStoreCertificatesList != null) {
            for (TrustStoreCertificate trustStoreCertificate : trustStoreCertificatesList) {
                try {
                    X509Certificate[] certs = SSLService.loadCertificates(trustStoreCertificate.getCertificate().getBytes());
                    for (X509Certificate cert : certs) {
                        X509CertificateShortInfo entry = new X509CertificateShortInfo(trustStoreCertificate.getName(), cert);
                        trustStoreCertificates.add(entry);
                    }
                } catch (Exception e) {
                    logger.error("Certificate load exception", e);
                }
            }
        }
    } catch (Exception e) {
        logger.error("Load trustStoreCertificates configuration exception", e);
    }
    return trustStoreCertificates;
}
Also used : X509CertificateShortInfo(org.gluu.oxtrust.util.X509CertificateShortInfo) TrustStoreCertificate(org.gluu.oxtrust.model.cert.TrustStoreCertificate) GluuConfiguration(org.gluu.oxtrust.model.GluuConfiguration) X509Certificate(java.security.cert.X509Certificate)

Aggregations

GluuConfiguration (org.gluu.oxtrust.model.GluuConfiguration)32 Date (java.util.Date)8 IOException (java.io.IOException)6 BasePersistenceException (org.gluu.persist.exception.BasePersistenceException)6 Operation (io.swagger.v3.oas.annotations.Operation)5 ApiResponses (io.swagger.v3.oas.annotations.responses.ApiResponses)5 ProtectedApi (org.gluu.oxtrust.service.filter.ProtectedApi)5 TrustStoreCertificate (org.gluu.oxtrust.model.cert.TrustStoreCertificate)4 Parameters (org.testng.annotations.Parameters)3 Test (org.testng.annotations.Test)3 X509Certificate (java.security.cert.X509Certificate)2 ArrayList (java.util.ArrayList)2 GET (javax.ws.rs.GET)2 PUT (javax.ws.rs.PUT)2 AppConfiguration (org.gluu.config.oxtrust.AppConfiguration)2 SmtpConfiguration (org.gluu.model.SmtpConfiguration)2 GluuOxTrustStat (org.gluu.oxtrust.model.GluuOxTrustStat)2 TrustStoreConfiguration (org.gluu.oxtrust.model.cert.TrustStoreConfiguration)2 X509CertificateShortInfo (org.gluu.oxtrust.util.X509CertificateShortInfo)2 File (java.io.File)1