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);
}
}
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);
}
}
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;
}
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);
}
}
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;
}
Aggregations