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