use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.
the class PasswordResetAction method redirect.
public void redirect() {
try {
ExternalContext externalContext = FacesContext.getCurrentInstance().getExternalContext();
externalContext.redirect("/identity/passwordResetResult.htm");
} catch (Exception e) {
log.warn("Error redirecting to password reset result page");
}
}
use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.
the class ConfigurationStatusAction method getHostName.
public String getHostName(String hostName) {
if (hostName == null || StringUtils.isEmpty(hostName)) {
ExternalContext context = FacesContext.getCurrentInstance().getExternalContext();
hostName = context.getRequestServerName();
}
return hostName;
}
use of javax.faces.context.ExternalContext in project oxTrust by GluuFederation.
the class PasswordReminderAction method requestReminderImpl.
public String requestReminderImpl() throws Exception {
if (enabled()) {
FacesContext facesContext = FacesContext.getCurrentInstance();
ExternalContext externalContext = facesContext.getExternalContext();
if (facesContext == null || 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) {
passwordResetService.prepareBranch();
PasswordResetRequest request = new PasswordResetRequest();
String guid = passwordResetService.generateGuidForNewPasswordResetRequest();
Date creationTime = Calendar.getInstance(TimeZone.getTimeZone("UTC")).getTime();
request.setCreationDate(creationTime);
request.setPersonInum(matchedPersons.get(0).getInum());
request.setOxGuid(guid);
request.setDn(passwordResetService.getDnForPasswordResetRequest(guid));
int value = this.oxTrustappConfiguration.getPasswordResetRequestExpirationTime() / 60;
// Set expiration time
request.setExpirationDate(DateUtils.addSeconds(creationTime, appConfiguration.getPasswordResetRequestExpirationTime()));
int ttl = (int) ((request.getExpirationDate().getTime() - creationTime.getTime()) / 1000L);
request.setTtl(ttl);
String expirationTime = Integer.toString(value) + " minute(s)";
rendererParameters.setParameter("expirationTime", expirationTime);
rendererParameters.setParameter("givenName", matchedPersons.get(0).getGivenName());
rendererParameters.setParameter("organizationName", organizationService.getOrganization().getDisplayName());
rendererParameters.setParameter("resetLink", appConfiguration.getApplicationUrl() + httpServletRequest.getContextPath() + "/resetPassword.htm?guid=" + request.getOxGuid());
String subj = facesMessages.evalResourceAsString("#{msgs['mail.reset.found.message.subject']}");
String messagePlain = facesMessages.evalResourceAsString("#{msgs['mail.reset.found.message.plain.body']}");
String messageHtml = facesMessages.evalResourceAsString("#{msgs['mail.reset.found.message.html.body']}");
mailService.sendMail(email, null, subj, messagePlain, messageHtml);
passwordResetService.addPasswordResetRequest(request);
try {
oxTrustAuditService.audit("PASSWORD REMINDER REQUEST" + request.getBaseDn() + " ADDED", identity.getUser(), (HttpServletRequest) FacesContext.getCurrentInstance().getExternalContext().getRequest());
} catch (Exception e) {
}
}
facesMessages.add(FacesMessage.SEVERITY_INFO, facesMessages.evalResourceAsString("#{msgs['resetPasswordSuccess.pleaseCheckYourEmail']}"));
return OxTrustConstants.RESULT_SUCCESS;
}
return OxTrustConstants.RESULT_FAILURE;
}
use of javax.faces.context.ExternalContext in project Payara by payara.
the class WoodstockHandler method createHyperlinkArray.
@Handler(id = "createHyperlinkArray", output = { @HandlerOutput(name = "links", type = Hyperlink[].class) })
public static void createHyperlinkArray(HandlerContext handlerCtx) {
FacesContext ctx = handlerCtx.getFacesContext();
ExternalContext extCtx = ctx.getExternalContext();
Map<String, String[]> reqParams = extCtx.getRequestParameterValuesMap();
String[] linkText = reqParams.get("text");
String[] linkUrl = reqParams.get("urls");
if (linkText == null) {
// No data! Should we add something here anyway?
return;
}
int len = linkText.length;
Hyperlink[] arr = new Hyperlink[len];
String url = null;
String ctxPath = extCtx.getRequestContextPath();
int ctxPathSize = ctxPath.length();
for (int idx = 0; idx < len; idx++) {
// FIXME: Set parent
arr[idx] = new Hyperlink();
arr[idx].setId("bcLnk" + idx);
// Set rendererType to avoid using widget renderer!!
arr[idx].setRendererType("com.sun.webui.jsf.Hyperlink");
arr[idx].setText(linkText[idx]);
url = linkUrl[idx];
if (url.startsWith(ctxPath)) {
url = url.substring(ctxPathSize);
}
arr[idx].setUrl(url);
}
handlerCtx.setOutputValue("links", arr);
}
use of javax.faces.context.ExternalContext in project Payara by payara.
the class GuiUtil method initSessionAttributes.
public static void initSessionAttributes() {
Logger logger = GuiUtil.getLogger();
if (logger.isLoggable(Level.INFO)) {
logger.log(Level.INFO, GuiUtil.getCommonMessage("LOG_INIT_SESSION"));
}
ExternalContext externalCtx = FacesContext.getCurrentInstance().getExternalContext();
Map<String, Object> sessionMap = externalCtx.getSessionMap();
if (logger.isLoggable(Level.FINE)) {
logger.log(Level.INFO, "SessionMap from externalCtx: " + sessionMap.toString());
}
Object request = externalCtx.getRequest();
if (request instanceof javax.servlet.ServletRequest) {
ServletRequest srequest = (ServletRequest) request;
sessionMap.put("hostName", srequest.getServerName());
String restServerName = (String) sessionMap.get(AdminConsoleAuthModule.REST_SERVER_NAME);
if (restServerName == null) {
throw new IllegalStateException("REST Server Name not set!");
}
int port = (Integer) sessionMap.get(AdminConsoleAuthModule.REST_SERVER_PORT);
sessionMap.put("requestIsSecured", srequest.isSecure());
sessionMap.put("REST_URL", "http" + (srequest.isSecure() ? "s" : "") + "://" + restServerName + ":" + port + "/management/domain");
sessionMap.put("MONITOR_URL", "http" + (srequest.isSecure() ? "s" : "") + "://" + restServerName + ":" + port + "/monitoring/domain");
} else {
// should never get here.
sessionMap.put("hostName", "");
}
final String domainName = RestUtil.getPropValue((String) (sessionMap.get("REST_URL")), "administrative.domain.name", null);
sessionMap.put("domainName", domainName);
sessionMap.put("localhostNodeName", "localhost-" + domainName);
sessionMap.put("_noNetwork", (System.getProperty("com.sun.enterprise.tools.admingui.NO_NETWORK", "false").equals("true")) ? Boolean.TRUE : Boolean.FALSE);
sessionMap.put("supportCluster", Boolean.FALSE);
Map version = RestUtil.restRequest(sessionMap.get("REST_URL") + "/version", null, "GET", null, false);
sessionMap.put("appServerVersion", ((Map) version.get("data")).get("message"));
Map locations = RestUtil.restRequest(sessionMap.get("REST_URL") + "/locations", null, "GET", null, false);
final String installDir = (String) ((Map) ((Map) locations.get("data")).get("properties")).get("Base-Root");
sessionMap.put("baseRootDir", installDir);
sessionMap.put("topDir", (new File(installDir)).getParent());
Map runtimeInfoMap = RestUtil.restRequest(sessionMap.get("REST_URL") + "/get-runtime-info", null, "GET", null, false);
String debugFlag = (String) ((Map) ((Map) runtimeInfoMap.get("data")).get("properties")).get("debug");
if ("true".equals(debugFlag)) {
String debugPort = (String) ((Map) ((Map) runtimeInfoMap.get("data")).get("properties")).get("debugPort");
sessionMap.put("debugInfo", GuiUtil.getMessage("inst.debugEnabled") + debugPort);
} else {
sessionMap.put("debugInfo", GuiUtil.getMessage("inst.notEnabled"));
}
try {
Map secureAdminAttrs = RestUtil.getAttributesMap(sessionMap.get("REST_URL") + "/secure-admin");
if (Boolean.parseBoolean((String) secureAdminAttrs.get("enabled"))) {
sessionMap.put("secureAdminEnabled", "true");
} else {
sessionMap.put("secureAdminEnabled", "false");
}
} catch (Exception ex) {
sessionMap.put("secureAdminEnabled", "false");
}
Map asadminRecorderEnabled = RestUtil.restRequest(sessionMap.get("REST_URL") + "/asadmin-recorder-enabled", null, "GET", null, false);
sessionMap.put("showEnableAsadminRecorderButton", !(boolean) ((Map) ((Map) asadminRecorderEnabled.get("data")).get("extraProperties")).get("asadminRecorderEnabled"));
sessionMap.put("showDisableAsadminRecorderButton", (boolean) ((Map) ((Map) asadminRecorderEnabled.get("data")).get("extraProperties")).get("asadminRecorderEnabled"));
Map environmentWarningConfiguration = RestUtil.restRequest(sessionMap.get("REST_URL") + "/get-environment-warning-configuration", null, "GET", null, false);
sessionMap.put("environmentWarningBarEnabled", ((Map) ((Map) ((Map) environmentWarningConfiguration.get("data")).get("extraProperties")).get("environmentWarningConfiguration")).get("enabled"));
sessionMap.put("environmentWarningBarMessage", ((Map) ((Map) ((Map) environmentWarningConfiguration.get("data")).get("extraProperties")).get("environmentWarningConfiguration")).get("message"));
sessionMap.put("environmentWarningBarBackgroundColour", ((Map) ((Map) ((Map) environmentWarningConfiguration.get("data")).get("extraProperties")).get("environmentWarningConfiguration")).get("backgroundColour"));
sessionMap.put("environmentWarningBarTextColour", ((Map) ((Map) ((Map) environmentWarningConfiguration.get("data")).get("extraProperties")).get("environmentWarningConfiguration")).get("textColour"));
sessionMap.put("reqMsg", GuiUtil.getMessage("msg.JS.enterValue"));
sessionMap.put("reqMsgSelect", GuiUtil.getMessage("msg.JS.selectValue"));
sessionMap.put("reqInt", GuiUtil.getMessage("msg.JS.enterIntegerValue"));
sessionMap.put("reqNum", GuiUtil.getMessage("msg.JS.enterNumericValue"));
sessionMap.put("reqPort", GuiUtil.getMessage("msg.JS.enterPortValue"));
sessionMap.put("_SESSION_INITIALIZED", "TRUE");
sessionMap.put("restartRequired", Boolean.FALSE);
/* refer to issue# 5698 and issue# 3691
* There is a chance that this getAdminSessionTimoutInMinutes() throws an exception in Turkish locale.
* In such a case, we catch and log the exception and assume it is set to 0.
* Otherwise GUI's main page can't come up.
*/
try {
Map result = RestUtil.restRequest(GuiUtil.getSessionValue("REST_URL") + "/configs/config/server-config/admin-service/das-config", null, "GET", null, false);
String timeOut = (String) ((Map) ((Map) ((Map) result.get("data")).get("extraProperties")).get("entity")).get("adminSessionTimeoutInMinutes");
if ((timeOut != null) && (!timeOut.equals(""))) {
int time = Integer.parseInt(timeOut);
if (time == 0) {
((HttpServletRequest) request).getSession().setMaxInactiveInterval(-1);
} else {
((HttpServletRequest) request).getSession().setMaxInactiveInterval(time * 60);
}
}
} catch (Exception nfe) {
((HttpServletRequest) request).getSession().setMaxInactiveInterval(-1);
log("log.error.initSession", nfe);
}
try {
setTimeStamp();
} catch (Exception ex) {
log("log.error.initSession", ex);
}
}
Aggregations