Search in sources :

Example 36 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project BroadleafCommerce by BroadleafCommerce.

the class PropertiesVariableExpression method getForceShowIdColumns.

/**
 * Returns true if the <b>listGrid.forceShowIdColumns</b> system property or a <b>showIds</b> request parameter is set
 * to true. Used in the admin to show ID columns when displaying list grids.
 */
public boolean getForceShowIdColumns() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    boolean forceShow = BLCSystemProperty.resolveBooleanSystemProperty("listGrid.forceShowIdColumns");
    forceShow = forceShow || "true".equals(request.getParameter("showIds"));
    return forceShow;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 37 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project BroadleafCommerce by BroadleafCommerce.

the class StaleStateProtectionServiceImpl method invalidateState.

@Override
public void invalidateState(boolean notify) {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    if (BLCRequestUtils.isOKtoUseSession(new ServletWebRequest(request))) {
        HttpSession session = request.getSession();
        session.removeAttribute(STATEVERSIONTOKEN);
        if (notify) {
            getStateVersionToken();
            request.setAttribute(STATECHANGENOTIFICATIONTOKEN, "true");
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) HttpSession(javax.servlet.http.HttpSession) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) ServletWebRequest(org.springframework.web.context.request.ServletWebRequest)

Example 38 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project spring-cloud by Rogge666.

the class SessionUserInfo method getSessionUser.

/**
 * 获取当前会话(静态)
 */
public static <T extends SessionUser> T getSessionUser(Class<T> clazz) {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    ApplicationContext ctx = WebApplicationContextUtils.getWebApplicationContext(request.getServletContext());
    SessionUserInfo sessionUserInfo = (SessionUserInfo) ctx.getBean("sessionUserInfo");
    return sessionUserInfo.getSessionUser(request.getSession(), clazz);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ApplicationContext(org.springframework.context.ApplicationContext) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes)

Example 39 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project spring-cloud by Rogge666.

the class Util method getCurrentLanguage.

/**
 * 获取当前会话语言(如果找不到默认返回中文)
 *
 * @return
 */
public static LanguageEnum getCurrentLanguage() {
    try {
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
        LanguageEnum language = (LanguageEnum) request.getSession().getAttribute(Constant.CURRENT_LANGUAGE);
        if (language != null) {
            return language;
        }
    } catch (Exception e) {
    }
    return LanguageEnum.zh_CN;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) LanguageEnum(com.rogge.common.model.LanguageEnum)

Example 40 with ServletRequestAttributes

use of org.springframework.web.context.request.ServletRequestAttributes in project Gatekeeper by FINRAOS.

the class GatekeeperCommonConfig method userProfile.

/* Request scoped bean to create autowireable UserProfile object */
@Bean
@Scope(value = "request", proxyMode = ScopedProxyMode.TARGET_CLASS)
public IGatekeeperUserProfile userProfile() {
    HttpServletRequest req = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    Principal p = req.getUserPrincipal();
    return (IGatekeeperUserProfile) p;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletRequestAttributes(org.springframework.web.context.request.ServletRequestAttributes) IGatekeeperUserProfile(org.finra.gatekeeper.common.authfilter.parser.IGatekeeperUserProfile) Principal(java.security.Principal) Scope(org.springframework.context.annotation.Scope) FilterRegistrationBean(org.springframework.boot.context.embedded.FilterRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Aggregations

ServletRequestAttributes (org.springframework.web.context.request.ServletRequestAttributes)205 HttpServletRequest (javax.servlet.http.HttpServletRequest)92 MockHttpServletRequest (org.springframework.mock.web.MockHttpServletRequest)62 RequestAttributes (org.springframework.web.context.request.RequestAttributes)50 MockHttpServletResponse (org.springframework.mock.web.MockHttpServletResponse)32 Test (org.junit.jupiter.api.Test)28 lombok.val (lombok.val)25 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)22 Test (org.junit.Test)18 AuthChecker (com.code.server.login.anotation.AuthChecker)17 HttpSession (javax.servlet.http.HttpSession)12 Before (org.junit.Before)12 HashMap (java.util.HashMap)11 Method (java.lang.reflect.Method)8 Date (java.util.Date)7 AbstractTracingSpan (org.apache.skywalking.apm.agent.core.context.trace.AbstractTracingSpan)7 TraceSegment (org.apache.skywalking.apm.agent.core.context.trace.TraceSegment)7 HttpServletRequest (jakarta.servlet.http.HttpServletRequest)6 Map (java.util.Map)6 BeforeEach (org.junit.jupiter.api.BeforeEach)6