Example #1
0
 public List<Authority> find(Role role) {
   Connection conn = null;
   List<Authority> auths = null;
   try {
     conn = ConnectionUtils.getConnection();
     auths = authDAO.find(conn, role);
   } catch (SQLException e) {
     logger.error(e.getMessage());
   } finally {
     DbUtils.closeQuietly(conn);
   }
   return auths;
 }
Example #2
0
 public Authority get(String value) {
   Connection conn = null;
   Authority auth = null;
   try {
     conn = ConnectionUtils.getConnection();
     auth = authDAO.get(conn, value);
   } catch (SQLException e) {
     logger.error(e.getMessage());
   } finally {
     DbUtils.closeQuietly(conn);
   }
   return auth;
 }
Example #3
0
 /**
  * {@inheritDoc}
  *
  * <p>此操作会清空 Cache 中 authorities 对应的 value,下次请求时装载。
  *
  * @see #getAll()
  */
 public void delete(Authority auth) throws JibuException {
   Connection conn = null;
   try {
     conn = ConnectionUtils.getConnection();
     authDAO.delete(conn, auth);
     DbUtils.commitAndClose(conn);
     Cache cache = CacheUtils.getAuthCache();
     cache.remove("authorities");
   } catch (SQLException e) {
     DbUtils.rollbackAndCloseQuietly(conn);
     throw new JibuException(e.getMessage());
   }
 }
Example #4
0
 public List<Authority> find(Authority auth) {
   if (null == auth) return this.getAll();
   Connection conn = null;
   List<Authority> auths = null;
   try {
     conn = ConnectionUtils.getConnection();
     auths = authDAO.find(conn, auth);
   } catch (SQLException e) {
     logger.error(e.getMessage());
   } finally {
     DbUtils.closeQuietly(conn);
   }
   return auths;
 }
Example #5
0
  private List<String> findRoleNamesByUsername(String username) {
    Connection conn = null;
    Cache cache = CacheUtils.getUserCache();
    List<String> names = (List<String>) cache.get(username);
    if (null != names) return names;

    try {
      conn = ConnectionUtils.getConnection();
      names = roleDAO.findByUsername(conn, username);
      cache.put(username, names);
    } catch (SQLException e) {
      logger.error(e.getMessage());
    } finally {
      DbUtils.closeQuietly(conn);
    }
    return names;
  }
Example #6
0
  /**
   * {@inheritDoc}
   *
   * <p>如果 Cache 中的 authorities 对应的 value 为空,从 DAO 得到最新的 value 并装入 Cache。
   */
  public List<Authority> getAll() {
    Connection conn = null;
    List<Authority> auths = null;

    Cache cache = CacheUtils.getAuthCache();
    auths = (List<Authority>) cache.get("authorities");
    if (null != auths) return auths;
    try {
      conn = ConnectionUtils.getConnection();
      auths = authDAO.getAll(conn);
      cache.put("authorities", auths);
    } catch (SQLException e) {
      logger.error(e.getMessage());
    } finally {
      DbUtils.closeQuietly(conn);
    }
    return auths;
  }
Example #7
0
 private List<String> findRoleNamesByValue(String value) {
   Connection conn = null;
   Cache cache = CacheUtils.getAuthCache();
   List<String> names = (List<String>) cache.get(value);
   if (null != names) return names;
   try {
     conn = ConnectionUtils.getConnection();
     Authority auth = authDAO.get(conn, value);
     if (null != auth) {
       names = roleDAO.findByAuthid(conn, auth.getId());
       cache.put(value, names);
     }
   } catch (SQLException e) {
     logger.error(e.getMessage());
   } finally {
     DbUtils.closeQuietly(conn);
   }
   return names;
 }