List of usage examples for javax.servlet.http HttpSession getServletContext
public ServletContext getServletContext();
From source file:be.fedict.eid.idp.sp.protocol.openid.AuthenticationRequestServlet.java
/** * Used by the {@link AuthenticationResponseServlet} for processing the * returned OpenID response//from w ww . j a v a2 s . c o m * * @param request * HTTP Servlet Request, used to get the OpenID * {@link ConsumerManager} from the {@link ServletContext} * @return the OpenID {@link ConsumerManager} */ public static ConsumerManager getConsumerManager(HttpServletRequest request) { HttpSession httpSession = request.getSession(); ServletContext servletContext = httpSession.getServletContext(); ConsumerManager consumerManager = (ConsumerManager) servletContext.getAttribute(CONSUMER_MANAGER_ATTRIBUTE); if (null == consumerManager) { throw new IllegalStateException("no ConsumerManager found in ServletContext"); } return consumerManager; }
From source file:org.apache.qpid.server.management.plugin.HttpManagementUtil.java
public static void saveAuthorisedSubject(HttpSession session, Subject subject) { session.setAttribute(ATTR_SUBJECT, subject); // Cause the user logon to be logged. session.setAttribute(ATTR_LOGIN_LOGOUT_REPORTER, new LoginLogoutReporter(subject, getBroker(session.getServletContext()))); }
From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.VTwo.EditConfigurationUtils.java
/** * May return null if data property statement cannot be found. *///from w w w . ja v a 2 s . c om public static DataPropertyStatement getDataPropertyStatement(VitroRequest vreq, HttpSession session, Integer dataHash, String predicateUri) { DataPropertyStatement dps = null; if (dataHash != 0) { OntModel model = ModelAccess.on(session.getServletContext()).getOntModel(); dps = RdfLiteralHash.getPropertyStmtByHash(EditConfigurationUtils.getSubjectUri(vreq), predicateUri, dataHash, model); } return dps; }
From source file:org.apache.ofbiz.content.data.DataEvents.java
/** Streams ImageDataResource data to the output. */ // TODO: remove this method in favor of serveObjectData public static String serveImage(HttpServletRequest request, HttpServletResponse response) { HttpSession session = request.getSession(); ServletContext application = session.getServletContext(); Delegator delegator = (Delegator) request.getAttribute("delegator"); Map<String, Object> parameters = UtilHttp.getParameterMap(request); Debug.logInfo("Img UserAgent - " + request.getHeader("User-Agent"), module); String dataResourceId = (String) parameters.get("imgId"); if (UtilValidate.isEmpty(dataResourceId)) { String errorMsg = "Error getting image record from db: " + " dataResourceId is empty"; Debug.logError(errorMsg, module); request.setAttribute("_ERROR_MESSAGE_", errorMsg); return "error"; }/*from ww w .j a v a 2 s . c om*/ try { GenericValue dataResource = EntityQuery.use(delegator).from("DataResource") .where("dataResourceId", dataResourceId).cache().queryOne(); if (!"Y".equals(dataResource.getString("isPublic"))) { // now require login... GenericValue userLogin = (GenericValue) session.getAttribute("userLogin"); if (userLogin == null) { String errorMsg = "You must be logged in to download the Data Resource with ID [" + dataResourceId + "]"; Debug.logError(errorMsg, module); request.setAttribute("_ERROR_MESSAGE_", errorMsg); return "error"; } // make sure the logged in user can download this content; otherwise is a pretty big security hole for DataResource records... // TODO: should we restrict the roleTypeId? long contentAndRoleCount = EntityQuery.use(delegator).from("ContentAndRole") .where("partyId", userLogin.get("partyId"), "dataResourceId", dataResourceId).queryCount(); if (contentAndRoleCount == 0) { String errorMsg = "You do not have permission to download the Data Resource with ID [" + dataResourceId + "], ie you are not associated with it."; Debug.logError(errorMsg, module); request.setAttribute("_ERROR_MESSAGE_", errorMsg); return "error"; } } String mimeType = DataResourceWorker.getMimeType(dataResource); // hack for IE and mime types String userAgent = request.getHeader("User-Agent"); if (userAgent.indexOf("MSIE") > -1) { Debug.logInfo("Found MSIE changing mime type from - " + mimeType, module); mimeType = "application/octet-stream"; } if (mimeType != null) { response.setContentType(mimeType); } OutputStream os = response.getOutputStream(); Map<String, Object> resourceData = DataResourceWorker.getDataResourceStream(dataResource, "", application.getInitParameter("webSiteId"), UtilHttp.getLocale(request), application.getRealPath("/"), false); os.write(IOUtils.toByteArray((ByteArrayInputStream) resourceData.get("stream"))); os.flush(); } catch (GenericEntityException e) { String errMsg = "Error downloading digital product content: " + e.toString(); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } catch (GeneralException e) { String errMsg = "Error downloading digital product content: " + e.toString(); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } catch (IOException e) { String errMsg = "Error downloading digital product content: " + e.toString(); Debug.logError(e, errMsg, module); request.setAttribute("_ERROR_MESSAGE_", errMsg); return "error"; } return "success"; }
From source file:edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.java
public static ModelAccess on(HttpSession session) { Object o = session.getAttribute(ATTRIBUTE_NAME); if (o instanceof ModelAccess) { return (ModelAccess) o; } else {/*from w ww .ja v a 2 s .c o m*/ ModelAccess parent = on(session.getServletContext()); ModelAccess ma = new ModelAccess(Scope.SESSION, parent); session.setAttribute(ATTRIBUTE_NAME, ma); return ma; } }
From source file:com.onehippo.gogreen.login.HstConcurrentLoginFilter.java
static void unregisterUserSession(HttpSession session) { String username = (String) session.getAttribute(USERNAME_ATTR); log.debug("HstConcurrentLoginFilter will unregister session for {}", username); if (username == null) { return;/*w ww . jav a2 s.c o m*/ } ServletContext servletContext = session.getServletContext(); @SuppressWarnings("unchecked") Map<String, HttpSessionWrapper> map = (Map<String, HttpSessionWrapper>) servletContext .getAttribute(USERNAME_SESSIONID_MAP_ATTR); if (map != null) { HttpSessionWrapper oldHttpSessionWrapper = null; synchronized (map) { oldHttpSessionWrapper = map.get(username); if (oldHttpSessionWrapper != null) { if (oldHttpSessionWrapper.equalsTo(session)) { map.remove(username); log.debug("HstConcurrentLoginFilter kicked out session ({}) for {}.", oldHttpSessionWrapper.getId(), username); } else { log.debug( "HstConcurrentLoginFilter didn't kick out session ({}) for {} because it's logged on by other http session.", oldHttpSessionWrapper.getId(), username); } } } } else { log.error("HstConcurrentLoginFilter is in invalid state. The session ids map is not found."); } session.removeAttribute(USERNAME_ATTR); log.debug("HstConcurrentLoginFilter removed user name session attribute: {}", username); }
From source file:edu.cornell.mannlib.vitro.webapp.search.indexing.IndexBuilder.java
public static void checkIndexOnRootLogin(HttpServletRequest req) { HttpSession session = req.getSession(); ServletContext context = session.getServletContext(); IndexBuilder indexBuilder = (IndexBuilder) context.getAttribute(IndexBuilder.class.getName()); log.debug("Checking if the index is empty"); if (indexBuilder.indexer.isIndexEmpty()) { log.info("Search index is empty. Running a full index rebuild."); indexBuilder.doIndexRebuild();/* w w w.j a v a 2 s . co m*/ } }
From source file:net.ontopia.topicmaps.classify.WebChew.java
/** * INTERNAL: Returns the plug-in class instance used by the ontopoly * plugin. Used by classify/plugin.jsp./*w w w .java 2 s . c o m*/ */ public static ClassifyPluginIF getPlugin(HttpServletRequest request) { // create plugin by dynamically intantiating plugin class HttpSession session = request.getSession(true); ServletContext scontext = session.getServletContext(); String pclass = scontext.getInitParameter("classify_plugin"); if (pclass == null) pclass = "net.ontopia.topicmaps.classify.DefaultPlugin"; ClassifyPluginIF cp = (ClassifyPluginIF) ObjectUtils.newInstance(pclass); if (cp instanceof HttpServletRequestAwareIF) ((HttpServletRequestAwareIF) cp).setRequest(request); return cp; }
From source file:org.wso2.carbon.identity.provider.openid.util.OpenIDUtil.java
/** * Returns an instance of <code>OpenIDAdminClient</code>. * Only one instance of this will be created for a session. * This method is used to reuse the same client within a session. * * @param session// w ww . j a va 2s.c om * @return {@link OpenIDAdminClient} * @throws AxisFault */ public static OpenIDAdminClient getOpenIDAdminClient(HttpSession session) throws AxisFault { OpenIDAdminClient client = (OpenIDAdminClient) session .getAttribute(OpenIDConstants.SessionAttribute.OPENID_ADMIN_CLIENT); if (client == null) { // a session timeout or the fist request String serverURL = CarbonUIUtil.getServerURL(session.getServletContext(), session); ConfigurationContext configContext = (ConfigurationContext) session.getServletContext() .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_COOKIE); client = new OpenIDAdminClient(configContext, serverURL, cookie); session.setAttribute(OpenIDConstants.SessionAttribute.OPENID_ADMIN_CLIENT, client); } return client; }
From source file:mercury.BaseHandler.java
public static Properties getI18nProperties(final HttpSession session, String module) { String lang = (String) (session.getAttribute("I18N")); if (lang == null || lang.trim().equals("")) { lang = "pt_BR"; session.setAttribute("I18N", lang); }//from w w w. j av a 2 s. co m String attrName = "I18N_" + module + "." + lang; ServletContext sc = session.getServletContext(); return (Properties) (sc.getAttribute(attrName)); }