use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class IQOwnerHandler method refreshConfigurationFormValues.
private void refreshConfigurationFormValues() {
synchronized (room) {
FormField field = configurationForm.getField("muc#roomconfig_roomname");
field.clearValues();
field.addValue(room.getNaturalLanguageName());
field = configurationForm.getField("muc#roomconfig_roomdesc");
field.clearValues();
field.addValue(room.getDescription());
field = configurationForm.getField("muc#roomconfig_changesubject");
field.clearValues();
field.addValue((room.canOccupantsChangeSubject() ? "1" : "0"));
field = configurationForm.getField("muc#roomconfig_maxusers");
field.clearValues();
field.addValue(Integer.toString(room.getMaxUsers()));
field = configurationForm.getField("muc#roomconfig_presencebroadcast");
field.clearValues();
for (MUCRole.Role roleToBroadcast : room.getRolesToBroadcastPresence()) {
field.addValue(roleToBroadcast.toString());
}
field = configurationForm.getField("muc#roomconfig_publicroom");
field.clearValues();
field.addValue((room.isPublicRoom() ? "1" : "0"));
field = configurationForm.getField("muc#roomconfig_persistentroom");
field.clearValues();
field.addValue((room.isPersistent() ? "1" : "0"));
field = configurationForm.getField("muc#roomconfig_moderatedroom");
field.clearValues();
field.addValue((room.isModerated() ? "1" : "0"));
field = configurationForm.getField("muc#roomconfig_membersonly");
field.clearValues();
field.addValue((room.isMembersOnly() ? "1" : "0"));
field = configurationForm.getField("muc#roomconfig_allowinvites");
field.clearValues();
field.addValue((room.canOccupantsInvite() ? "1" : "0"));
field = configurationForm.getField("muc#roomconfig_passwordprotectedroom");
field.clearValues();
field.addValue((room.isPasswordProtected() ? "1" : "0"));
field = configurationForm.getField("muc#roomconfig_roomsecret");
field.clearValues();
field.addValue(room.getPassword());
field = configurationForm.getField("muc#roomconfig_whois");
field.clearValues();
field.addValue((room.canAnyoneDiscoverJID() ? "anyone" : "moderators"));
field = configurationForm.getField("muc#roomconfig_allowpm");
field.clearValues();
field.addValue((room.canSendPrivateMessage()));
field = configurationForm.getField("muc#roomconfig_enablelogging");
field.clearValues();
field.addValue((room.isLogEnabled() ? "1" : "0"));
field = configurationForm.getField("x-muc#roomconfig_reservednick");
field.clearValues();
field.addValue((room.isLoginRestrictedToNickname() ? "1" : "0"));
field = configurationForm.getField("x-muc#roomconfig_canchangenick");
field.clearValues();
field.addValue((room.canChangeNickname() ? "1" : "0"));
field = configurationForm.getField("x-muc#roomconfig_registration");
field.clearValues();
field.addValue((room.isRegistrationEnabled() ? "1" : "0"));
field = configurationForm.getField("muc#roomconfig_roomadmins");
field.clearValues();
for (JID jid : room.getAdmins()) {
if (GroupJID.isGroup(jid)) {
try {
// add each group member to the result (clients don't understand groups)
Group group = GroupManager.getInstance().getGroup(jid);
for (JID groupMember : group.getAll()) {
field.addValue(groupMember);
}
} catch (GroupNotFoundException gnfe) {
Log.warn("Invalid group JID in the member list: " + jid);
}
} else {
field.addValue(jid.toString());
}
}
field = configurationForm.getField("muc#roomconfig_roomowners");
field.clearValues();
for (JID jid : room.getOwners()) {
if (GroupJID.isGroup(jid)) {
try {
// add each group member to the result (clients don't understand groups)
Group group = GroupManager.getInstance().getGroup(jid);
for (JID groupMember : group.getAll()) {
field.addValue(groupMember);
}
} catch (GroupNotFoundException gnfe) {
Log.warn("Invalid group JID in the member list: " + jid);
}
} else {
field.addValue(jid.toString());
}
}
// Remove the old element
probeResult.remove(probeResult.element(QName.get("x", "jabber:x:data")));
// Add the new representation of configurationForm as an element
probeResult.add(configurationForm.getElement());
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class IQAdminHandler method handleItemsElement.
/**
* Handles packets that includes item elements. Depending on the item's attributes the
* interpretation of the request may differ. For example, an item that only contains the
* "affiliation" attribute is requesting the list of participants or members. Whilst if the item
* contains the affiliation together with a jid means that the client is changing the
* affiliation of the requested jid.
*
* @param senderRole the role of the user that sent the request packet.
* @param itemsList the list of items sent by the client.
* @param reply the iq packet that will be sent back as a reply to the client's request.
* @throws ForbiddenException If the user is not allowed to perform his request.
* @throws ConflictException If the desired room nickname is already reserved for the room or
* if the room was going to lose all of its owners.
* @throws NotAllowedException Thrown if trying to ban an owner or an administrator.
* @throws CannotBeInvitedException If the user being invited as a result of being added to a members-only room still does not have permission
*/
private void handleItemsElement(MUCRole senderRole, List<Element> itemsList, IQ reply) throws ForbiddenException, ConflictException, NotAllowedException, CannotBeInvitedException {
String affiliation;
String roleAttribute;
boolean hasJID = itemsList.get(0).attributeValue("jid") != null;
boolean hasNick = itemsList.get(0).attributeValue("nick") != null;
// Check if the client is requesting or changing the list of moderators/members/etc.
if (!hasJID && !hasNick) {
// The client is requesting the list of moderators/members/participants/outcasts
// Create the result that will hold an item for each
// moderator/member/participant/outcast
Element result = reply.setChildElement("query", "http://jabber.org/protocol/muc#admin");
for (final Element item : itemsList) {
affiliation = item.attributeValue("affiliation");
roleAttribute = item.attributeValue("role");
Element metaData;
if ("outcast".equals(affiliation)) {
// The client is requesting the list of outcasts
if (MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (JID jid : room.getOutcasts()) {
if (GroupJID.isGroup(jid)) {
try {
// add each group member to the result (clients don't understand groups)
Group group = GroupManager.getInstance().getGroup(jid);
for (JID groupMember : group.getAll()) {
metaData = addAffiliationToResult(affiliation, result, groupMember);
}
} catch (GroupNotFoundException gnfe) {
logger.warn("Invalid group JID in the outcast list: " + jid);
}
} else {
metaData = addAffiliationToResult(affiliation, result, jid);
}
}
} else if ("member".equals(affiliation)) {
// In a members-only room members can get the list of members
if (!room.isMembersOnly() && MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (JID jid : room.getMembers()) {
if (GroupJID.isGroup(jid)) {
try {
// add each group member to the result (clients don't understand groups)
Group group = GroupManager.getInstance().getGroup(jid);
for (JID groupMember : group.getAll()) {
metaData = addAffiliationToResult(affiliation, result, groupMember);
}
} catch (GroupNotFoundException gnfe) {
logger.warn("Invalid group JID in the member list: " + jid);
}
} else {
metaData = addAffiliationToResult(affiliation, result, jid);
}
}
} else if ("moderator".equals(roleAttribute)) {
// The client is requesting the list of moderators
if (MUCRole.Affiliation.admin != senderRole.getAffiliation() && MUCRole.Affiliation.owner != senderRole.getAffiliation()) {
throw new ForbiddenException();
}
for (MUCRole role : room.getModerators()) {
metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin");
metaData.addAttribute("role", "moderator");
metaData.addAttribute("jid", role.getUserAddress().toString());
metaData.addAttribute("nick", role.getNickname());
metaData.addAttribute("affiliation", role.getAffiliation().toString());
}
} else if ("participant".equals(roleAttribute)) {
// The client is requesting the list of participants
if (MUCRole.Role.moderator != senderRole.getRole()) {
throw new ForbiddenException();
}
for (MUCRole role : room.getParticipants()) {
metaData = result.addElement("item", "http://jabber.org/protocol/muc#admin");
metaData.addAttribute("role", "participant");
metaData.addAttribute("jid", role.getUserAddress().toString());
metaData.addAttribute("nick", role.getNickname());
metaData.addAttribute("affiliation", role.getAffiliation().toString());
}
} else if ("owner".equals(affiliation)) {
// The client is requesting the list of owners
for (JID jid : room.getOwners()) {
if (GroupJID.isGroup(jid)) {
try {
// add each group member to the result (clients don't understand groups)
Group group = GroupManager.getInstance().getGroup(jid);
for (JID groupMember : group.getAll()) {
metaData = addAffiliationToResult(affiliation, result, groupMember);
}
} catch (GroupNotFoundException gnfe) {
logger.warn("Invalid group JID in the owner list: " + jid);
}
} else {
metaData = addAffiliationToResult(affiliation, result, jid);
}
}
} else if ("admin".equals(affiliation)) {
// The client is requesting the list of admins
for (JID jid : room.getAdmins()) {
if (GroupJID.isGroup(jid)) {
try {
// add each group member to the result (clients don't understand groups)
Group group = GroupManager.getInstance().getGroup(jid);
for (JID groupMember : group.getAll()) {
metaData = addAffiliationToResult(affiliation, result, groupMember);
}
} catch (GroupNotFoundException gnfe) {
logger.warn("Invalid group JID in the admin list: " + jid);
}
} else {
metaData = addAffiliationToResult(affiliation, result, jid);
}
}
} else {
reply.setError(PacketError.Condition.bad_request);
}
}
} else {
// The client is modifying the list of moderators/members/participants/outcasts
String nick;
String target;
boolean hasAffiliation;
// Keep a registry of the updated presences
List<Presence> presences = new ArrayList<>(itemsList.size());
// Collect the new affiliations or roles for the specified jids
for (final Element item : itemsList) {
try {
affiliation = item.attributeValue("affiliation");
hasAffiliation = affiliation != null;
target = (hasAffiliation ? affiliation : item.attributeValue("role"));
List<JID> jids = new ArrayList<>();
// jid could be of the form "full JID" or "bare JID" depending if we are
// going to change a role or an affiliation
nick = item.attributeValue("nick");
if (hasJID) {
// could be a group JID
jids.add(GroupJID.fromString(item.attributeValue("jid")));
} else {
// Get the JID based on the requested nick
for (MUCRole role : room.getOccupantsByNickname(nick)) {
if (!jids.contains(role.getUserAddress())) {
jids.add(role.getUserAddress());
}
}
}
for (JID jid : jids) {
switch(target) {
case "moderator":
// Add the user as a moderator of the room based on the full JID
presences.add(room.addModerator(jid, senderRole));
break;
case "owner":
presences.addAll(room.addOwner(jid, senderRole));
break;
case "admin":
presences.addAll(room.addAdmin(jid, senderRole));
break;
case "participant":
// Add the user as a participant of the room based on the full JID
presences.add(room.addParticipant(jid, item.elementTextTrim("reason"), senderRole));
break;
case "visitor":
// Add the user as a visitor of the room based on the full JID
presences.add(room.addVisitor(jid, senderRole));
break;
case "member":
// Add the user as a member of the room based on the bare JID
boolean hadAffiliation = room.getAffiliation(jid) != MUCRole.Affiliation.none;
presences.addAll(room.addMember(jid, nick, senderRole));
// are not disabled system-wide xmpp.muc.skipInvite
if (!skipInvite && !hadAffiliation && room.isMembersOnly()) {
List<JID> invitees = new ArrayList<>();
if (GroupJID.isGroup(jid)) {
try {
Group group = GroupManager.getInstance().getGroup(jid);
invitees.addAll(group.getAll());
} catch (GroupNotFoundException gnfe) {
logger.error("Failed to send invitations for group members", gnfe);
}
} else {
invitees.add(jid);
}
for (JID invitee : invitees) {
room.sendInvitation(invitee, null, senderRole, null);
}
}
break;
case "outcast":
// Add the user as an outcast of the room based on the bare JID
presences.addAll(room.addOutcast(jid, item.elementTextTrim("reason"), senderRole));
break;
case "none":
if (hasAffiliation) {
// Set that this jid has a NONE affiliation based on the bare JID
presences.addAll(room.addNone(jid, senderRole));
} else {
// Kick the user from the room
if (MUCRole.Role.moderator != senderRole.getRole()) {
throw new ForbiddenException();
}
presences.add(room.kickOccupant(jid, senderRole.getUserAddress(), senderRole.getNickname(), item.elementTextTrim("reason")));
}
break;
default:
reply.setError(PacketError.Condition.bad_request);
break;
}
}
} catch (UserNotFoundException e) {
// Do nothing
}
}
// Send the updated presences to the room occupants
for (Presence presence : presences) {
room.send(presence, room.getRole());
}
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class RayoComponent method routeIncomingSIP.
public boolean routeIncomingSIP(CallParticipant cp) {
boolean canRoute = false;
Group group = null;
JID foundUser = findUser(cp.getToPhoneNumber());
if (foundUser != null)
canRoute = true;
else {
try {
group = GroupManager.getInstance().getGroup(cp.getToPhoneNumber());
canRoute = true;
} catch (GroupNotFoundException e) {
}
}
Log.info("Incoming SIP, call route to entity " + cp.getToPhoneNumber() + " " + canRoute);
if (canRoute) {
String callId = "rayo-incoming-" + System.currentTimeMillis();
cp.setCallId(callId);
cp.setConferenceId(callId);
// regular phone
if (cp.getMediaPreference() == null)
cp.setMediaPreference("PCMU/8000/1");
ConferenceManager conferenceManager = ConferenceManager.getConference(callId, cp.getMediaPreference(), cp.getToPhoneNumber(), false);
conferenceManager.setCallId(callId);
Map<String, String> headers = cp.getHeaders();
headers.put("mixer_name", callId);
headers.put("call_protocol", "SIP");
headers.put("codec_name", "PCM/48000/2".equals(cp.getMediaPreference()) ? "OPUS" : "PCMU");
headers.put("group_name", cp.getToPhoneNumber());
if (// send this call to specific user
foundUser != null) {
cp.setCallOwner(foundUser.toString());
routeSIPCall(foundUser, cp, callId, headers);
} else {
conferenceManager.setGroupName(cp.getToPhoneNumber());
for (JID memberJID : group.getMembers()) {
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(memberJID.getNode());
for (ClientSession session : sessions) {
routeSIPCall(session.getAddress(), cp, callId, headers);
}
}
}
}
return canRoute;
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class RayoComponent method notifyConferenceMonitors.
public void notifyConferenceMonitors(ConferenceEvent conferenceEvent) {
Log.info("RayoComponent notifyConferenceMonitors " + conferenceEvent.toString());
if (defaultIncomingConferenceId.equals(conferenceEvent.getConferenceId()))
return;
ConferenceManager conferenceManager = null;
try {
if (conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT) || conferenceEvent.equals(ConferenceEvent.MEMBER_JOINED)) {
Log.info("RayoComponent notifyConferenceMonitors looking for call " + conferenceEvent.getCallId() + " " + conferenceEvent.getMemberCount());
try {
conferenceManager = ConferenceManager.findConferenceManager(conferenceEvent.getConferenceId());
} catch (Exception e) {
}
if (conferenceManager != null) {
String groupName = conferenceManager.getGroupName();
String callId = conferenceManager.getCallId();
// special case of SIP incoming
if (callId == null)
callId = conferenceEvent.getConferenceId();
CallHandler farParty = CallHandler.findCall(callId);
CallHandler callHandler = CallHandler.findCall(conferenceEvent.getCallId());
if (callHandler != null) {
Log.info("RayoComponent notifyConferenceMonitors found call handler " + callHandler + " " + farParty);
CallParticipant callParticipant = callHandler.getCallParticipant();
ArrayList memberList = conferenceManager.getMemberList();
if (conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT) && callId.equals(conferenceEvent.getCallId())) {
if (// far party left
farParty != null && farParty.getCallParticipant().isHeld() == false) {
synchronized (memberList) {
for (int i = 0; i < memberList.size(); i++) {
CallHandler participant = ((ConferenceMember) memberList.get(i)).getCallHandler();
participant.cancelRequest("Far Party has left");
}
}
}
}
int memberCount = memberList.size();
if (groupName == null) {
if (isMixerMuc(conferenceEvent.getConferenceId())) {
MUCRoom room = XMPPServer.getInstance().getMultiUserChatManager().getMultiUserChatService("conference").getChatRoom(conferenceEvent.getConferenceId());
Log.info("RayoComponent notifyConferenceMonitors routing to room occupants of " + conferenceEvent.getConferenceId());
for (MUCRole role : room.getOccupants()) {
String jid = role.getUserAddress().toString();
Log.info("RayoComponent notifyConferenceMonitors routing to room occupant " + jid);
Presence presence = new Presence();
presence.setFrom(conferenceEvent.getCallId() + "@" + getDomain());
presence.setTo(jid);
if (conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT)) {
UnjoinedEvent event = new UnjoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
presence.getElement().add(rayoProvider.toXML(event));
} else {
JoinedEvent event = new JoinedEvent(null, conferenceEvent.getConferenceId(), JoinDestinationType.MIXER);
presence.getElement().add(rayoProvider.toXML(event));
}
sendPacket(presence);
}
} else {
Log.info("RayoComponent notifyConferenceMonitors routing to owner " + callParticipant.getCallOwner() + " " + memberCount);
routeJoinEvent(callParticipant.getCallOwner(), callParticipant, conferenceEvent, memberCount, groupName, callId, farParty, conferenceManager);
}
} else {
Group group = GroupManager.getInstance().getGroup(groupName);
for (JID memberJID : group.getMembers()) {
Collection<ClientSession> sessions = SessionManager.getInstance().getSessions(memberJID.getNode());
for (ClientSession session : sessions) {
routeJoinEvent(session.getAddress().toString(), callParticipant, conferenceEvent, memberCount, groupName, callId, farParty, conferenceManager);
}
}
}
if (memberCount == 0 && conferenceEvent.equals(ConferenceEvent.MEMBER_LEFT)) {
conferenceManager.recordConference(false, null, null);
conferenceManager.endConference(conferenceEvent.getConferenceId());
CallParticipant heldCall = conferenceManager.getHeldCall();
if (heldCall != null) {
JID target = getJID(heldCall.getCallId());
if (target != null) {
Presence presence = new Presence();
presence.setFrom(callId + "@" + getDomain());
presence.setTo(target);
presence.getElement().add(rayoProvider.toXML(new EndEvent(null, EndEvent.Reason.valueOf("HANGUP"), callParticipant.getHeaders())));
sendPacket(presence);
}
}
} else if (memberCount == 2) {
// reset after informing on redirect
conferenceManager.setTransferCall(false);
}
}
}
}
} catch (Exception e) {
Log.error("RayoComponent Error in notifyConferenceMonitors " + e);
e.printStackTrace();
}
}
use of org.jivesoftware.openfire.group.Group in project Openfire by igniterealtime.
the class GroupController method createGroup.
/**
* Creates the group.
*
* @param groupEntity
* the group entity
* @return the group
* @throws ServiceException
* the service exception
*/
public Group createGroup(GroupEntity groupEntity) throws ServiceException {
Group group;
if (groupEntity != null && !groupEntity.getName().isEmpty()) {
try {
group = GroupManager.getInstance().createGroup(groupEntity.getName());
group.setDescription(groupEntity.getDescription());
group.getProperties().put("sharedRoster.showInRoster", "onlyGroup");
group.getProperties().put("sharedRoster.displayName", groupEntity.getName());
group.getProperties().put("sharedRoster.groupList", "");
} catch (GroupAlreadyExistsException e) {
throw new ServiceException("Could not create a group", groupEntity.getName(), ExceptionType.GROUP_ALREADY_EXISTS, Response.Status.CONFLICT, e);
}
} else {
throw new ServiceException("Could not create new group", "groups", ExceptionType.ILLEGAL_ARGUMENT_EXCEPTION, Response.Status.BAD_REQUEST);
}
return group;
}
Aggregations