Tabnine Logo
HttpSession.getAttribute
Code IndexAdd Tabnine to your IDE (free)

How to use
getAttribute
method
in
javax.servlet.http.HttpSession

Best Java code snippets using javax.servlet.http.HttpSession.getAttribute (Showing top 20 results out of 10,503)

Refine searchRefine arrow

  • HttpServletRequest.getSession
  • HttpSession.setAttribute
  • HttpServletRequest.getParameter
  • HttpSession.removeAttribute
  • FilterChain.doFilter
  • HttpServletResponse.sendRedirect
origin: spring-projects/spring-framework

/**
 * Retrieves saved FlashMap instances from the HTTP session, if any.
 */
@Override
@SuppressWarnings("unchecked")
@Nullable
protected List<FlashMap> retrieveFlashMaps(HttpServletRequest request) {
  HttpSession session = request.getSession(false);
  return (session != null ? (List<FlashMap>) session.getAttribute(FLASH_MAPS_SESSION_ATTRIBUTE) : null);
}
origin: dropwizard/dropwizard

@SuppressWarnings("unchecked")
Flash(HttpSession session) {
  this.session = session;
  this.value = (T) session.getAttribute(ATTRIBUTE);
  if (this.value != null) {
    session.removeAttribute(ATTRIBUTE);
  }
}
origin: stackoverflow.com

 HttpSession session = request.getSession();
Integer n = (Integer) session.getAttribute("foo");
// not thread safe
// another thread might be have got stale value between get and set
session.setAttribute("foo", (n == null) ? 1 : n + 1);
origin: DeemOpen/zkui

@Override
public void doFilter(ServletRequest req, ServletResponse res, FilterChain fc) throws IOException, ServletException {
  HttpServletRequest request = (HttpServletRequest) req;
  HttpServletResponse response = (HttpServletResponse) res;
  if (!request.getRequestURI().contains("/login") && !request.getRequestURI().contains("/acd/appconfig")) {
    RequestDispatcher dispatcher;
    HttpSession session = request.getSession();
    if (session != null) {
      if (session.getAttribute("authName") == null || session.getAttribute("authRole") == null) {
        response.sendRedirect("/login");
        return;
      }
    } else {
      request.setAttribute("fail_msg", "Session timed out!");
      dispatcher = request.getRequestDispatcher("/Login");
      dispatcher.forward(request, response);
      return;
    }
  }
  fc.doFilter(req, res);
}
origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

/**
 * Set the timestamp on the session to mark when the authentication happened,
 * useful for calculating authentication age. This gets stored in the sesion
 * and can get pulled out by other components.
 */
@Override
public void onAuthenticationSuccess(HttpServletRequest request, HttpServletResponse response, Authentication authentication) throws IOException, ServletException {
  Date authTimestamp = new Date();
  HttpSession session = request.getSession();
  session.setAttribute(AUTH_TIMESTAMP, authTimestamp);
  if (session.getAttribute(AuthorizationRequestFilter.PROMPT_REQUESTED) != null) {
    session.setAttribute(AuthorizationRequestFilter.PROMPTED, Boolean.TRUE);
    session.removeAttribute(AuthorizationRequestFilter.PROMPT_REQUESTED);
  }
  logger.info("Successful Authentication of " + authentication.getName() + " at " + authTimestamp.toString());
  super.onAuthenticationSuccess(request, response, authentication);
}
origin: stackoverflow.com

 HttpServletRequest request = this.getThreadLocalRequest();

HttpSession session = request.getSession();

// in your authentication method
if(isCorrectPassword)
  session.setAttribute("authenticatedUserName", "name");

// later
 if (session.getAttribute("authenticatedUserName") != null)
origin: gocd/gocd

  public boolean verify(HttpServletRequest request) {
    String postedToken = request.getParameter(TOKEN);
    String expectedToken = (String) request.getSession().getAttribute(TOKEN);
    return !StringUtils.isBlank(postedToken) && !StringUtils.isBlank(expectedToken) && postedToken.equals(expectedToken);
  }
}
origin: mitreid-connect/OpenID-Connect-Java-Spring-Server

HttpSession session = request.getSession();
  chain.doFilter(req, res);
  return;
    session.setAttribute(LOGIN_HINT, loginHint);
  } else {
    session.removeAttribute(LOGIN_HINT);
        chain.doFilter(req, res);
      } else {
        logger.info("Client requested no prompt");
            response.sendRedirect(uriBuilder.toString());
            return;
      if (session.getAttribute(PROMPTED) == null) {
        session.setAttribute(PROMPT_REQUESTED, Boolean.TRUE);
          chain.doFilter(req, res);
        } else {
        session.removeAttribute(PROMPTED);
        chain.doFilter(req, res);
      Date authTime = (Date) session.getAttribute(AuthenticationTimeStamper.AUTH_TIMESTAMP);
origin: DeemOpen/zkui

String action = request.getParameter("action");
String currentPath = request.getParameter("currentPath");
String displayPath = request.getParameter("displayPath");
String authRole = (String) request.getSession().getAttribute("authRole");
      request.getSession().setAttribute("flashMsg", "Node created!");
      dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Creating node: " + currentPath + newNode);
    response.sendRedirect("/home?zkPath=" + displayPath);
    break;
  case "Save Property":
      request.getSession().setAttribute("flashMsg", "Property Saved!");
      if (ZooKeeperUtil.INSTANCE.checkIfPwdField(newProperty)) {
        newValue = ZooKeeperUtil.INSTANCE.SOPA_PIPA;
      dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Saving Property: " + currentPath + "," + newProperty + "=" + newValue);
    response.sendRedirect("/home?zkPath=" + displayPath);
    break;
  case "Update Property":
      dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Updating Property: " + currentPath + "," + newProperty + "=" + newValue);
          dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Deleting Property: " + delPropLst.toString());
          dao.insertHistory((String) request.getSession().getAttribute("authName"), request.getRemoteAddr(), "Deleting Nodes: " + delNodeLst.toString());
origin: spring-projects/spring-session

  @Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    assertThat(wrappedRequest.getSession().getAttribute(ATTR))
        .isEqualTo(VALUE);
    wrappedRequest.getSession().removeAttribute(ATTR);
    assertThat(wrappedRequest.getSession().getAttribute(ATTR)).isNull();
  }
});
origin: elasticjob/elastic-job-lite

@Override
public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
  HttpServletRequest httpRequest = (HttpServletRequest) servletRequest;
  HttpSession httpSession = httpRequest.getSession();
  if (null == httpSession.getAttribute(RegistryCenterRestfulApi.REG_CENTER_CONFIG_KEY)) {
    loadActivatedRegCenter(httpSession);
  }
  if (null == httpSession.getAttribute(EventTraceDataSourceRestfulApi.DATA_SOURCE_CONFIG_KEY)) {
    loadActivatedEventTraceDataSource(httpSession);
  }
  filterChain.doFilter(servletRequest, servletResponse);
}

origin: stackoverflow.com

public class Logout extends HttpServlet {
 public Logout() {
   super();
 }
 protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
   HttpSession session = request.getSession();
   if(session.getAttribute("user") != null){
     session.removeAttribute("user");
     response.sendRedirect("login.jsp");
   }
 }
origin: spring-projects/spring-session

  @Override
  public void doFilter(HttpServletRequest wrappedRequest) {
    wrappedRequest.getSession().setAttribute(ATTR, VALUE);
    assertThat(wrappedRequest.getSession().getAttribute(ATTR))
        .isEqualTo(VALUE);
    assertThat(
        Collections.list(wrappedRequest.getSession().getAttributeNames()))
            .containsOnly(ATTR);
  }
});
origin: spring-projects/spring-security

DiscoveryInformation discovered = (DiscoveryInformation) request.getSession()
    .getAttribute(DISCOVERY_INFO_KEY);
    .getSession().getAttribute(ATTRIBUTE_LIST_KEY);
request.getSession().removeAttribute(DISCOVERY_INFO_KEY);
request.getSession().removeAttribute(ATTRIBUTE_LIST_KEY);
origin: nutzam/nutz

  for (Enumeration<String> en = session.getAttributeNames(); en.hasMoreElements();) {
    String tem = en.nextElement();
    session_attr.put(tem, session.getAttribute(tem));
for (Object o : Lang.enum2collection(req.getParameterNames(), new ArrayList<String>())) {
  String key = (String) o;
  String value = req.getParameter(key);
  p.put(key, value);
origin: jenkinsci/jenkins

  @Override
  public boolean toggleCollapsed(String paneId) {
    final HttpSession session = Stapler.getCurrentRequest().getSession();
    final String property = format(attribute, paneId);
    final Object collapsed = session.getAttribute(property);
    if (collapsed == null) {
      session.setAttribute(property, true);
      return true;
    }
    session.removeAttribute(property);
    return false;
  }
}
origin: nutzam/nutz

public void clear() {
  synchronized (session) {
    Enumeration<String> ems = session.getAttributeNames();
    List<String> keys = new ArrayList<String>();
    while (ems.hasMoreElements()) {
      String key = ems.nextElement();
      if (null == key)
        continue;
      Object value = session.getAttribute(key);
      if (value instanceof ObjectProxy) {
        keys.add(key);
        ((ObjectProxy) value).depose();
      }
    }
    for (String key : keys) {
      session.removeAttribute(key);
    }
  }
}
origin: gocd/gocd

@Override
protected void doFilterInternal(HttpServletRequest request,
                HttpServletResponse response,
                FilterChain filterChain) throws ServletException, IOException {
  if (!SessionUtils.hasAuthenticationToken(request)) {
    LOGGER.debug("Authentication token is not created for the request.");
    filterChain.doFilter(request, response);
    return;
  }
  final AuthenticationToken<?> authenticationToken = SessionUtils.getAuthenticationToken(request);
  Assert.notNull(authenticationToken);
  synchronized (request.getSession(false).getId().intern()) {
    long localCopyOfLastChangedTime = lastChangedTime;//This is so that the volatile variable is accessed only once.
    Long previousLastChangedTime = (Long) request.getSession().getAttribute(SECURITY_CONFIG_LAST_CHANGE);
    if (previousLastChangedTime == null) {
      request.getSession().setAttribute(SECURITY_CONFIG_LAST_CHANGE, localCopyOfLastChangedTime);
    } else if (previousLastChangedTime < localCopyOfLastChangedTime) {
      request.getSession().setAttribute(SECURITY_CONFIG_LAST_CHANGE, localCopyOfLastChangedTime);
      LOGGER.debug("Invalidating existing token {}", authenticationToken);
      authenticationToken.invalidate();
    }
  }
  filterChain.doFilter(request, response);
}
origin: BroadleafCommerce/BroadleafCommerce

private Long lookupSandboxId(HttpServletRequest request) {
  String sandboxIdStr = request.getParameter(SANDBOX_ID_VAR);
  Long sandboxId = null;
  if (sandboxIdStr != null) {
    try {
      sandboxId = Long.valueOf(sandboxIdStr);
      if (LOG.isTraceEnabled()) {
        LOG.trace("SandboxId found on request " + sandboxId);
      }
    } catch (NumberFormatException nfe) {
      LOG.warn("blcSandboxId parameter could not be converted into a Long", nfe);
    }
  }
  if (sandboxId == null) {
    // check the session
    HttpSession session = request.getSession(false);
    if (session != null) {
      sandboxId = (Long) session.getAttribute(SANDBOX_ID_VAR);
      if (LOG.isTraceEnabled()) {
        if (sandboxId != null) {
          LOG.trace("SandboxId found in session " + sandboxId);
        }
      }
    }
  } else {
    HttpSession session = request.getSession();
    session.setAttribute(SANDBOX_ID_VAR, sandboxId);
  }
  return sandboxId;
}
origin: azkaban/azkaban

/**
 * Adds a session value to the request
 */
protected void addSessionValue(final HttpServletRequest request, final String key,
  final Object value) {
 List l = (List) request.getSession(true).getAttribute(key);
 if (l == null) {
  l = new ArrayList();
 }
 l.add(value);
 request.getSession(true).setAttribute(key, l);
}
javax.servlet.httpHttpSessiongetAttribute

Javadoc

Returns the object bound with the specified name in this session, or null if no object is bound under the name.

Popular methods of HttpSession

  • setAttribute
    Binds an object to this session, using the name specified. If an object of the same name is already
  • getId
    Returns a string containing the unique identifier assigned to this session. The identifier is assign
  • removeAttribute
    Removes the object bound with the specified name from this session. If the session does not have an
  • invalidate
    Invalidates this session then unbinds any objects bound to it.
  • getAttributeNames
    Returns an Enumeration of String objects containing the names of all the objects bound to this sessi
  • getServletContext
    Returns the ServletContext to which this session belongs.
  • getMaxInactiveInterval
    Returns the maximum time interval, in seconds, that the servlet container will keep this session ope
  • setMaxInactiveInterval
    Specifies the time, in seconds, between client requests before the servlet container will invalidate
  • isNew
    Returns true if the client does not yet know about the session or if the client chooses not to join
  • getLastAccessedTime
    Returns the last time the client sent a request associated with this session, as the number of milli
  • getCreationTime
    Returns the time when this session was created, measured in milliseconds since midnight January 1, 1
  • getSessionContext
  • getCreationTime,
  • getSessionContext,
  • getValueNames,
  • putValue,
  • getValue,
  • removeValue,
  • <init>,
  • addAttribute,
  • containsKey

Popular in Java

  • Updating database using SQL prepared statement
  • setRequestProperty (URLConnection)
  • findViewById (Activity)
  • getSharedPreferences (Context)
  • Component (java.awt)
    A component is an object having a graphical representation that can be displayed on the screen and t
  • GridLayout (java.awt)
    The GridLayout class is a layout manager that lays out a container's components in a rectangular gri
  • Comparator (java.util)
    A Comparator is used to compare two objects to determine their ordering with respect to each other.
  • Queue (java.util)
    A collection designed for holding elements prior to processing. Besides basic java.util.Collection o
  • SSLHandshakeException (javax.net.ssl)
    The exception that is thrown when a handshake could not be completed successfully.
  • JComboBox (javax.swing)
  • Github Copilot alternatives
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now