org.jivesoftware.openfire.XMPPServer.createJID()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.2k)|赞(0)|评价(0)|浏览(81)

本文整理了Java中org.jivesoftware.openfire.XMPPServer.createJID()方法的一些代码示例,展示了XMPPServer.createJID()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。XMPPServer.createJID()方法的具体详情如下:
包路径:org.jivesoftware.openfire.XMPPServer
类名称:XMPPServer
方法名:createJID

XMPPServer.createJID介绍

[英]Creates an XMPPAddress local to this server.
[中]创建此服务器本地的XMPPAddress。

代码示例

代码示例来源:origin: igniterealtime/Openfire

/**
 * Sets the list of admin users based off of a list of usernames.  Clears list first.
 *
 * @param usernames List of usernames to set as admins.
 */
public void setAdminUsers(List<String> usernames) {
  if (adminList == null) {
    adminList = new ArrayList<>();
  }
  else {
    adminList.clear();
  }
  List<JID> admins = new ArrayList<>();
  for (String username : usernames) {
    admins.add(XMPPServer.getInstance().createJID(username, null));
  }
  adminList.addAll(admins);
  provider.setAdmins(admins);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Returns true if the user is an admin.
 *
 * @param username Username of user to check whether they are an admin or not.
 * @param allowAdminIfEmpty Allows the "admin" user to log in if the adminList is empty.
 * @return True or false if user is an admin.
 */
public boolean isUserAdmin(String username, boolean allowAdminIfEmpty) {
  if (adminList == null) {
    loadAdminList();
  }
  if (allowAdminIfEmpty && adminList.isEmpty()) {
    return "admin".equals(username);
  }
  JID userJID = XMPPServer.getInstance().createJID(username, null);
  return adminList.contains(userJID);
}

代码示例来源:origin: igniterealtime/Openfire

public PrivacyList(String username, String name, boolean isDefault, Element listElement) {
  this.userJID = XMPPServer.getInstance().createJID(username, null, true);
  this.name = name;
  this.isDefault = isDefault;
  // Set the new list items
  updateList(listElement);
}

代码示例来源:origin: igniterealtime/Openfire

private JID getUserJID() {
  return XMPPServer.getInstance().createJID(getUsername(), null, true);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Returns true if the provided username belongs to a user of the group.
 *
 * @param username the username to check.
 * @return true if the provided username belongs to a user of the group.
 */
public boolean isUser(String username) {
  if  (username != null) {
    return isUser(XMPPServer.getInstance().createJID(username, null, true));
  }
  else {
    return false;
  }
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public UserProvider getUserProvider( String username )
{
  // TODO add optional caching, to prevent retrieving the administrative users upon every invocation.
  final JID jid = XMPPServer.getInstance().createJID( username, null );
  final boolean isAdmin = AdminManager.getAdminProvider().getAdmins().contains( jid );
  if ( isAdmin )
  {
    return adminProvider;
  } else
  {
    return userProvider;
  }
}

代码示例来源:origin: igniterealtime/Openfire

public JID getValidJID(String username) {
  if (username != null && !username.isEmpty()) {
    try {
      if (username.contains("@")) {
        JID jid = new JID(username);
        if (userManager.isRegisteredUser(jid)) {
          return jid;
        }
      } else if (userManager.isRegisteredUser(username)) {
        return xmppServer.createJID(username, null);
      }
    } catch (IllegalArgumentException e) {
    }
  }
  // Return null if JID is invalid or user not registered
  return null;
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public AuthProvider getAuthProvider( String username )
{
  // TODO add optional caching, to prevent retrieving the administrative users upon every invocation.
  final JID jid = XMPPServer.getInstance().createJID( username, null );
  final boolean isAdmin = AdminManager.getAdminProvider().getAdmins().contains( jid );
  if ( isAdmin )
  {
    return adminProvider;
  } else
  {
    return userProvider;
  }
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Removes an account from the list of Admin accounts, based off username, which will be converted
 * to a JID.
 *
 * @param username Username of user to remove from admin list.
 */
public void removeAdminAccount(String username) {
  if (adminList == null) {
    loadAdminList();
  }
  JID userJID = XMPPServer.getInstance().createJID(username, null);
  if (!adminList.contains(userJID)) {
    return;
  }
  // Remove user from admin list cache.
  adminList.remove(userJID);
  // Store updated list of admins with provider.
  provider.setAdmins(adminList);
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Adds a new account to the list of Admin accounts, based off a username, which will be converted
 * into a JID.
 *
 * @param username Username of account to add to list of admins.
 */
public void addAdminAccount(String username) {
  if (adminList == null) {
    loadAdminList();
  }
  JID userJID = XMPPServer.getInstance().createJID(username, null);
  if (adminList.contains(userJID)) {
    // Already have them.
    return;
  }
  // Add new admin to cache.
  adminList.add(userJID);
  // Store updated list of admins with provider.
  provider.setAdmins(adminList);
}

代码示例来源:origin: igniterealtime/Openfire

private Collection<JID> getGroupMembers(String groupName) {
  Cache<String, ArrayList<JID>> groupMembershipCache = CacheFactory.createLocalCache(GROUP_MEMBERSHIP_CACHE_NAME);
  Collection<JID> members = groupMembershipCache.get(groupName);
  if (members != null) {
    return members;
  }
  
  try {
    List<String> users = manager.getGroupMembers(groupName);
    ArrayList<JID> results = new ArrayList<>();
    for (String username : users) {
      results.add(server.createJID(username, null));
    }
    
    groupMembershipCache.put(groupName, results);
    return results;
    
  } catch (RemoteException re) {
    LOG.error("Failure to get the members of crowd group:" + String.valueOf(groupName), re);
  }
  
  groupMembershipCache.put(groupName, new ArrayList<JID>());
  return Collections.emptyList();
}

代码示例来源:origin: igniterealtime/Openfire

/**
 * Returns an iterator for all groups that the User is a member of.
 *
 * @param user the user.
 * @return all groups the user belongs to.
 */
public Collection<Group> getGroups(User user) {
  return getGroups(XMPPServer.getInstance().createJID(user.getUsername(), null, true));
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void userDeleting(User user, Map<String, Object> params) {
  // Delete any affiliation of the user to any room of any MUC service
  MUCPersistenceManager
      .removeAffiliationFromDB(XMPPServer.getInstance().createJID(user.getUsername(), null, true));
  // TODO Delete any user information from the rooms loaded into memory
}

代码示例来源:origin: igniterealtime/Openfire

private void broadcast(org.xmpp.packet.Roster roster) {
  JID recipient = XMPPServer.getInstance().createJID(username, null, true);
  roster.setTo(recipient);
  // When roster versioning is enabled, the server MUST include 
  // the updated roster version with each roster push.
  if (RosterManager.isRosterVersioningEnabled()) {
    roster.getChildElement().addAttribute("ver", String.valueOf( roster.hashCode() ) );
  }
  SessionManager.getInstance().userBroadcast(username, roster);
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public boolean hasInfo(String name, String node, JID senderJID) {
  if (node == null) return true;
  String recipientJID = XMPPServer.getInstance().createJID(name, null, true).toBareJID();
  PEPService pepService = pepServiceManager.getPEPService(recipientJID);
  return pepService.getNode(node) != null;
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void contactDeleted(Roster roster, RosterItem item) {
  JID rosterOwner = XMPPServer.getInstance().createJID(roster.getUsername(), null);
  JID deletedContact = item.getJid();
  cancelSubscriptionToPEPService(deletedContact, rosterOwner);
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void userDeleting(User user, Map<String, Object> params) {
  // Delete this user's association in entityCapabilitiesUserMap.
  JID jid = XMPPServer.getInstance().createJID(user.getUsername(), null, true);
  String verHashOfUser = entityCapabilitiesUserMap.remove(jid);
  // If there are no other references to the deleted user's 'ver' hash,
  // it is safe to remove that 'ver' hash's associated entity
  // capabilities from the entityCapabilitiesMap cache.
  for (String verHash : entityCapabilitiesUserMap.values()) {
    if (verHash.equals(verHashOfUser)) {
      // A different user is making use of the deleted user's same
      // 'ver' hash, so let's not remove the associated entity
      // capabilities from the entityCapabilitiesMap.
      return;
    }
  }
  entityCapabilitiesMap.remove(verHashOfUser);
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public void userDeleting(User user, Map<String, Object> params) {
  final JID bareJID = XMPPServer.getInstance().createJID(user.getUsername(), null);
  final PEPService pepService = pepServiceManager.getPEPService(bareJID.toString());
  if (pepService == null) {
    return;
  }
  // Remove the user's PEP service, finally.
  pepServiceManager.remove(bareJID);
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public DataForm getExtendedInfo(String name, String node, JID senderJID) {
  String recipientJID = XMPPServer.getInstance().createJID(name, null, true).toBareJID();
  PEPService pepService = pepServiceManager.getPEPService(recipientJID);
  if (node != null) {
    // Answer the extended info of a given node
    Node pubNode = pepService.getNode(node);
    // Get the metadata data form
    return pubNode.getMetadataForm();
  }
  return null;
}

代码示例来源:origin: igniterealtime/Openfire

@Override
public Iterator<Element> getIdentities(String name, String node, JID senderJID) {
  String recipientJID = XMPPServer.getInstance().createJID(name, null, true).toBareJID();
  PEPService pepService = pepServiceManager.getPEPService(recipientJID);
  if (node != null && pepService != null) {
    Node pubNode = pepService.getNode(node);
    if (pubNode == null) return null;
    // Answer the identity of a given node
    Element identity = DocumentHelper.createElement("identity");
    identity.addAttribute("category", "pubsub");
    identity.addAttribute("type", pubNode.isCollectionNode() ? "collection" : "leaf");
    List<Element> identities = new LinkedList<>();
    identities.add(identity);
    return identities.iterator();
  } else if (node != null) {
    return null;
  } else {
    PubSubModule pubsub = XMPPServer.getInstance().getPubSubModule();
    return pubsub.getIdentities(null, null, senderJID);
  }
}

相关文章