Search in sources :

Example 31 with GluuAppliance

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

the class ConfigureLogViewerAction method updateAppliance.

private void updateAppliance() {
    GluuAppliance updateAppliance = applianceService.getAppliance();
    try {
        updateAppliance.setOxLogViewerConfig(jsonService.objectToJson(logViewerConfiguration));
        updateAppliance.setOxLogConfigLocation(oxTrustLogConfigLocation);
        applianceService.updateAppliance(updateAppliance);
        loggerService.updateLoggerConfigLocation();
    } catch (Exception ex) {
        log.error("Failed to save log viewer configuration '{}'", ex);
    }
}
Also used : GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) IOException(java.io.IOException)

Example 32 with GluuAppliance

use of org.gluu.oxtrust.model.GluuAppliance 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;
}
Also used : BaseMappingException(org.gluu.persist.exception.mapping.BaseMappingException) TrustStoreConfiguration(org.gluu.oxtrust.model.cert.TrustStoreConfiguration) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) TrustStoreCertificate(org.gluu.oxtrust.model.cert.TrustStoreCertificate)

Example 33 with GluuAppliance

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

the class PasswordReminderAction method requestReminderImpl.

public String requestReminderImpl() throws Exception {
    if (enabled()) {
        FacesContext facesContext = FacesContext.getCurrentInstance();
        if (facesContext == null) {
            return OxTrustConstants.RESULT_FAILURE;
        }
        ExternalContext externalContext = facesContext.getExternalContext();
        if (externalContext == null) {
            return OxTrustConstants.RESULT_FAILURE;
        }
        HttpServletRequest httpServletRequest = (HttpServletRequest) externalContext.getRequest();
        GluuCustomPerson person = new GluuCustomPerson();
        person.setMail(email);
        List<GluuCustomPerson> matchedPersons = personService.findPersons(person, 0);
        if (matchedPersons != null && matchedPersons.size() > 0) {
            GluuAppliance appliance = applianceService.getAppliance();
            OrganizationalUnit requests = new OrganizationalUnit();
            requests.setOu("resetPasswordRequests");
            requests.setDn("ou=resetPasswordRequests," + appliance.getDn());
            if (!ldapEntryManager.contains(requests)) {
                ldapEntryManager.persist(requests);
            }
            PasswordResetRequest request = new PasswordResetRequest();
            do {
                request.setCreationDate(Calendar.getInstance().getTime());
                request.setPersonInum(matchedPersons.get(0).getInum());
                request.setOxGuid(StringHelper.getRandomString(16));
                request.setBaseDn("oxGuid=" + request.getOxGuid() + ", ou=resetPasswordRequests," + appliance.getDn());
            } while (ldapEntryManager.contains(request));
            rendererParameters.setParameter("givenName", matchedPersons.get(0).getGivenName());
            rendererParameters.setParameter("organizationName", organizationService.getOrganization().getDisplayName());
            rendererParameters.setParameter("resetLink", appConfiguration.getApplianceUrl() + httpServletRequest.getContextPath() + "/resetPassword/" + request.getOxGuid());
            String subj = facesMessages.evalResourceAsString("#{msg['mail.reset.found.message.subject']}");
            String messagePlain = facesMessages.evalResourceAsString("#{msg['mail.reset.found.message.plain.body']}");
            String messageHtml = facesMessages.evalResourceAsString("#{msg['mail.reset.found.message.html.body']}");
            // rendererParameters.setParameter("mail_body", messageHtml);
            // String mailHtml = renderService.renderView("/WEB-INF/mail/reset_password.xhtml");
            mailService.sendMail(email, null, subj, messagePlain, messageHtml);
            ldapEntryManager.persist(request);
        } else {
            GluuAppliance appliance = applianceService.getAppliance();
            SmtpConfiguration smtpConfiguration = appliance.getSmtpConfiguration();
            rendererParameters.setParameter("organizationName", organizationService.getOrganization().getDisplayName());
            String fromName = smtpConfiguration.getFromName();
            if (fromName == null) {
                fromName = String.format("%1$s identity server", organizationService.getOrganization().getDisplayName());
            }
            String subj = facesMessages.evalResourceAsString("#{msg['mail.reset.not_found.message.subject']}");
            String messagePlain = facesMessages.evalResourceAsString("#{msg['mail.reset.not_found.message.plain.body']}");
            String messageHtml = facesMessages.evalResourceAsString("#{msg['mail.reset.not_found.message.html.body']}");
            // rendererParameters.setParameter("mail_body", messageHtml);
            // String mailHtml = renderService.renderView("/WEB-INF/mail/reset_password.xhtml");
            mailService.sendMail(null, fromName, email, null, subj, messagePlain, messageHtml);
        }
        return OxTrustConstants.RESULT_SUCCESS;
    }
    return OxTrustConstants.RESULT_FAILURE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) FacesContext(javax.faces.context.FacesContext) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) OrganizationalUnit(org.gluu.oxtrust.model.OrganizationalUnit) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) SmtpConfiguration(org.xdi.model.SmtpConfiguration) ExternalContext(javax.faces.context.ExternalContext)

Example 34 with GluuAppliance

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

the class PasswordReminderAction method enabled.

public boolean enabled() {
    GluuAppliance appliance = applianceService.getAppliance();
    SmtpConfiguration smtpConfiguration = appliance.getSmtpConfiguration();
    boolean valid = smtpConfiguration != null && smtpConfiguration.getHost() != null && smtpConfiguration.getPort() != 0 && ((!smtpConfiguration.isRequiresAuthentication()) || (smtpConfiguration.getUserName() != null && smtpConfiguration.getPassword() != null)) && appliance.getPasswordResetAllowed() != null && appliance.getPasswordResetAllowed().isBooleanValue();
    if (valid) {
        if (recaptchaService.isEnabled()) {
            valid = recaptchaService.verifyRecaptchaResponse();
            if (!valid)
                facesMessages.add(FacesMessage.SEVERITY_ERROR, "Please check your input and CAPTCHA answer.");
        }
    } else {
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Sorry the Password Reminder functionality is not enabled.Please contact to administrator.");
    }
    return valid;
}
Also used : GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) SmtpConfiguration(org.xdi.model.SmtpConfiguration)

Example 35 with GluuAppliance

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

the class PasswordResetAction method start.

public String start() throws ParseException {
    GluuAppliance appliance = applianceService.getAppliance();
    this.request = ldapEntryManager.find(PasswordResetRequest.class, "oxGuid=" + this.guid + ",ou=resetPasswordRequests," + appliance.getDn());
    Calendar requestCalendarExpiry = Calendar.getInstance();
    Calendar currentCalendar = Calendar.getInstance();
    if (request != null) {
        SimpleDateFormat sdf = new SimpleDateFormat("EEE MMM dd HH:mm:ss z yyyy");
        requestCalendarExpiry.setTime(request.getCreationDate());
        requestCalendarExpiry.add(Calendar.HOUR, 2);
    }
    GluuCustomPerson person = personService.getPersonByInum(request.getPersonInum());
    GluuCustomAttribute question = null;
    if (person != null) {
        question = person.getGluuCustomAttribute("secretQuestion");
    }
    if (request != null && requestCalendarExpiry.after(currentCalendar)) {
        if (question != null) {
            securityQuestion = question.getValue();
        }
        return OxTrustConstants.RESULT_SUCCESS;
    } else {
        facesMessages.add(FacesMessage.SEVERITY_ERROR, "Your link is not valid or your user is not allowed to perform a password reset. If you want to initiate a reset password procedure please fill this form.");
        conversationService.endConversation();
        return OxTrustConstants.RESULT_FAILURE;
    }
}
Also used : PasswordResetRequest(org.gluu.oxtrust.model.PasswordResetRequest) GluuCustomAttribute(org.gluu.oxtrust.model.GluuCustomAttribute) GluuCustomPerson(org.gluu.oxtrust.model.GluuCustomPerson) GluuAppliance(org.gluu.oxtrust.model.GluuAppliance) Calendar(java.util.Calendar) SimpleDateFormat(java.text.SimpleDateFormat)

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