Example usage for javax.servlet.http HttpSession getAttribute

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

Introduction

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

Prototype

public Object getAttribute(String name);

Source Link

Document

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

Usage

From source file:be.fedict.eid.dss.webapp.BrowserInfoServlet.java

@SuppressWarnings("unchecked")
public static List<String> getPlugins(HttpSession httpSession) {
    List<String> plugins = (List<String>) httpSession.getAttribute(PLUGINS_SESSION_ATTRIBUTE);
    if (null == plugins) {
        plugins = new LinkedList<String>();
    }/*from   w ww .  j a v  a 2  s  .com*/
    return plugins;
}

From source file:org.keycloak.example.CustomerDatabaseClient.java

public static String increaseAndGetCounter(HttpServletRequest req) {
    HttpSession session = req.getSession();
    Integer counter = (Integer) session.getAttribute("counter");
    counter = (counter == null) ? 1 : counter + 1;
    session.setAttribute("counter", counter);
    return String.valueOf(counter);
}

From source file:be.fedict.eid.dss.webapp.BrowserInfoServlet.java

@SuppressWarnings("unchecked")
public static List<MimeType> getMimeTypes(HttpSession httpSession) {
    List<MimeType> mimeTypes = (List<MimeType>) httpSession.getAttribute(MIMETYPES_SESSION_ATTRIBUTE);
    if (null == mimeTypes) {
        mimeTypes = new LinkedList<MimeType>();
    }// w  w  w .j  ava 2s.  c  o  m
    return mimeTypes;
}

From source file:org.tec.webapp.web.ControllerUtils.java

/**
 * get the currently logged on user//from w  w  w .ja  v a2s. c  o m
 * @param session the current http session
 * @param userSvc the user service
 * @return the current user
 */
public static UserBean getCurrentUser(HttpSession session, UserSvc userSvc) {
    UserBean u = (UserBean) session.getAttribute(CURRENT_USER_KEY);

    if (u == null) {
        SecurityContext secctx = (SecurityContext) session.getAttribute(SPRING_SECURITY_CONTEXT_KEY);

        String currentUser = ((org.springframework.security.core.userdetails.User) secctx.getAuthentication()
                .getPrincipal()).getUsername();

        u = userSvc.getUser(currentUser);

        session.setAttribute(CURRENT_USER_KEY, u);
    }

    if (LOGGER.isDebugEnabled()) {
        LOGGER.debug("current user " + u);
    }

    return u;
}

From source file:cn.vlabs.umt.ui.UMTContext.java

public static boolean isAdminUser(HttpSession session) {
    UMTRole[] roles = (UMTRole[]) session.getAttribute(Attributes.ROLE);
    if (roles != null) {
        for (UMTRole role : roles) {
            if ("admin".equals(role.getName())) {
                return true;
            }//from w w w .  ja va2  s  .  c  o  m
        }
    }
    return false;
}

From source file:com.fruit.core.util.IWebUtils.java

/**
 * ?/*from   w  w  w  .ja v a2 s .c o m*/
 * @author eason
 * @param HttpSession
 * @return
 */
public static SysUser getCurrentSysUser(HttpSession httpSession) {
    SysUser sysUser = (SysUser) httpSession.getAttribute("sysUser");
    return sysUser;
}

From source file:com.netspective.sparx.security.EncryptedParametersFilter.java

public static final String getUserKey(final ServletRequest request) {
    HttpSession session = ((HttpServletRequest) request).getSession();
    String result = (String) session.getAttribute(SESSATTRNAME_ENCRYPTION_KEY);
    if (result == null) {
        try {/*from  w  ww.j a  va 2 s  .  co m*/
            result = GloballyUniqueIdentifier.getRandomGUID(true);
            session.setAttribute(SESSATTRNAME_ENCRYPTION_KEY, result);
        } catch (Exception e) {
            log.error("Error creating key", e);
            result = "really bad key (unsecure and not random)";
        }
    }
    return result;
}

From source file:org.appverse.web.framework.backend.api.helpers.security.SecurityHelper.java

public static String createXSRFToken(final HttpServletRequest request) throws IOException {
    // getSession(false) as this method never creates a new session
    HttpSession session = request.getSession(false);
    String xsrfSessionToken = (String) session.getAttribute(XSRF_TOKEN_NAME);
    if (xsrfSessionToken == null) {
        Random r = new Random(System.currentTimeMillis());
        long value = System.currentTimeMillis() + r.nextLong();
        char ids[] = session.getId().toCharArray();
        for (int i = 0; i < ids.length; i++) {
            value += ids[i] * (i + 1);/*from   w  w  w  . j  a v  a  2s  .  c o m*/
        }
        xsrfSessionToken = Long.toString(value);
        session.setAttribute(XSRF_TOKEN_NAME, xsrfSessionToken);
    }
    return xsrfSessionToken;
}

From source file:com.squarecash4glass.util.OAuth2Util.java

public static String getUserId(HttpServletRequest request) {
    HttpSession session = request.getSession();
    return (String) session.getAttribute("userId");
}

From source file:com.impetus.kwitter.KwitterUtils.java

public static Twitter getTwitterService() {
    HttpSession session = (HttpSession) FacesContext.getCurrentInstance().getExternalContext().getSession(true);
    Twitter twitter = (Twitter) session.getAttribute("twitter");
    if (twitter == null) {
        BeanFactory beanfactory = new ClassPathXmlApplicationContext("appContext.xml");
        twitter = (Twitter) beanfactory.getBean("twitter");
        session.setAttribute("twitter", twitter);
    }/*  w  ww  . j  a v  a  2 s  . com*/
    return twitter;
}