Search in sources :

Example 21 with ExternalContext

use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.

the class PassportProvidersAction method setCallbackUrl.

private void setCallbackUrl() {
    ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
    String hostname = context.getRequestServerName();
    if (hostname == null || hostname.isEmpty()) {
        hostname = configurationService.getConfiguration().getHostname();
    }
    if (this.provider.getType().equalsIgnoreCase("saml")) {
        this.provider.setCallbackUrl(String.format("https://%s/passport/auth/saml/%s/callback", hostname, this.provider.getId()));
    } else {
        this.provider.setCallbackUrl(String.format("https://%s/passport/auth/%s/callback", hostname, this.provider.getId()));
    }
}
Also used : ExternalContext(javax.faces.context.ExternalContext)

Example 22 with ExternalContext

use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.

the class RegisterPersonAction method redirectIfNeeded.

private void redirectIfNeeded() {
    if (postRegistrationRedirectUri != null) {
        try {
            ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
            externalContext.redirect(postRegistrationRedirectUri);
        } catch (IOException e) {
        }
    }
}
Also used : ExternalContext(javax.faces.context.ExternalContext) IOException(java.io.IOException)

Example 23 with ExternalContext

use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.

the class ScopeDescriptionDownloadAction method downloadFile.

public void downloadFile() {
    byte[] resultFile = null;
    ScopeDescription scopeDescription = getScopeDescription();
    if (scopeDescription != null) {
        JSONObject jsonObject = new JSONObject();
        try {
            HashMap<String, List<String>> pageParams = new HashMap<String, List<String>>();
            pageParams.put("scope", Arrays.asList(scopeDescription.getId()));
            String umaScope = viewHandlerService.getBookmarkableURL("/uma/scope/scopeDescriptionFile.xhtml", pageParams);
            jsonObject.put("name", scopeDescription.getId());
            jsonObject.put("icon_uri", umaScope);
            resultFile = jsonObject.toString().getBytes("UTF-8");
        } catch (Exception ex) {
            log.error("Failed to generate json response", ex);
        }
    }
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    if (resultFile == null) {
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        FileDownloader.sendError(response, "Failed to generate json file");
    } else {
        ContentDisposition contentDisposition = download ? ContentDisposition.ATTACHEMENT : ContentDisposition.NONE;
        ResponseHelper.downloadFile(scopeDescription.getId() + ".json", "application/json;charset=UTF-8", resultFile, contentDisposition, facesContext);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) JSONObject(org.codehaus.jettison.json.JSONObject) ContentDisposition(org.xdi.util.io.FileDownloader.ContentDisposition) HashMap(java.util.HashMap) ExternalContext(javax.faces.context.ExternalContext) HttpServletResponse(javax.servlet.http.HttpServletResponse) List(java.util.List) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Example 24 with ExternalContext

use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.

the class PasswordReminderAction method requestReminder.

public String requestReminder() 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));
            String subj = String.format("Password reset was requested at %1$s identity server", organizationService.getOrganization().getDisplayName());
            MailUtils mail = new MailUtils(appliance.getSmtpHost(), appliance.getSmtpPort(), appliance.isRequiresSsl(), appliance.isRequiresAuthentication(), appliance.getSmtpUserName(), applianceService.getDecryptedSmtpPassword(appliance));
            mail.sendMail(appliance.getSmtpFromName() + " <" + appliance.getSmtpFromEmailAddress() + ">", email, subj, String.format(MESSAGE_FOUND, matchedPersons.get(0).getGivenName(), organizationService.getOrganization().getDisplayName(), appConfiguration.getApplianceUrl() + httpServletRequest.getContextPath() + "/resetPassword/" + request.getOxGuid()));
            ldapEntryManager.persist(request);
        } else {
            GluuAppliance appliance = applianceService.getAppliance();
            String subj = String.format("Password reset was requested at %1$s identity server", organizationService.getOrganization().getDisplayName());
            MailUtils mail = new MailUtils(appliance.getSmtpHost(), appliance.getSmtpPort(), appliance.isRequiresSsl(), appliance.isRequiresAuthentication(), appliance.getSmtpUserName(), applianceService.getDecryptedSmtpPassword(appliance));
            String fromName = appliance.getSmtpFromName();
            if (fromName == null) {
                fromName = String.format("%1$s identity server", organizationService.getOrganization().getDisplayName());
            }
            mail.sendMail(fromName + " <" + appliance.getSmtpFromEmailAddress() + ">", email, subj, String.format(MESSAGE_NOT_FOUND, organizationService.getOrganization().getDisplayName()));
        }
        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) ExternalContext(javax.faces.context.ExternalContext) MailUtils(org.gluu.oxtrust.util.MailUtils)

Example 25 with ExternalContext

use of javax.faces.context.ExternalContext in project tomee by apache.

the class TomEEFacesConfigurationProviderFactory method getFacesConfigurationProvider.

@Override
public FacesConfigurationProvider getFacesConfigurationProvider(final ExternalContext externalContext) {
    FacesConfigurationProvider returnValue = (FacesConfigurationProvider) externalContext.getApplicationMap().get(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY);
    if (returnValue == null) {
        final ExternalContext extContext = externalContext;
        try {
            returnValue = resolveFacesConfigurationProviderFromService(extContext);
            externalContext.getApplicationMap().put(FACES_CONFIGURATION_PROVIDER_INSTANCE_KEY, returnValue);
        } catch (final ClassNotFoundException | NoClassDefFoundError e) {
        // ignore
        } catch (final InstantiationException | InvocationTargetException | IllegalAccessException e) {
            getLogger().log(Level.SEVERE, "", e);
        } catch (final PrivilegedActionException e) {
            throw new FacesException(e);
        }
    }
    return returnValue;
}
Also used : PrivilegedActionException(java.security.PrivilegedActionException) ExternalContext(javax.faces.context.ExternalContext) FacesConfigurationProvider(org.apache.myfaces.spi.FacesConfigurationProvider) InvocationTargetException(java.lang.reflect.InvocationTargetException) FacesException(javax.faces.FacesException)

Aggregations

ExternalContext (javax.faces.context.ExternalContext)58 FacesContext (javax.faces.context.FacesContext)28 Test (org.junit.Test)17 HttpServletRequest (javax.servlet.http.HttpServletRequest)13 HashMap (java.util.HashMap)11 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)9 Map (java.util.Map)7 IOException (java.io.IOException)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)5 File (java.io.File)4 Method (java.lang.reflect.Method)4 Locale (java.util.Locale)4 FacesException (javax.faces.FacesException)4 Flash (javax.faces.context.Flash)4 InvocationContext (javax.interceptor.InvocationContext)4 ExceptionQueuedEvent (javax.faces.event.ExceptionQueuedEvent)3 ExceptionQueuedEventContext (javax.faces.event.ExceptionQueuedEventContext)3 FileInputStream (java.io.FileInputStream)2 InputStream (java.io.InputStream)2 Date (java.util.Date)2