List of usage examples for javax.servlet.http HttpSession getServletContext
public ServletContext getServletContext();
From source file:net.sf.sail.webapp.presentation.web.filters.PasAuthenticationProcessingFilter.java
/** * @see org.acegisecurity.ui.AbstractProcessingFilter#successfulAuthentication(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse, * org.acegisecurity.Authentication) *///from w ww.j a v a2s .com @Override protected void successfulAuthentication(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, Authentication authResult) throws IOException, ServletException { UserDetails userDetails = (UserDetails) authResult.getPrincipal(); if (LOGGER.isDebugEnabled()) { logDebug(userDetails); } HttpSession session = request.getSession(); ApplicationContext springContext = WebApplicationContextUtils .getWebApplicationContext(session.getServletContext()); UserService userService = (UserService) springContext.getBean("userService"); User user = userService.retrieveUser(userDetails); session.setAttribute(User.CURRENT_USER_SESSION_KEY, user); // add new session in a allLoggedInUsers servletcontext HashMap variable String sessionId = session.getId(); HashMap<String, User> allLoggedInUsers = (HashMap<String, User>) session.getServletContext() .getAttribute("allLoggedInUsers"); if (allLoggedInUsers == null) { allLoggedInUsers = new HashMap<String, User>(); session.getServletContext().setAttribute(PasSessionListener.ALL_LOGGED_IN_USERS, allLoggedInUsers); } allLoggedInUsers.put(sessionId, user); super.successfulAuthentication(request, response, authResult); }
From source file:org.sakaiproject.tool.gradebook.ui.standalone.AuthnFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpSession session = ((HttpServletRequest) request).getSession(); Authn authnService = (Authn) WebApplicationContextUtils .getWebApplicationContext(session.getServletContext()).getBean(authnServiceBean); authnService.setAuthnContext(request); String userUid = authnService.getUserUid(); if (logger.isInfoEnabled()) logger.info("userUid=" + userUid); if (userUid == null) { if (authnRedirect != null) { if (authnRedirect.equals(((HttpServletRequest) request).getRequestURI())) { // Don't redirect to the same spot. chain.doFilter(request, response); } else { // ((HttpServletRequest)request).getRequestDispatcher(authnRedirect).forward(request, response); ((HttpServletResponse) response).sendRedirect(authnRedirect); }/*from www.j av a 2 s . c o m*/ } else { ((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED); } } else { chain.doFilter(request, response); } }
From source file:org.wso2.carbon.ui.DefaultCarbonAuthenticator.java
/** * /*from w ww . j a v a 2s. co m*/ * @param request * @return * @throws AxisFault */ private AuthenticationAdminClient getAuthenticationAdminCient(HttpServletRequest request) throws AxisFault { HttpSession session = request.getSession(); ServletContext servletContext = session.getServletContext(); String backendServerURL = request.getParameter("backendURL"); if (backendServerURL == null) { backendServerURL = CarbonUIUtil.getServerURL(servletContext, request.getSession()); } session.setAttribute(CarbonConstants.SERVER_URL, backendServerURL); ConfigurationContext configContext = (ConfigurationContext) servletContext .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_AUTH_TOKEN); return new AuthenticationAdminClient(configContext, backendServerURL, cookie, session, true); }
From source file:org.sakaiproject.tool.section.filter.AuthnFilter.java
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpSession session = ((HttpServletRequest) request).getSession(true); Authn authnService = (Authn) WebApplicationContextUtils .getWebApplicationContext(session.getServletContext()).getBean(authnBean); String userUid = null;//w w w . j a v a2s . c o m try { userUid = authnService.getUserUid(request); } catch (Exception e) { if (log.isDebugEnabled()) log.debug("Could not get user uuid from authn service."); } if (log.isDebugEnabled()) log.debug("userUid=" + userUid); if (userUid == null) { if (authnRedirect != null) { if (authnRedirect.equals(((HttpServletRequest) request).getRequestURI())) { // Don't redirect to the same spot. chain.doFilter(request, response); } else { ((HttpServletResponse) response).sendRedirect(authnRedirect); } } else { ((HttpServletResponse) response).sendError(HttpServletResponse.SC_UNAUTHORIZED); } } else { chain.doFilter(request, response); } }
From source file:org.intermine.web.struts.BagBuildController.java
private String getDefaultValue(HttpServletRequest request, InterMineAPI im) { HttpSession session = request.getSession(); ServletContext servletContext = session.getServletContext(); final Properties webProperties = SessionMethods.getWebProperties(servletContext); final FriendlyMineManager linkManager = FriendlyMineManager.getInstance(im, webProperties); Mine mine = linkManager.getLocalMine(); if (mine != null) { return mine.getDefaultValue(); }/*from ww w. j a v a 2 s. co m*/ return null; }
From source file:com.crimelab.service.DrugTestServiceImpl.java
@Override public Workbook create(DrugTest drugTest, HttpSession session) { Workbook wb = null;/*from w w w. ja va2 s . com*/ try { InputStream inp = session.getServletContext().getResourceAsStream("/WEB-INF/templates/DrugTest.xls"); wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); //iterate over keywords Cell fadtNo = findCell(sheet, "$fadtNo"); Cell sbrNo = findCell(sheet, "$sbrNo"); Cell timeDate = findCell(sheet, "$timeDate"); Cell name = findCell(sheet, "$name"); Cell address = findCell(sheet, "$address"); Cell age = findCell(sheet, "$age"); Cell sex = findCell(sheet, "$sex"); Cell purposeFL = findCell(sheet, "$purposeFL"); Cell purposePTCFOR = findCell(sheet, "$purposePTCFOR"); Cell specimenSubmitted = findCell(sheet, "$specimenSubmitted"); Cell purposeOfExamination = findCell(sheet, "$purposeOfExamination"); Cell methamphetamine = findCell(sheet, "$methamphetamine"); Cell thc = findCell(sheet, "$thc"); Cell remarks = findCell(sheet, "$remarks"); Cell examinerName = findCell(sheet, "$examinerName"); Cell examinerRank = findCell(sheet, "$examinerRank"); Cell examinerPosition = findCell(sheet, "$examinerPosition"); Cell appName = findCell(sheet, "$appName"); Cell appRank = findCell(sheet, "$appRank"); Cell appPosition = findCell(sheet, "$appPosition"); //Modify the cellContents here // Write the output to a file //get from param fadtNo.setCellValue(drugTest.getFadtNo()); sbrNo.setCellValue(drugTest.getSbrNo()); timeDate.setCellValue(drugTest.getTimeDate()); name.setCellValue(drugTest.getName()); address.setCellValue(drugTest.getAddress()); age.setCellValue(drugTest.getAge()); sex.setCellValue(drugTest.getSex()); switch (drugTest.getPurpose().trim()) { case "Firearm License": purposeFL.setCellValue(" "); purposePTCFOR.setCellValue(""); break; case "Permit to Carry Firearms Outside Residence (PTCFOR)": purposeFL.setCellValue(""); purposePTCFOR.setCellValue(" "); break; default: purposeFL.setCellValue(" "); purposePTCFOR.setCellValue(" "); break; } specimenSubmitted.setCellValue(drugTest.getSpecimenSubmitted()); purposeOfExamination.setCellValue(drugTest.getPurposeOfExamination()); methamphetamine.setCellValue(drugTest.getMethamphetamine()); thc.setCellValue(drugTest.getThc()); remarks.setCellValue(drugTest.getRemarks()); examinerName.setCellValue(drugTest.getExaminerName()); examinerRank.setCellValue(drugTest.getExaminerRank()); examinerPosition.setCellValue(drugTest.getExaminerPosition()); appName.setCellValue(drugTest.getAppName()); appRank.setCellValue(drugTest.getAppRank()); appPosition.setCellValue(drugTest.getAppPosition()); drugTestDAO.drugTestInfo(drugTest); } catch (Exception e) { e.printStackTrace(); } return wb; }
From source file:org.wso2.carbon.identity.authenticator.krb5.ui.Krb5UIAuthenticator.java
public void unauthenticate(Object object) throws Exception { HttpSession session = ((HttpServletRequest) object).getSession(); ServletContext servletContext = session.getServletContext(); ConfigurationContext configContext = (ConfigurationContext) servletContext .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT); String backendServerURL = CarbonUIUtil.getServerURL(servletContext, session); try {/* ww w . j a va 2 s.co m*/ String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_AUTH_TOKEN); Krb5AuthenticatorClient proxy = new Krb5AuthenticatorClient(configContext, backendServerURL, cookie, session); proxy.logout(session); } catch (Exception ignored) { String msg = "Configuration context is null."; log.error(msg); throw new Exception(msg); } }
From source file:org.flymine.web.ChartRenderer.java
/** * First, check for a cached image, otherwise defer to appropriate method. * * @param mapping The ActionMapping used to select this instance * @param form The optional ActionForm bean for this request (if any) * @param request The HTTP request we are processing * @param response The HTTP response we are creating * @return an ActionForward object defining where control goes next * @exception Exception if the application business logic throws * an exception//from w ww . j a v a 2 s .c o m */ public ActionForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response) throws Exception { HttpSession session = request.getSession(); ServletContext servletContext = session.getServletContext(); Map graphImageCache = (Map) servletContext.getAttribute(Constants.GRAPH_CACHE); String filename = (String) graphImageCache.get(request.getQueryString()); if (filename != null) { //ServletUtilities.sendTempFile(filename, response); return null; } Method method = getClass().getMethod(request.getParameter("method"), SIG); if (!"execute".equals(method.getName())) { // avoid infinite loop return (ActionForward) method.invoke(this, new Object[] { mapping, form, request, response }); } LOG.error("bad method parameter \"" + request.getParameter("method") + "\""); return null; }
From source file:com.mobileman.projecth.web.controller.admin.AdminDoctorsController.java
/** * @param session//w w w . jav a2 s .c o m * @param request * @param page * @return String */ @RequestMapping(method = RequestMethod.GET, value = "/admin/{page}") public String getPage(HttpSession session, HttpServletRequest request, @PathVariable String page) { return processPage(session.getServletContext(), page); }
From source file:com.crimelab.service.CriminalServiceImpl.java
@Override public Workbook createTenprintsCards(HttpSession session, String month) { Workbook wb = null;/*from ww w .j a v a 2 s. c om*/ try { InputStream inp = session.getServletContext() .getResourceAsStream("/WEB-INF/templates/TenprintsCards.xls"); wb = WorkbookFactory.create(inp); Sheet sheet = wb.getSheetAt(0); CellStyle cs1 = wb.createCellStyle(); CellStyle cs2 = wb.createCellStyle(); CellStyle bl = wb.createCellStyle(); CellStyle br = wb.createCellStyle(); CellStyle bt = wb.createCellStyle(); CellStyle bb = wb.createCellStyle(); cs1.setWrapText(true); cs2.setAlignment(ALIGN_CENTER); bt.setBorderTop(BORDER_THIN); bb.setBorderBottom(BORDER_THIN); bl.setBorderLeft(BORDER_THIN); br.setBorderRight(BORDER_THIN); Row intro1 = sheet.createRow(9); Cell in1 = intro1.createCell(0); in1.setCellValue("Submitted Tenprints Cards from " + month.split("-")[0]); in1.setCellStyle(cs1); in1.setCellStyle(cs2); int ctr = 11; //initial Row row = sheet.createRow(ctr); month = month.split("-")[1]; //JOptionPane.showMessageDialog(null, criminalDAO.getAllCriminal(month)); for (Criminal criminal : criminalDAO.getAllCriminal(month)) { //JOptionPane.showMessageDialog(null, criminal.getReportNo()); Cell cell2 = row.createCell(2);//.setCellValue(criminal.getRequestingParty()); cell2.setCellValue(criminal.getLastName()); cell2.setCellStyle(bt); cell2.setCellStyle(bb); cell2.setCellStyle(bl); cell2.setCellStyle(br); Cell cell3 = row.createCell(3);//.setCellValue(criminal.getDescriptionOfEvidence()); cell3.setCellValue(criminal.getFirstName()); cell2.setCellStyle(bt); cell2.setCellStyle(bb); cell3.setCellStyle(bl); cell3.setCellStyle(br); Cell cell4 = row.createCell(4);//.setCellValue(criminal.getSpecimenWeight()); cell4.setCellValue(criminal.getMiddleName()); cell4.setCellStyle(bt); cell4.setCellStyle(bb); cell4.setCellStyle(bl); cell4.setCellStyle(br); Cell cell5 = row.createCell(5);//.setCellValue(criminal.getCustody()); cell5.setCellValue(criminal.getTimeDateArrest()); cell5.setCellStyle(bt); cell5.setCellStyle(bb); cell5.setCellStyle(bl); cell5.setCellStyle(br); Cell cell6 = row.createCell(6);//.setCellValue(criminal.getSuspects()); cell6.setCellValue(criminal.getOffenseCharge()); cell6.setCellStyle(bt); cell6.setCellStyle(bb); cell6.setCellStyle(bl); cell6.setCellStyle(br); row = sheet.createRow(ctr += 1); return wb; } } catch (Exception e) { e.printStackTrace(); } return wb; }