Ejemplo n.º 1
0
 public static int getPerfil() {
   ServletRequestAttributes attr =
       (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
   HttpSession session = attr.getRequest().getSession(true);
   Integer id = new Integer(session.getAttribute("userPerfil").toString());
   return id;
 }
Ejemplo n.º 2
0
  private String faqUrl() throws Exception {
    ServletRequestAttributes requestAttributes =
        (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = requestAttributes.getRequest();

    return UrlBuilder.createFaqUrl(request);
  }
Ejemplo n.º 3
0
 /**
  * 获取当前session对象. 若当前线程不是web请求或当前尚未创建{@code session}则返回{@code null}.
  *
  * @return 当前session对象或{@code null}.
  */
 public static HttpSession currentSession() {
   ServletRequestAttributes attrs =
       (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
   if (attrs == null) {
     return null;
   }
   return attrs.getRequest().getSession(false);
 }
Ejemplo n.º 4
0
  /**
   * returns the current http session object
   *
   * @return session
   */
  public HttpSession getSession() {
    HttpSession session = null;
    ServletRequestAttributes attr =
        (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    HttpSession contextSess = attr == null ? session : attr.getRequest().getSession(true);

    return contextSess;
  }
 @Before("aopAspect()")
 public void doAccessCheck() throws LoginException, PrivilegeException {
   // System.out.println("AOP: before collab 2");
   ServletRequestAttributes attr =
       (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
   HttpSession session = attr.getRequest().getSession(true);
   CommonMethod.checkPrivilege(attr, session, MetaData.FinanceMgrModule);
 }
Ejemplo n.º 6
0
 /**
  * 获取当前Request对象.
  *
  * @return 当前Request对象或{@code null}.
  * @throws IllegalStateException 当前线程不是web请求抛出此异常.
  */
 public static HttpServletRequest currentRequest() throws IllegalStateException {
   ServletRequestAttributes attrs =
       (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
   if (attrs == null) {
     throw new IllegalStateException("当前线程中不存在 Request 上下文");
   }
   return attrs.getRequest();
 }
Ejemplo n.º 7
0
  /** Recupera el nombre y apellido del usuario Autenticado */
  public static String getSessionUser() {
    ServletRequestAttributes attr =
        (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    HttpSession session = attr.getRequest().getSession(true);
    String usuario = (String) session.getAttribute("user");

    return usuario;
  }
Ejemplo n.º 8
0
  /** Retorna si hay un usuario Autenticado */
  public static Boolean isUserAutenticado() {
    ServletRequestAttributes attr =
        (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
    HttpSession session = attr.getRequest().getSession(true);

    if (session.getAttribute("userId") == null) {
      return false;
    }
    return true;
  }
Ejemplo n.º 9
0
  private String signUrl() throws Exception {
    ServletRequestAttributes requestAttributes =
        (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
    HttpServletRequest request = requestAttributes.getRequest();

    return UrlBuilder.signUrl()
        .request(request)
        .claName(claName)
        .repositoryId(repositoryId)
        .pullRequestId(pullRequestId)
        .build();
  }
  /**
   * Process this request, publishing an event regardless of the outcome.
   *
   * <p>The actual event handling is performed by the abstract {@link #doService} template method.
   */
  protected final void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {

    long startTime = System.currentTimeMillis();
    Throwable failureCause = null;

    LocaleContext previousLocaleContext = LocaleContextHolder.getLocaleContext();
    LocaleContext localeContext = buildLocaleContext(request);

    RequestAttributes previousAttributes = RequestContextHolder.getRequestAttributes();
    ServletRequestAttributes requestAttributes =
        buildRequestAttributes(request, response, previousAttributes);

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
    asyncManager.registerCallableInterceptor(
        FrameworkServlet.class.getName(), new RequestBindingInterceptor());

    initContextHolders(request, localeContext, requestAttributes);

    try {
      doService(request, response);
    } catch (ServletException ex) {
      failureCause = ex;
      throw ex;
    } catch (IOException ex) {
      failureCause = ex;
      throw ex;
    } catch (Throwable ex) {
      failureCause = ex;
      throw new NestedServletException("Request processing failed", ex);
    } finally {
      resetContextHolders(request, previousLocaleContext, previousAttributes);
      if (requestAttributes != null) {
        requestAttributes.requestCompleted();
      }

      if (logger.isDebugEnabled()) {
        if (failureCause != null) {
          this.logger.debug("Could not complete request", failureCause);
        } else {
          if (asyncManager.isConcurrentHandlingStarted()) {
            logger.debug("Leaving response open for concurrent processing");
          } else {
            this.logger.debug("Successfully completed request");
          }
        }
      }

      publishRequestHandledEvent(request, response, startTime, failureCause);
    }
  }
Ejemplo n.º 11
0
  public static HttpServletRequest getRequest() {

    HttpServletRequest request;
    try {
      ServletRequestAttributes attributes =
          (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();

      request = attributes.getRequest();
    } catch (Exception ex) {
      ex.printStackTrace();
      request = null;
    }

    return request;
  }
Ejemplo n.º 12
0
  public static HttpSession getSession() {

    HttpSession session;
    try {
      ServletRequestAttributes attributes =
          (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();

      session = attributes.getRequest().getSession();
    } catch (Exception ex) {
      ex.printStackTrace();
      session = null;
    }

    return session;
  }
  @Override
  protected void doFilterInternal(
      HttpServletRequest request, HttpServletResponse response, FilterChain filterChain)
      throws ServletException, IOException {

    ServletRequestAttributes attributes = new ServletRequestAttributes(request, response);
    initContextHolders(request, attributes);

    try {
      filterChain.doFilter(request, response);
    } finally {
      resetContextHolders();
      if (logger.isDebugEnabled()) {
        logger.debug("Cleared thread-bound request context: " + request);
      }
      attributes.requestCompleted();
    }
  }
Ejemplo n.º 14
0
  private Object getSessionAttribute(String attributeName) {
    Object result = null;

    // try to get session attribute from GraniteDS context
    GraniteContext graniteContext = GraniteContext.getCurrentInstance();
    if (graniteContext != null) {
      result = graniteContext.getSessionMap().get(attributeName);
    } else {
      // try to get session attribute from current request context holder session
      ServletRequestAttributes requestAttributes =
          (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
      if (requestAttributes != null) {
        HttpSession session = requestAttributes.getRequest().getSession();
        result = session.getAttribute(attributeName);
      }
    }
    if (result == null) {
      throw new InvalidSessionException("Error getting session attribute: " + attributeName);
    } else {
      return result;
    }
  }
Ejemplo n.º 15
0
  @PrePersist
  @PreUpdate
  public void onSaveOrUpdate(IdEntity entity) throws HibernateException {

    // 如果对象是IdEntity子类,添加审计信息.

    String loginName = null;
    if (null == loginName || StringUtils.isBlank(loginName)) {
      ServletRequestAttributes servletRequestAttributes =
          (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
      if (null != servletRequestAttributes) {
        HttpServletRequest request = servletRequestAttributes.getRequest();
        User user = (User) request.getSession().getAttribute(Constants.SESSION_USER_INFO);
        loginName = user.getUuid().toString();
      } else {
        loginName = "1";
      }
    }
    if (entity.getUuid() == null) {
      // 创建新对象
      entity.setCreateDate(new Date());
      entity.setCreateUserId(loginName);

      entity.setUpdateDate(new Date());
      entity.setUpdateUserId(loginName);
    } else {
      // 修改旧对象
      entity.setUpdateDate(new Date());
      entity.setUpdateUserId(loginName);

      logger.info(
          "{} 对象(ID:{}) 被 {} 在 {} 修改",
          new Object[] {
            entity.getClass().getSimpleName(), entity.getUuid(), loginName, new Date()
          });
    }
  }
Ejemplo n.º 16
0
 public static HttpServletRequest getRequest() {
   ServletRequestAttributes attrs =
       (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
   return attrs.getRequest();
 }
Ejemplo n.º 17
0
 private String syncUrl() throws Exception {
   ServletRequestAttributes requestAttributes =
       (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
   HttpServletRequest request = requestAttributes.getRequest();
   return UrlBuilder.createSyncUrl(request, claName, repositoryId, pullRequestId);
 }
 /**
  * Получить сессию
  *
  * @return - сессия
  */
 private HttpSession getSession() {
   ServletRequestAttributes attr =
       (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
   return attr.getRequest().getSession(true); // true == allow create
 }
Ejemplo n.º 19
0
 /**
  * Get session
  *
  * @return
  */
 public HttpSession getSession() {
   ServletRequestAttributes attr =
       (ServletRequestAttributes) RequestContextHolder.currentRequestAttributes();
   HttpSession session = attr.getRequest().getSession();
   return session;
 }