Example usage for org.springframework.web.context.request RequestContextHolder currentRequestAttributes

List of usage examples for org.springframework.web.context.request RequestContextHolder currentRequestAttributes

Introduction

In this page you can find the example usage for org.springframework.web.context.request RequestContextHolder currentRequestAttributes.

Prototype

public static RequestAttributes currentRequestAttributes() throws IllegalStateException 

Source Link

Document

Return the RequestAttributes currently bound to the thread.

Usage

From source file:net.jforum.core.support.spring.RoleManagerFactoryBean.java

/**
 * @see org.springframework.beans.factory.FactoryBean#getObject()
 *//*  w w  w.  j  a va 2  s. c  o m*/
public RoleManager getObject() throws Exception {
    String sessionId = RequestContextHolder.currentRequestAttributes().getSessionId();
    UserSession userSession = this.sessionManager.getUserSession(sessionId);
    return userSession != null ? userSession.getRoleManager() : null;
}

From source file:de.dominikschadow.javasecurity.sessionhandling.users.UserBean.java

public String getSessionId() {
    return RequestContextHolder.currentRequestAttributes().getSessionId();
}

From source file:darks.orm.web.context.SpringRequestHolder.java

@Override
public HttpServletRequest getRequest() {
    RequestAttributes attributes = RequestContextHolder.currentRequestAttributes();
    return (HttpServletRequest) attributes.resolveReference(RequestKey);
}

From source file:net.groupbuy.template.directive.ExecuteTimeDirective.java

@SuppressWarnings("rawtypes")
public void execute(Environment env, Map params, TemplateModel[] loopVars, TemplateDirectiveBody body)
        throws TemplateException, IOException {
    RequestAttributes requestAttributes = RequestContextHolder.currentRequestAttributes();
    if (requestAttributes != null) {
        Long executeTime = (Long) requestAttributes.getAttribute(
                ExecuteTimeInterceptor.EXECUTE_TIME_ATTRIBUTE_NAME, RequestAttributes.SCOPE_REQUEST);
        if (executeTime != null) {
            setLocalVariable(VARIABLE_NAME, executeTime, env, body);
        }/*from   w w w. j a va2  s.com*/
    }
}

From source file:org.n52.web.common.RequestUtils.java

/**
 * Get the full request {@link URL} including the query parameter
 *
 * @return Request {@link URL} with query parameter
 * @throws IOException//ww w  .  jav  a2  s  . c o m
 * @throws URISyntaxException
 */
public static String resolveFullRequestUrl() throws IOException, URISyntaxException {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();

    URL url = new URL(request.getRequestURL().toString());

    String scheme = url.getProtocol();
    String userInfo = url.getUserInfo();
    String host = url.getHost();

    int port = url.getPort();

    String path = request.getRequestURI();
    if (path != null && path.endsWith("/")) {
        path = path.substring(0, path.length() - 1);
    }
    String query = request.getQueryString();

    URI uri = new URI(scheme, userInfo, host, port, path, query, null);
    return uri.toString();
}

From source file:com.boaglio.controller.IndexController.java

@GetMapping("/hello")
public String hello(Map<String, Object> model, HttpServletRequest httpServletRequest) {

    String sessionID = RequestContextHolder.currentRequestAttributes().getSessionId();
    String user = httpServletRequest.getRemoteUser();
    model.put("sessionID", sessionID);

    System.out.println("------------------------------------------");
    System.out.println(" sessionID = " + sessionID);
    System.out.println("      user = " + user);

    return "hello";
}

From source file:org.ratty.impl.SecurityServiceImpl.java

public void haveToBeLogged() throws NotLoggedException {

    ServletRequestAttributes attr = (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    HttpSession session = attr.getRequest().getSession();

    if (session != null) {
        Object isLoggedObj = session.getAttribute("isLogged");

        if (!(isLoggedObj != null && isLoggedObj instanceof Boolean && (Boolean) isLoggedObj)) {
            throw new NotLoggedException("The user is not logged !");
        }//from   w ww .  j a  v  a 2 s  . c o  m
    }
}

From source file:com.ocs.dynamo.service.impl.DefaultUserDetailsServiceImpl.java

@Override
public String getCurrentUserName() {
    try {//from   ww w .  j a v a2 s .c o m
        HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder
                .currentRequestAttributes()).getRequest();
        return request.getUserPrincipal().getName();
    } catch (Exception ex) {
        // ignore - no request available during integration test
        return SYSTEM;
    }
}

From source file:io.jmnarloch.spring.boot.hystrix.wrapper.RequestAttributeAwareCallableWrapper.java

@Override
public <T> Callable<T> wrapCallable(Callable<T> callable) {
    return new RequestAttributeAwareCallable<>(callable, RequestContextHolder.currentRequestAttributes());
}

From source file:com.inkubator.hrm.util.HrmUserInfoUtil.java

public static String getRequestRemoteAddrBySpring() {
    HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.currentRequestAttributes())
            .getRequest();//from  w w w. ja va  2 s  .c o m
    return request.getRemoteAddr();
}