/**
  * Sets the default Privacy list used for the session's user. This list is processed if there is
  * no active list set for the session.
  *
  * @param defaultList the default Privacy list used for the session's user.
  */
 public void setDefaultList(PrivacyList defaultList) {
   // Do nothing if nothing has changed
   if ((this.defaultList == null && defaultList == null)
       || (defaultList != null && defaultList.getName().equals(this.defaultList))) {
     return;
   }
   this.defaultList = defaultList != null ? defaultList.getName() : null;
   if (ClusterManager.isClusteringStarted()) {
     // Track information about the session and share it with other cluster nodes
     Cache<String, ClientSessionInfo> cache = SessionManager.getInstance().getSessionInfoCache();
     cache.put(getAddress().toString(), new ClientSessionInfo(this));
   }
 }
 /**
  * Returns true if the specified packet must not be blocked based on the active or default privacy
  * list rules. The active list will be tried first. If none was found then the default list is
  * going to be used. If no default list was defined for this user then allow the packet to flow.
  *
  * @param packet the packet to analyze if it must be blocked.
  * @return true if the specified packet must be blocked.
  */
 @Override
 public boolean canProcess(Packet packet) {
   PrivacyList list = getActiveList();
   if (list != null) {
     // If a privacy list is active then make sure that the packet is not blocked
     return !list.shouldBlockPacket(packet);
   } else {
     list = getDefaultList();
     // There is no active list so check if there exists a default list and make
     // sure that the packet is not blocked
     return list == null || !list.shouldBlockPacket(packet);
   }
 }
Пример #3
0
 /**
  * Sets a given privacy list as the new default list of the user.
  *
  * @param username the name of the user that is setting a new default list.
  * @param newDefault the new default privacy list.
  * @param oldDefault the previous privacy list or <tt>null</tt> if no default list existed.
  */
 public void changeDefaultList(String username, PrivacyList newDefault, PrivacyList oldDefault) {
   // TODO Analyze concurrency issues when other resource may log in while doing this change
   if (oldDefault != null) {
     // Update old default list to become just another list
     oldDefault.setDefaultList(false);
     provider.updatePrivacyList(username, oldDefault);
   }
   // Update new list to become the default
   newDefault.setDefaultList(true);
   // Set new default list in the cache
   listsCache.put(getDefaultCacheKey(username), newDefault);
   // Update both lists in the database
   provider.updatePrivacyList(username, newDefault);
 }
Пример #4
0
 /**
  * Deletes an existing privacy list of a user. If the privacy list being deleted was the default
  * list then the user will end up with no default list. Therefore, the user will have to set a new
  * default list.
  *
  * @param username the username of the list owner.
  * @param listName the name of the list being deleted.
  */
 public void deletePrivacyList(String username, String listName) {
   // Trigger event that a privacy list is being deleted
   for (PrivacyListEventListener listener : listeners) {
     listener.privacyListDeleting(listName);
   }
   // Remove the list from the cache
   listsCache.remove(getCacheKey(username, listName));
   // Delete the privacy list from the DB
   provider.deletePrivacyList(username, listName);
   // Check if deleted list was the default list
   PrivacyList defaultList = listsCache.get(getDefaultCacheKey(username));
   if (defaultList != null && listName.equals(defaultList.getName())) {
     listsCache.remove(getDefaultCacheKey(username));
   }
 }
 /**
  * Sets the Privacy list that overrides the default privacy list. This list affects only this
  * session and only for the duration of the session.
  *
  * @param activeList the Privacy list that overrides the default privacy list.
  */
 public void setActiveList(PrivacyList activeList) {
   this.activeList = activeList != null ? activeList.getName() : null;
   if (ClusterManager.isClusteringStarted()) {
     // Track information about the session and share it with other cluster nodes
     Cache<String, ClientSessionInfo> cache = SessionManager.getInstance().getSessionInfoCache();
     cache.put(getAddress().toString(), new ClientSessionInfo(this));
   }
 }
Пример #6
0
 /**
  * Updated the existing privacy list in the database.
  *
  * @param username the username of the user that updated a privacy list.
  * @param list the PrivacyList to update in the database.
  */
 public void updatePrivacyList(String username, PrivacyList list) {
   Connection con = null;
   PreparedStatement pstmt = null;
   try {
     con = DbConnectionManager.getConnection();
     pstmt = con.prepareStatement(UPDATE_PRIVACY_LIST);
     pstmt.setInt(1, (list.isDefault() ? 1 : 0));
     pstmt.setString(2, list.asElement().asXML());
     pstmt.setString(3, username);
     pstmt.setString(4, list.getName());
     pstmt.executeUpdate();
   } catch (Exception e) {
     Log.error("Error updating privacy list: " + list.getName() + " of username: " + username, e);
   } finally {
     DbConnectionManager.closeConnection(pstmt, con);
   }
 }
Пример #7
0
 /**
  * Creates and saves the new privacy list to the database.
  *
  * @param username the username of the user that created a new privacy list.
  * @param list the PrivacyList to save.
  */
 public void createPrivacyList(String username, PrivacyList list) {
   Connection con = null;
   PreparedStatement pstmt = null;
   try {
     con = DbConnectionManager.getConnection();
     pstmt = con.prepareStatement(INSERT_PRIVACY_LIST);
     pstmt.setString(1, username);
     pstmt.setString(2, list.getName());
     pstmt.setInt(3, (list.isDefault() ? 1 : 0));
     pstmt.setString(4, list.asElement().asXML());
     pstmt.executeUpdate();
   } catch (Exception e) {
     Log.error("Error adding privacy list: " + list.getName() + " of username: "******"0", which is the case we care about.
   privacyListCount.set(-1);
 }