Package org.apache.shiro.session

Examples of org.apache.shiro.session.Session


  @Override
  public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException {
    String result = null;
    Subject subject = getSubject();
    Session session = getSubject().getSession();
    String attr = getAttr(params);
    String value = null;
    if (subject != null && session != null && attr != null) {
      if (log.isDebugEnabled()) {
        log.debug("Attr is exsit.");
      }
      if (session.getAttribute(attr) != null) {
        value = String.valueOf(session.getAttribute(attr));
        if (value.equalsIgnoreCase("UnknownUserException")) {
          result = "账户验证失败或已被禁用!";
        } else if (value.equalsIgnoreCase("IncorrectCredentialsException")) {
          result = "账户验证失败或已被禁用!";
        } else if (value.equalsIgnoreCase("IncorrectCaptchaException")) {
View Full Code Here


  static final Logger log = Logger.getLogger("LoginUsernameTag");

  @Override
  public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException {
    String result = null;
    Session session = getSubject().getSession();
    if (session != null && session.getAttribute(AppConstants.LOGIN_USER_NAME) != null) {
      if (log.isDebugEnabled()) {
        log.debug("tempUser is exsit.");
      }

      String username = session.getAttribute(AppConstants.LOGIN_USER_NAME).toString();
      if (username != null) {
        result = username;
      }
    } else {
      if (log.isDebugEnabled()) {
View Full Code Here

      //rememberMe自动登录
      Subject subject = SubjectUtils.me().getSubject();
      if (!subject.isAuthenticated() && subject.isRemembered()) {
        Object principal = subject.getPrincipal();
        Session session = SubjectUtils.me().getSession();
        if (null != principal) {
          if (session.getAttribute(AppConstants.CURRENT_USER) == null) {
            session.setAttribute(AppConstants.CURRENT_USER, (User) principal);
          }
        } else {
          SubjectUtils.me().getSubject().logout();
        }
      }
View Full Code Here

  }

  @Override
  public void render(Environment env, Map params, TemplateDirectiveBody body) throws IOException, TemplateException {
    Subject subject = getSubject();
    Session session = getSubject().getSession();
    String attr = getAttr(params);
    if (attr != null && subject != null && session != null && session.getAttribute(attr) != null) {
      if (log.isDebugEnabled()) {
        log.debug("Attr is exsit.");
      }

      renderBody(env, body);
View Full Code Here

    String captchaCode = captcha.getChallenge();
    if (logger.isDebugEnabled()) {
      logger.debug("captcha:" + captchaCode);
    }
    //System.out.println(validationCode);
    Session session = SecurityUtils.getSubject().getSession();
    session.setAttribute(captchaName, EncriptionUtils.encrypt(captchaCode));
    session.setAttribute(captchaName + "_time", new Date().getTime());
//    CookieUtils.addCookie(request, response, AppConstants.CAPTCHA_NAME, EncriptionUtils.encrypt(captchaCode), -1);
    // 取得验证码图片并输出
    BufferedImage bufferedImage = captcha.getImage();

    try {
View Full Code Here

  protected void setFailureAttribute(ServletRequest request, ServletResponse response, AuthenticationException ae) {
    String className = ae.getClass().getSimpleName();
    if (ThreadLocalUtil.isJson()) {
      request.setAttribute(getFailureKeyAttribute(), className);
    } else {
      Session session = getSubject(request, response).getSession();
      session.setAttribute(getFailureKeyAttribute(), className);
      session.setAttribute(AppConstants.LOGIN_USER_NAME, getUsername(request));
    }
  }
View Full Code Here

  protected void clearFailureAttribute(ServletRequest request, ServletResponse response) {
    if (ThreadLocalUtil.isJson()) {
      request.setAttribute("user", SubjectUtils.me().getUser());
      request.removeAttribute(getFailureKeyAttribute());
    } else {
      Session session = getSubject(request, response).getSession();
      session.removeAttribute(getFailureKeyAttribute());
      session.removeAttribute(AppConstants.LOGIN_USER_NAME);
    }
  }
View Full Code Here

    }
  }

  @Deprecated
  protected void setUserAttribute(ServletRequest request, ServletResponse response) {
    Session session = getSubject(request, response).getSession();
    session.setAttribute(AppConstants.CURRENT_USER, session.getAttribute(AppConstants.TEMP_USER));
  }
View Full Code Here

    return SecurityUtils.getSubject();
  }

  public Session getSession() {
    Subject subject = SecurityUtils.getSubject();
    Session session = subject.getSession();
    if (session == null) {
      throw new UnknownSessionException("Unable found required Session");
    } else {
      return session;
    }
View Full Code Here

   *
   * @param <T> User
   * @return T User
   */
  public <T extends User> T getUser() {
    Session session = getSession();
    Object user = getSubject().getPrincipals().getPrimaryPrincipal();
    if (ValidateUtils.me().isNullOrEmpty(user))
      return null;
    else {
      T u = (T) user;
View Full Code Here

TOP

Related Classes of org.apache.shiro.session.Session

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.