use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class BroadcastPlugin method processIQ.
private void processIQ(IQ iq, boolean targetAll, Group group, boolean canProceed) {
IQ reply = IQ.createResultIQ(iq);
Element childElement = iq.getChildElement();
String namespace = childElement.getNamespaceURI();
Element childElementCopy = iq.getChildElement().createCopy();
reply.setChildElement(childElementCopy);
if ("http://jabber.org/protocol/disco#info".equals(namespace)) {
if (iq.getTo().getNode() == null) {
// Return service identity and features
Element identity = childElementCopy.addElement("identity");
identity.addAttribute("category", "component");
identity.addAttribute("type", "generic");
identity.addAttribute("name", "Broadcast service");
childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#items");
} else {
if (targetAll) {
// Return identity and features of the "all" group
Element identity = childElementCopy.addElement("identity");
identity.addAttribute("category", "component");
identity.addAttribute("type", "generic");
identity.addAttribute("name", "Broadcast all connected users");
childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
} else if (group != null && canProceed) {
// Return identity and features of the "all" group
Element identity = childElementCopy.addElement("identity");
identity.addAttribute("category", "component");
identity.addAttribute("type", "generic");
identity.addAttribute("name", "Broadcast " + group.getName());
childElementCopy.addElement("feature").addAttribute("var", "http://jabber.org/protocol/disco#info");
} else {
// Group not found or not allowed to use that group so
// answer item_not_found error
reply.setError(PacketError.Condition.item_not_found);
}
}
} else if ("http://jabber.org/protocol/disco#items".equals(namespace)) {
if (iq.getTo().getNode() == null) {
// Return the list of groups hosted by the service that can be used by the user
Collection<Group> groups;
JID address = new JID(iq.getFrom().toBareJID());
if (allowedUsers.contains(address)) {
groups = groupManager.getGroups();
} else {
groups = groupManager.getGroups(iq.getFrom());
}
for (Group userGroup : groups) {
try {
JID groupJID = new JID(userGroup.getName() + "@" + serviceName + "." + componentManager.getServerName());
childElementCopy.addElement("item").addAttribute("jid", groupJID.toString());
} catch (Exception e) {
// Group name is not valid to be used as a JID
}
}
if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
// Add the "all" group to the list
childElementCopy.addElement("item").addAttribute("jid", "all@" + serviceName + "." + componentManager.getServerName());
}
}
} else {
// Answer an error since the server can't handle the requested namespace
reply.setError(PacketError.Condition.service_unavailable);
}
try {
componentManager.sendPacket(this, reply);
} catch (Exception e) {
Log.error(e.getMessage(), e);
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class BroadcastPlugin method processPacket.
public void processPacket(Packet packet) {
boolean canProceed = false;
Group group = null;
String toNode = packet.getTo().getNode();
// Check if user is allowed to send packet to this service[+group]
boolean targetAll = "all".equals(toNode);
if (targetAll) {
// See if the user is allowed to send the packet.
JID address = new JID(packet.getFrom().toBareJID());
if (allowedUsers.isEmpty() || allowedUsers.contains(address)) {
canProceed = true;
}
} else {
try {
if (toNode != null) {
group = groupManager.getGroup(toNode);
boolean isGroupUser = group.isUser(packet.getFrom()) || group.isUser(new JID(packet.getFrom().toBareJID()));
if (disableGroupPermissions || (groupMembersAllowed && isGroupUser) || allowedUsers.contains(new JID(packet.getFrom().toBareJID()))) {
canProceed = true;
}
}
} catch (GroupNotFoundException e) {
// Ignore.
}
}
if (packet instanceof Message) {
// Respond to incoming messages
Message message = (Message) packet;
processMessage(message, targetAll, group, canProceed);
} else if (packet instanceof Presence) {
// Respond to presence subscription request or presence probe
Presence presence = (Presence) packet;
processPresence(canProceed, presence);
} else if (packet instanceof IQ) {
// Handle disco packets
IQ iq = (IQ) packet;
// Ignore IQs of type ERROR or RESULT
if (IQ.Type.error == iq.getType() || IQ.Type.result == iq.getType()) {
return;
}
processIQ(iq, targetAll, group, canProceed);
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class AgentManager method removeAgentIfNecessary.
/**
* Removes an agent from the system if they no longer belong to any Workgroups.
*
* @param agent the agent to remove.
*/
public void removeAgentIfNecessary(Agent agent) {
// Go through all workgroups to see if this user is in RequestQueues
WorkgroupManager workgroupManager = WorkgroupManager.getInstance();
for (Workgroup workgroup : workgroupManager.getWorkgroups()) {
for (RequestQueue queue : workgroup.getRequestQueues()) {
if (queue.getMembers().contains(agent)) {
return;
}
for (Group group : queue.getGroups()) {
if (group.isUser(agent.getAgentJID())) {
return;
}
}
}
}
try {
// Send Presence to Workgroup that this user is no longer available.
AgentSession session = agent.getAgentSession();
if (session != null) {
for (Workgroup workgroup : session.getWorkgroups()) {
session.depart(workgroup);
}
}
// If we get here, then remove from agent.
deleteAgent(agent.getAgentJID());
} catch (IllegalArgumentException e) {
Log.error(e.getMessage(), e);
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class UserServicePlugin method updateUser.
public void updateUser(String username, String password, String name, String email, String groupNames) throws UserNotFoundException, GroupAlreadyExistsException {
User user = getUser(username);
if (password != null)
user.setPassword(password);
if (name != null)
user.setName(name);
if (email != null)
user.setEmail(email);
if (groupNames != null) {
Collection<Group> newGroups = new ArrayList<Group>();
StringTokenizer tkn = new StringTokenizer(groupNames, ",");
while (tkn.hasMoreTokens()) {
String groupName = tkn.nextToken();
Group group = null;
try {
group = GroupManager.getInstance().getGroup(groupName);
} catch (GroupNotFoundException e) {
// Create this group ;
group = GroupManager.getInstance().createGroup(groupName);
group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
group.getProperties().put("sharedRoster.displayName", groupName);
group.getProperties().put("sharedRoster.groupList", "");
}
newGroups.add(group);
}
Collection<Group> existingGroups = GroupManager.getInstance().getGroups(user);
// Get the list of groups to add to the user
Collection<Group> groupsToAdd = new ArrayList<Group>(newGroups);
groupsToAdd.removeAll(existingGroups);
// Get the list of groups to remove from the user
Collection<Group> groupsToDelete = new ArrayList<Group>(existingGroups);
groupsToDelete.removeAll(newGroups);
// Add the user to the new groups
for (Group group : groupsToAdd) {
group.getMembers().add(server.createJID(username, null));
}
// Remove the user from the old groups
for (Group group : groupsToDelete) {
group.getMembers().remove(server.createJID(username, null));
}
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class UserServicePluginNG method getUserGroups.
/**
* Gets the user groups.
*
* @param username
* the username
* @return the user groups
* @throws ServiceException
* the service exception
*/
public List<String> getUserGroups(String username) throws ServiceException {
User user = getAndCheckUser(username);
Collection<Group> groups = GroupManager.getInstance().getGroups(user);
List<String> groupNames = new ArrayList<String>();
for (Group group : groups) {
groupNames.add(group.getName());
}
return groupNames;
}
Aggregations