Search in sources :

Example 6 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 7 with ExternalContext

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

the class ScopeDescriptionDownloadAction method downloadIcon.

public void downloadIcon() {
    byte[] resultFile = null;
    ScopeDescription scopeDescription = getScopeDescription();
    if (scopeDescription != null) {
        GluuImage gluuImage = imageService.getGluuImageFromXML(scopeDescription.getFaviconImageAsXml());
        try {
            resultFile = imageService.getThumImageData(gluuImage);
        } catch (Exception ex) {
            log.error("Failed to generate image response", ex);
        }
    }
    FacesContext facesContext = FacesContext.getCurrentInstance();
    ExternalContext externalContext = facesContext.getExternalContext();
    if (resultFile == null) {
        HttpServletResponse response = (HttpServletResponse) externalContext.getResponse();
        FileDownloader.sendError(response, "Failed to prepare icon");
    } else {
        ContentDisposition contentDisposition = download ? ContentDisposition.ATTACHEMENT : ContentDisposition.NONE;
        ResponseHelper.downloadFile(scopeDescription.getId() + ".jpg", "image/jpeg", resultFile, contentDisposition, facesContext);
    }
}
Also used : FacesContext(javax.faces.context.FacesContext) ContentDisposition(org.xdi.util.io.FileDownloader.ContentDisposition) ExternalContext(javax.faces.context.ExternalContext) GluuImage(org.xdi.model.GluuImage) HttpServletResponse(javax.servlet.http.HttpServletResponse) LdapMappingException(org.gluu.site.ldap.persistence.exception.LdapMappingException) ScopeDescription(org.xdi.oxauth.model.uma.persistence.ScopeDescription)

Example 8 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 9 with ExternalContext

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

the class ClientWindowHelper method handleInitialRedirect.

/**
     * Handles the initial redirect for the LAZY mode, if no windowId is available in the current request URL.
     *
     * @param facesContext the {@link FacesContext}
     * @param newWindowId the new windowId
     */
public static void handleInitialRedirect(FacesContext facesContext, String newWindowId) {
    // store the new windowId as context attribute to prevent infinite loops
    // #sendRedirect will append the windowId (from ClientWindow#getWindowId again) to the redirectUrl
    facesContext.getAttributes().put(INITIAL_REDIRECT_WINDOW_ID, newWindowId);
    ExternalContext externalContext = facesContext.getExternalContext();
    String url = constructRequestUrl(externalContext);
    // remember the initial redirect windowId till the next request - see #729
    addRequestWindowIdCookie(facesContext, newWindowId, newWindowId);
    try {
        externalContext.redirect(url);
    } catch (IOException e) {
        throw new FacesException("Could not send initial redirect!", e);
    }
}
Also used : ExternalContext(javax.faces.context.ExternalContext) IOException(java.io.IOException) FacesException(javax.faces.FacesException)

Example 10 with ExternalContext

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

the class JsfUtils method getViewConfigPageParameters.

public static Set<RequestParameter> getViewConfigPageParameters() {
    ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
    Set<RequestParameter> result = new HashSet<RequestParameter>();
    if (//detection of early config for different mojarra versions
    externalContext == null || externalContext.getRequestParameterValuesMap() == null || externalContext.getRequest() == null) {
        return result;
    }
    NavigationParameterContext navigationParameterContext = BeanProvider.getContextualReference(NavigationParameterContext.class);
    for (Map.Entry<String, String> entry : navigationParameterContext.getPageParameters().entrySet()) {
        //TODO add multi-value support
        result.add(new RequestParameter(entry.getKey(), new String[] { entry.getValue() }));
    }
    return result;
}
Also used : NavigationParameterContext(org.apache.deltaspike.core.api.config.view.navigation.NavigationParameterContext) ExternalContext(javax.faces.context.ExternalContext) Map(java.util.Map) HashSet(java.util.HashSet)

Aggregations

ExternalContext (javax.faces.context.ExternalContext)12 FacesContext (javax.faces.context.FacesContext)5 IOException (java.io.IOException)2 FacesException (javax.faces.FacesException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 LdapMappingException (org.gluu.site.ldap.persistence.exception.LdapMappingException)2 ScopeDescription (org.xdi.oxauth.model.uma.persistence.ScopeDescription)2 ContentDisposition (org.xdi.util.io.FileDownloader.ContentDisposition)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 PrivilegedActionException (java.security.PrivilegedActionException)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 ConfigurableNavigationHandler (javax.faces.application.ConfigurableNavigationHandler)1 ExceptionQueuedEvent (javax.faces.event.ExceptionQueuedEvent)1 ExceptionQueuedEventContext (javax.faces.event.ExceptionQueuedEventContext)1 HttpSession (javax.servlet.http.HttpSession)1 NavigationParameterContext (org.apache.deltaspike.core.api.config.view.navigation.NavigationParameterContext)1