Example usage for javax.servlet.http HttpSession getServletContext

List of usage examples for javax.servlet.http HttpSession getServletContext

Introduction

In this page you can find the example usage for javax.servlet.http HttpSession getServletContext.

Prototype

public ServletContext getServletContext();

Source Link

Document

Returns the ServletContext to which this session belongs.

Usage

From source file:org.intermine.webservice.server.lists.ListUploadService.java

/**
 * Get the String Matcher for parsing the list of identifiers.
 * @return The matcher to use.//  ww  w. j a v  a 2 s  . c o  m
 */
protected StrMatcher getMatcher() {
    final HttpSession session = request.getSession();
    final Properties webProperties = (Properties) session.getServletContext()
            .getAttribute(Constants.WEB_PROPERTIES);

    final String bagUploadDelims = (String) webProperties.get("list.upload.delimiters") + " ";
    final StrMatcher matcher = StrMatcher.charSetMatcher(bagUploadDelims);
    return matcher;
}

From source file:org.wso2.carbon.apimgt.authenticator.oidc.ui.authenticator.OIDCUIAuthenticator.java

@Override
public void unauthenticate(Object o) throws Exception {

    HttpServletRequest request = (HttpServletRequest) o;
    HttpSession session = request.getSession();
    String username = (String) session.getAttribute(CarbonConstants.LOGGED_USER);
    ServletContext servletContext = session.getServletContext();
    ConfigurationContext configContext = (ConfigurationContext) servletContext
            .getAttribute(CarbonConstants.CONFIGURATION_CONTEXT);

    String backendServerURL = CarbonUIUtil.getServerURL(servletContext, session);
    try {/* ww w.j a v a  2s  .c  o  m*/
        String cookie = (String) session.getAttribute(ServerConstants.ADMIN_SERVICE_AUTH_TOKEN);

        OIDCAuthenticationClient authClient = new OIDCAuthenticationClient(configContext, backendServerURL,
                cookie, session);

        authClient.logout(session);
        log.info(username + "@" + PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()
                + " successfully logged out");

    } catch (Exception ignored) {
        String msg = "OIDC logout failed";
        log.error(msg, ignored);
        throw new Exception(msg, ignored);
    }

    String logoutUrl = Util.getIdentityProviderURI() + "logout";

    request.setAttribute(OIDCConstants.HTTP_ATTR_IS_LOGOUT_REQ, true);
    request.setAttribute(OIDCConstants.EXTERNAL_LOGOUT_PAGE, logoutUrl);
}

From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.BasicAuthenticator.java

/**
 * Anyone listening to the model might need to know that another user is
 * logged in.//from  w w w . ja  v  a 2  s  .co m
 */
private void notifyOtherUsers(String userUri, HttpSession session) {
    Authenticate.sendLoginNotifyEvent(new LoginEvent(userUri), session.getServletContext(), session);
}

From source file:com.orchestra.portale.controller.NewDeepeningPageController.java

@RequestMapping(value = "/savedpage", method = RequestMethod.POST)
public ModelAndView savedpage(HttpServletRequest request, @RequestParam Map<String, String> params,
        @RequestParam("cover") MultipartFile cover, @RequestParam("file") MultipartFile[] files)
        throws InterruptedException {
    ModelAndView model = new ModelAndView("okpageadmin");

    DeepeningPage dp = new DeepeningPage();
    dp.setName(params.get("name"));
    System.out.println(params.get("name"));

    int i = 1;//from  ww w .j a  va 2s  .  co  m
    ArrayList<String> categories = new ArrayList<String>();
    while (params.containsKey("category" + i)) {

        categories.add(params.get("category" + i));

        i = i + 1;
    }
    dp.setCategories(categories);

    ArrayList<AbstractPoiComponent> listComponent = new ArrayList<AbstractPoiComponent>();

    //componente cover
    if (!cover.isEmpty()) {
        CoverImgComponent coverimg = new CoverImgComponent();
        coverimg.setLink("cover.jpg");
        listComponent.add(coverimg);
    }
    //componente galleria immagini
    ArrayList<ImgGallery> links = new ArrayList<ImgGallery>();
    if (files.length > 0) {
        ImgGalleryComponent img_gallery = new ImgGalleryComponent();

        i = 0;
        while (i < files.length) {
            ImgGallery img = new ImgGallery();

            Thread.sleep(100);
            Date date = new Date();
            SimpleDateFormat sdf = new SimpleDateFormat("MMddyyyyhmmssSSa");
            String currentTimestamp = sdf.format(date);
            img.setLink("img_" + currentTimestamp + ".jpg");
            if (params.containsKey("credit" + (i + 1))) {
                img.setCredit(params.get("credit" + (i + 1)));
            }

            i = i + 1;
            links.add(img);
        }
        img_gallery.setLinks(links);
        listComponent.add(img_gallery);
    }
    //DESCRIPTION COMPONENT
    i = 1;
    if (params.containsKey("par" + i)) {
        ArrayList<Section> list = new ArrayList<Section>();

        while (params.containsKey("par" + i)) {
            Section section = new Section();
            if (params.containsKey("titolo" + i)) {
                section.setTitle(params.get("titolo" + i));
            }
            section.setDescription(params.get("par" + i));
            list.add(section);
            i = i + 1;

        }
        DescriptionComponent description_component = new DescriptionComponent();
        description_component.setSectionsList(list);
        listComponent.add(description_component);
    }
    dp.setComponents(listComponent);

    pm.saveDeepeningPage(dp);

    DeepeningPage poi2 = pm.findDeepeningPageByName(dp.getName());

    for (int z = 0; z < files.length; z++) {
        MultipartFile file = files[z];

        try {
            byte[] bytes = file.getBytes();

            // Creating the directory to store file
            HttpSession session = request.getSession();
            ServletContext sc = session.getServletContext();

            File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "dpage" + File.separator + "img"
                    + File.separator + poi2.getId());
            if (!dir.exists()) {
                dir.mkdirs();
            }

            // Create the file on server
            File serverFile = new File(dir.getAbsolutePath() + File.separator + links.get(z).getLink());
            BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
            stream.write(bytes);
            stream.close();

        } catch (Exception e) {

            model.addObject("mess", "ERRORE!");
            return model;
        }
    }
    MultipartFile file = cover;

    try {
        byte[] bytes = file.getBytes();

        // Creating the directory to store file
        HttpSession session = request.getSession();
        ServletContext sc = session.getServletContext();

        File dir = new File(sc.getRealPath("/") + "dist" + File.separator + "dpage" + File.separator + "img"
                + File.separator + poi2.getId());
        if (!dir.exists()) {
            dir.mkdirs();
        }

        // Create the file on server
        File serverFile = new File(dir.getAbsolutePath() + File.separator + "cover.jpg");
        BufferedOutputStream stream = new BufferedOutputStream(new FileOutputStream(serverFile));
        stream.write(bytes);
        stream.close();

    } catch (Exception e) {

    }
    model.addObject("mess", "PAGINA INSERITA CORRETTAMENTE!");
    return model;
}

From source file:com.crimelab.service.MedicoLegalServiceImpl.java

@Override
public Workbook createMedicoMonthly(HttpSession session, String month) {
    Workbook wb = null;/*from   ww w  .  j a  v  a  2 s.c o m*/

    try {
        InputStream inp = session.getServletContext()
                .getResourceAsStream("/WEB-INF/templates/MedicoMonthly.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("Period Covered:");
        in1.setCellStyle(cs1);
        in1.setCellStyle(cs2);

        Row intro2 = sheet.createRow(10);
        Cell in2 = intro2.createCell(0);
        in1.setCellValue(month.split("-")[0]);
        in1.setCellStyle(cs1);
        in1.setCellStyle(cs2);

        int ctr = 12; //initial
        Row row = sheet.createRow(ctr);
        month = month.split("-")[1];

        //JOptionPane.showMessageDialog(null, medicoLegalDAO.getAllMedicoLegal(month));
        for (MedicoLegal medicoLegal : medicoLegalDAO.getAllMedicoLegal(month)) {
            //JOptionPane.showMessageDialog(null, medicoLegal.getReportNo());
            Cell cell0 = row.createCell(0);
            cell0.setCellValue(medicoLegal.getCaseNo());
            cell0.setCellStyle(bt);
            cell0.setCellStyle(bb);
            cell0.setCellStyle(bl);
            cell0.setCellStyle(br);

            Cell cell1 = row.createCell(1);//.setCellValue(medicoLegal.getReportNo());
            cell1.setCellValue(medicoLegal.getExaminerName());
            cell1.setCellStyle(bt);
            cell1.setCellStyle(bb);
            cell1.setCellStyle(bl);
            cell1.setCellStyle(br);

            Cell cell2 = row.createCell(2);//.setCellValue(medicoLegal.getRequestingParty());
            cell2.setCellValue(medicoLegal.getCaseType());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell2.setCellStyle(bl);
            cell2.setCellStyle(br);

            Cell cell3 = row.createCell(3);//.setCellValue(medicoLegal.getDescriptionOfEvidence());
            cell3.setCellValue(medicoLegal.getVictim());
            cell2.setCellStyle(bt);
            cell2.setCellStyle(bb);
            cell3.setCellStyle(bl);
            cell3.setCellStyle(br);

            Cell cell4 = row.createCell(4);//.setCellValue(medicoLegal.getSpecimenWeight());
            cell4.setCellValue(medicoLegal.getSuspect());
            cell4.setCellStyle(bt);
            cell4.setCellStyle(bb);
            cell4.setCellStyle(bl);
            cell4.setCellStyle(br);

            Cell cell5 = row.createCell(5);//.setCellValue(medicoLegal.getCustody());
            cell5.setCellValue(medicoLegal.getTimeDateReceived());
            cell5.setCellStyle(bt);
            cell5.setCellStyle(bb);
            cell5.setCellStyle(bl);
            cell5.setCellStyle(br);

            Cell cell6 = row.createCell(6);//.setCellValue(medicoLegal.getSuspects());
            cell6.setCellValue(medicoLegal.getFindings());
            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;
}

From source file:com.onehippo.gogreen.login.HstConcurrentLoginFilter.java

private void registerUserSession(HttpServletRequest request, String username) {
    log.debug("HstConcurrentLoginFilter will register session for {}", username);
    HttpSession session = request.getSession();
    session.setAttribute(USERNAME_ATTR, username);

    ServletContext servletContext = session.getServletContext();
    @SuppressWarnings("unchecked")
    Map<String, HttpSessionWrapper> map = (Map<String, HttpSessionWrapper>) servletContext
            .getAttribute(USERNAME_SESSIONID_MAP_ATTR);

    if (map != null) {
        String newSessionId = session.getId();
        HttpSessionWrapper oldHttpSessionWrapper = map.put(username,
                new HttpSessionWrapper(session, earlySessionInvalidation));
        log.debug("HstConcurrentLoginFilter registered session ({}) for {}.", newSessionId, username);

        if (oldHttpSessionWrapper != null) {
            oldHttpSessionWrapper.invalidate();
            log.debug("HstConcurrentLoginFilter kicked out session ({}) for {}.", oldHttpSessionWrapper.getId(),
                    username);//from   w w  w.j  a  v  a2  s  .c  om
        }
    } else {
        log.error("HstConcurrentLoginFilter is in invalid state. The session ids map is not found.");
    }
}

From source file:net.longfalcon.web.AdminIndexController.java

@RequestMapping(value = "/admin/site-edit", method = RequestMethod.GET)
public String editSiteView(Model model, HttpSession httpSession) {
    Site site = config.getDefaultSite();
    model.addAttribute("title", "Site Edit");
    model.addAttribute("siteObject", site);

    List<String> themeNameList = new ArrayList<>();
    try {/*from  w  ww. j  av  a  2 s .c  o m*/
        String realPath = httpSession.getServletContext().getRealPath("/public-resources/themes");
        File themesDir = new File(realPath);
        String[] themeDirList = themesDir.list();
        Collections.addAll(themeNameList, themeDirList);
    } catch (Exception e) {
        _log.error(e, e);
    }

    Map<Integer, String> showPasswordedRelOptionsMap = new HashMap<>();
    showPasswordedRelOptionsMap.put(0, "Dont show passworded or potentially passworded");
    showPasswordedRelOptionsMap.put(1, "Dont show passworded");
    showPasswordedRelOptionsMap.put(2, "Show everything");

    Map<Integer, String> newGroupsScanMethodMap = new HashMap<>();
    newGroupsScanMethodMap.put(1, "Days");
    newGroupsScanMethodMap.put(0, "Posts");

    Map<Integer, String> registerStatusMap = new HashMap<>();
    registerStatusMap.put(SiteService.REGISTER_STATUS_OPEN, "Open");
    registerStatusMap.put(SiteService.REGISTER_STATUS_INVITE, "Invite");
    registerStatusMap.put(SiteService.REGISTER_STATUS_CLOSED, "Closed");

    model.addAttribute("yesNoMap", YES_NO_MAP);
    model.addAttribute("showPasswordedRelOptionsMap", showPasswordedRelOptionsMap);
    model.addAttribute("newGroupsScanMethodMap", newGroupsScanMethodMap);
    model.addAttribute("registerStatusMap", registerStatusMap);
    model.addAttribute("themeNameList", themeNameList);
    return "admin/site-edit";
}

From source file:org.ecocean.ApiAccess.java

public Document initConfig(HttpServletRequest request) {
    if (this.configDoc != null)
        return this.configDoc;
    HttpSession session = request.getSession(true);
    String context = "context0";
    context = ServletUtilities.getContext(request);
    //Shepherd myShepherd = new Shepherd(context);
    ServletContext sc = session.getServletContext();
    File afile = new File(sc.getRealPath("/") + "/WEB-INF/classes/apiaccess.xml");
    System.out.println("reading file??? " + afile.toString());

    // h/t http://www.mkyong.com/java/how-to-read-xml-file-in-java-dom-parser/
    try {//from   ww w .  ja  v  a 2 s.co  m
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        this.configDoc = dBuilder.parse(afile);
        this.configDoc.getDocumentElement().normalize();
    } catch (Exception ex) {
        System.out.println("could not read " + afile.toString() + ": " + ex.toString());
        this.configDoc = null;
    }
    return this.configDoc;
}

From source file:edu.cornell.mannlib.vitro.webapp.edit.n3editing.configuration.generators.NewIndividualFormGenerator.java

private void prepareForUpdate(VitroRequest vreq, HttpSession session, EditConfigurationVTwo editConfiguration) {
    //Here, retrieve model from 
    Model model = (Model) session.getServletContext().getAttribute("jenaOntModel");
    //This form is always doing a non-update
    editConfiguration.prepareForNonUpdate(model);

}

From source file:edu.cornell.mannlib.vitro.webapp.controller.authenticate.BasicAuthenticator.java

/**
 * Record the login in the user/session map.
 * /* w  ww .  j  av a  2s  .  com*/
 * TODO What is this map used for?
 */
private void recordInUserSessionMap(String userUri, HttpSession session) {
    Map<String, HttpSession> userURISessionMap = Authenticate
            .getUserURISessionMapFromContext(session.getServletContext());
    userURISessionMap.put(userUri, session);
}