Example usage for javax.servlet.http HttpServletRequest getSession

List of usage examples for javax.servlet.http HttpServletRequest getSession

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletRequest getSession.

Prototype

public HttpSession getSession();

Source Link

Document

Returns the current session associated with this request, or if the request does not have a session, creates one.

Usage

From source file:org.runway.utils.AuthenticationUtils.java

public static void autoLogin(User user, HttpServletRequest request,
        AuthenticationManager authenticationManager) {

    //           GrantedAuthority[] grantedAuthorities = new GrantedAuthority[] { new GrantedAuthorityImpl(
    //             user.getAuthority()) };

    UsernamePasswordAuthenticationToken token = new UsernamePasswordAuthenticationToken(user.getUsername(),
            user.getPassword(), user.getAuthorities());

    // generate session if one doesn't exist
    HttpSession session = request.getSession();

    token.setDetails(new WebAuthenticationDetails(request));
    Authentication authenticatedUser = authenticationManager.authenticate(token);

    SecurityContextHolder.getContext().setAuthentication(authenticatedUser);
    // setting role to the session
    session.setAttribute(HttpSessionSecurityContextRepository.SPRING_SECURITY_CONTEXT_KEY,
            SecurityContextHolder.getContext());

}

From source file:edu.cornell.mannlib.vitro.webapp.dao.filtering.filters.FilterByRoleLevelPermission.java

private static Permission getPermissionFromRequest(HttpServletRequest req) {
    if (req == null) {
        throw new NullPointerException("request may not be null.");
    }/*from w w w. ja  v a  2s.  co m*/

    IdentifierBundle ids = RequestIdentifiers.getIdBundleForRequest(req);
    for (Permission p : HasPermission.getPermissions(ids)) {
        if (p instanceof DisplayByRolePermission) {
            return p;
        }
    }
    return getDefaultPermission(req.getSession().getServletContext());
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.java

public static ModelAccess on(HttpServletRequest req) {
    Object o = req.getAttribute(ATTRIBUTE_NAME);
    if (o instanceof ModelAccess) {
        return (ModelAccess) o;
    } else {// w ww  . j a va 2 s  .  c  om
        ModelAccess parent = on(req.getSession());
        ModelAccess ma = new ModelAccess(Scope.REQUEST, parent);
        req.setAttribute(ATTRIBUTE_NAME, ma);
        return ma;
    }
}

From source file:gov.nih.nci.caIMAGE.util.SafeHTMLUtil.java

/**
 * A utility method to check the valid value against a string values
 * Author for method: // ww  w . j ava  2s  . co m
 * @param input - the data to be validated
 * @param source - the source against which the input to be validated
 * @param request - http request
 * @return boolean
 */
public static boolean isValidStringValue(String input, String source, HttpServletRequest request) {
    // validate for intentCode
    System.out.println("SafeHTMLUtil.isValidStringValue.");
    List dropDownList = (List) request.getSession().getAttribute(source);
    String nv = null;
    boolean validValue = true;
    if (input != null && input.length() > 0 && dropDownList != null) {
        // assign the value to false
        validValue = false;

        for (int i = 0; i < dropDownList.size(); i++) {
            nv = ((DropdownOption) dropDownList.get(i)).getLabel();
            if (nv.equals(input)) {
                validValue = true;
                break;
            }
        }
    }
    return validValue;
}

From source file:com.ofbizcn.securityext.login.LoginEvents.java

/**
 * Save USERNAME and PASSWORD for use by auth pages even if we start in non-auth pages.
 *
 * @param request The HTTP request object for the current JSP or Servlet request.
 * @param response The HTTP response object for the current JSP or Servlet request.
 * @return String// w w w . j  ava 2  s  . c o  m
 */
public static String saveEntryParams(HttpServletRequest request, HttpServletResponse response) {
    GenericValue userLogin = (GenericValue) request.getSession().getAttribute("userLogin");
    HttpSession session = request.getSession();
    Delegator delegator = (Delegator) request.getAttribute("delegator");

    // save entry login parameters if we don't have a valid login object
    if (userLogin == null) {

        String username = request.getParameter("USERNAME");
        String password = request.getParameter("PASSWORD");

        if ((username != null) && ("true".equalsIgnoreCase(EntityUtilProperties
                .getPropertyValue("security.properties", "username.lowercase", delegator)))) {
            username = username.toLowerCase();
        }
        if ((password != null) && ("true".equalsIgnoreCase(EntityUtilProperties
                .getPropertyValue("security.properties", "password.lowercase", delegator)))) {
            password = password.toLowerCase();
        }

        // save parameters into the session - so they can be used later, if needed
        if (username != null)
            session.setAttribute("USERNAME", username);
        if (password != null)
            session.setAttribute("PASSWORD", password);

    } else {
        // if the login object is valid, remove attributes
        session.removeAttribute("USERNAME");
        session.removeAttribute("PASSWORD");
    }

    return "success";
}

From source file:fr.paris.lutece.portal.web.PortalJspBean.java

/**
 * Remove the upload filter next url from the session
 * @param request the HTTP request//from  ww  w .j  a  v a 2 s . c  om
 */
public static void removeUploadFilterSiteNextUrl(HttpServletRequest request) {
    HttpSession session = request.getSession();
    session.removeAttribute(ATTRIBUTE_UPLOAD_FILTER_SITE_NEXT_URL);
}

From source file:fr.paris.lutece.portal.web.PortalJspBean.java

/**
 * Returns the url (asked before login) to redirect after login
 * @param request The Http request/*w ww.j  a  v  a  2s . c o  m*/
 * @return The url asked before login
 * @since v1.1
 */
public static String getLoginNextUrl(HttpServletRequest request) {
    HttpSession session = request.getSession();
    String strNextUrl = (String) session.getAttribute(ATTRIBUTE_LOGIN_NEXT_URL);

    return strNextUrl;
}

From source file:fr.paris.lutece.portal.web.PortalJspBean.java

/**
 * Get the upload filter site next url//from   w w w.  j  av a 2  s.c o m
 * @param request the HTTP request
 * @return the next url
 */
public static String getUploadFilterSiteNextUrl(HttpServletRequest request) {
    HttpSession session = request.getSession();
    String strNextUrl = (String) session.getAttribute(ATTRIBUTE_UPLOAD_FILTER_SITE_NEXT_URL);

    return strNextUrl;
}

From source file:edu.cornell.mannlib.vitro.webapp.dao.jena.VClassGroupCache.java

/**
 * Use getVClassGroups(HttpServletRequest) to get a language-aware image of
 * the cached groups and classes./*from w  ww . j a va 2s.  c  o  m*/
 */
public static VClassGroupsForRequest getVClassGroups(HttpServletRequest req) {
    return new VClassGroupsForRequest(req, getVClassGroupCache(req.getSession().getServletContext()));
}

From source file:com.serotonin.m2m2.Common.java

public static void setUser(HttpServletRequest request, User user) {
    request.getSession().setAttribute(SESSION_USER, user);
}