List of usage examples for javax.servlet ServletContext getAttribute
public Object getAttribute(String name);
null
if there is no attribute by that name. From source file:org.apache.struts.util.RequestUtils.java
/** * <p>Retrieves the servlet mapping pattern for the specified {@link ActionServlet}.</p> * * @return the servlet mapping// w ww. j a v a 2 s . c o m * @see Globals#SERVLET_KEY * @since Struts 1.3.6 */ public static String getServletMapping(ActionServlet servlet) { ServletContext servletContext = servlet.getServletConfig().getServletContext(); return (String) servletContext.getAttribute(Globals.SERVLET_KEY); }
From source file:org.intermine.web.logic.session.SessionMethods.java
/** * Get the set of accepted Open-ID providers. * @param session The session to use for lookups * @return The set of open-id providers. *///w ww . ja v a2s .c o m public static Set<String> getOpenIdProviders(HttpSession session) { ServletContext ctx = session.getServletContext(); return (Set<String>) ctx.getAttribute(Constants.OPENID_PROVIDERS); }
From source file:org.red5.logging.ContextLoggingListener.java
public void contextDestroyed(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); LoggerContext context = (LoggerContext) servletContext .getAttribute(Red5LoggerFactory.LOGGER_CONTEXT_ATTRIBUTE); if (context != null) { Logger logger = context.getLogger(Logger.ROOT_LOGGER_NAME); logger.debug("Shutting down context {}", context.getName()); context.reset();//from www . ja va 2 s .com context.stop(); } else { System.err.printf("No logger context found for %s%n", event.getServletContext().getContextPath()); } }
From source file:org.apache.hadoop.hdfs.server.namenode.RenewDelegationTokenServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final UserGroupInformation ugi; final ServletContext context = getServletContext(); final Configuration conf = (Configuration) context.getAttribute(JspHelper.CURRENT_CONF); try {/* w ww. j a v a 2s . c o m*/ ugi = getUGI(req, conf); } catch (IOException ioe) { LOG.info("Request for token received with no authentication from " + req.getRemoteAddr(), ioe); resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Unable to identify or authenticate user"); return; } final NameNode nn = (NameNode) context.getAttribute("name.node"); String tokenString = req.getParameter(TOKEN); if (tokenString == null) { resp.sendError(HttpServletResponse.SC_MULTIPLE_CHOICES, "Token to renew not specified"); } final Token<DelegationTokenIdentifier> token = new Token<DelegationTokenIdentifier>(); token.decodeFromUrlString(tokenString); try { long result = ugi.doAs(new PrivilegedExceptionAction<Long>() { public Long run() throws Exception { return nn.renewDelegationToken(token); } }); PrintStream os = new PrintStream(resp.getOutputStream()); os.println(result); os.close(); } catch (Exception e) { // transfer exception over the http String exceptionClass = e.getClass().getCanonicalName(); String exceptionMsg = e.getLocalizedMessage(); String strException = exceptionClass + ";" + exceptionMsg; LOG.info("Exception while renewing token. Re-throwing. s=" + strException, e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, strException); } }
From source file:org.onebusaway.quickstart.webapp.BootstrapWebApplicationContext.java
@Override protected void loadBeanDefinitions(DefaultListableBeanFactory beanFactory) throws BeansException, IOException { super.loadBeanDefinitions(beanFactory); System.out.println("=== BootstrapWebApplicationContext! ============================"); ServletContext servletContext = getServletContext(); final CommandLine cli = (CommandLine) servletContext .getAttribute(WebappCommon.COMMAND_LINE_CONTEXT_ATTRIBUTE); if (cli == null) throw new IllegalStateException("expected a CommandLine object stored in the webapp context"); final Map<String, BeanDefinition> beanDefinitions = configureBeanDefinitions(cli); if (beanDefinitions.isEmpty()) return;//from w w w . j av a 2s . co m for (Map.Entry<String, BeanDefinition> entry : beanDefinitions.entrySet()) { String beanName = entry.getKey(); BeanDefinition beanDefinition = entry.getValue(); beanFactory.registerBeanDefinition(beanName, beanDefinition); } }
From source file:cn.edu.zjnu.acm.judge.config.StartUpConfiguration.java
@Autowired public void setStartUpDate(ServletContext servlet, ApplicationContext application) { servlet.setAttribute("startUpDate", application.getStartupDate()); log.debug("{}: {}", ServletContext.TEMPDIR, servlet.getAttribute(ServletContext.TEMPDIR)); }
From source file:com.betfair.tornjak.monitor.overlay.AuthUtilsTest.java
@Test public void testNotAuthenticated() throws Exception { HttpServletRequest request = mock(HttpServletRequest.class); HttpServletResponse response = mock(HttpServletResponse.class); ServletContext context = mock(ServletContext.class); when(context.getAttribute("com.betfair.tornjak.monitor.overlay.RolePerms")) .thenReturn(new AuthBuilder().role("jmxadmin").allow(".*:.*:.*").getRolePerms()); when(request.getUserPrincipal()).thenReturn(null); Auth auth = AuthUtils.checkAuthorised(request, response, context); assertThat("User should not be authorised", auth, nullValue()); verify(response, times(1)).sendError(HttpServletResponse.SC_UNAUTHORIZED); verifyNoMoreInteractions(response);/*from w w w. j ava 2 s.c om*/ }
From source file:org.firstopen.custom.event.agent.Initializer.java
public void contextDestroyed(ServletContextEvent event) { ServletContext servletContext = event.getServletContext(); try {/*from w w w . j a v a 2 s. c o m*/ EventMonitorBean eventMonitorBean = (EventMonitorBean) servletContext .getAttribute(Constants.EVENT_MONITOR_KEY); if (eventMonitorBean != null) eventMonitorBean.shutdown(); event.getServletContext().log("Context Destroyed, eventMonitorBean shutdown complete."); } catch (InfrastructureException e) { log.error("unable to shutdown EventMonitorBean", e); } }
From source file:org.apache.hadoop.hdfs.server.namenode.GetDelegationTokenServlet.java
@Override protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException { final UserGroupInformation ugi; final ServletContext context = getServletContext(); final Configuration conf = (Configuration) context.getAttribute(JspHelper.CURRENT_CONF); try {// ww w .java 2 s.co m ugi = getUGI(req, conf); } catch (IOException ioe) { LOG.info("Request for token received with no authentication from " + req.getRemoteAddr(), ioe); resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Unable to identify or authenticate user"); return; } LOG.info("Sending token: {" + ugi.getUserName() + "," + req.getRemoteAddr() + "}"); final NameNode nn = (NameNode) context.getAttribute("name.node"); String renewer = req.getParameter(RENEWER); final String renewerFinal = (renewer == null) ? req.getUserPrincipal().getName() : renewer; DataOutputStream dos = null; try { dos = new DataOutputStream(resp.getOutputStream()); final DataOutputStream dosFinal = dos; // for doAs block ugi.doAs(new PrivilegedExceptionAction<Void>() { @Override public Void run() throws IOException { final Credentials ts = DelegationTokenSecretManager.createCredentials(nn, ugi, renewerFinal); ts.write(dosFinal); dosFinal.close(); return null; } }); } catch (Exception e) { LOG.info("Exception while sending token. Re-throwing. ", e); resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { if (dos != null) dos.close(); } }
From source file:com.manydesigns.portofino.stripes.AuthenticationRequiredResolution.java
public void execute(HttpServletRequest request, HttpServletResponse response) throws Exception { if (request.getParameter("__portofino_quiet_auth_failure") != null) { return;//from w w w . ja va2s . c om } ServletContext servletContext = request.getServletContext(); Configuration configuration = (Configuration) servletContext .getAttribute(BaseModule.PORTOFINO_CONFIGURATION); String loginPage = configuration.getString(PortofinoProperties.LOGIN_PAGE); if (response.getContentType() == null || response.getContentType().contains("text/html")) { ElementsActionBeanContext context = new ElementsActionBeanContext(); context.setRequest(request); String originalPath = context.getActionPath(); UrlBuilder urlBuilder = new UrlBuilder(Locale.getDefault(), originalPath, false); Map<?, ?> parameters = request.getParameterMap(); urlBuilder.addParameters(parameters); String returnUrl = urlBuilder.toString(); logger.info("Anonymous user not allowed to see {}. Redirecting to login.", originalPath); RedirectResolution redirectResolution = new RedirectResolution(loginPage, true); redirectResolution.addParameter("returnUrl", returnUrl); redirectResolution.execute(request, response); } else { logger.debug("AJAX call while user disconnected"); UrlBuilder loginUrlBuilder = new UrlBuilder(request.getLocale(), loginPage, false); response.setHeader(LOGIN_PAGE_HEADER, loginUrlBuilder.toString()); new ErrorResolution(STATUS, errorMessage).execute(request, response); } }