All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.mg.framework.utils.RequestHolder Maven / Gradle / Ivy

The newest version!
package com.mg.framework.utils;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class RequestHolder {
    public static HttpServletRequest getRequest(){
        HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        return req;
    }

    public static HttpServletResponse getResponse(){
        HttpServletResponse resp = ((ServletWebRequest) RequestContextHolder.getRequestAttributes()).getResponse();
        return resp;
    }

    public static Session getShiroSession(){
        return SecurityUtils.getSubject().getSession();
    }

    public static Session getShiroSession(boolean create){
        return SecurityUtils.getSubject().getSession(create);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy