Commit 59fbb933 authored by Gaston Dombiak's avatar Gaston Dombiak Committed by gaston

. Users may only log in using their reserved nickname. JM-225

. Occupants may not be able to change their nicknames. JM-225
. Room registration may now be disabled. JM-308


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1623 b35dd754-fafc-0310-a699-88a17e54d16e
parent 0d3194be
......@@ -206,11 +206,13 @@ public interface MUCRoom {
* nickname reserved by the first user.
* @throws ServiceUnavailableException If the user cannot join the room since the max number
* of users has been reached.
* @throws NotAcceptableException If the registered user is trying to join with a
* nickname different than the reserved nickname.
*/
MUCRole joinRoom(String nickname, String password, HistoryRequest historyRequest, MUCUser user,
Presence presence) throws UnauthorizedException, UserAlreadyExistsException,
RoomLockedException, ForbiddenException, RegistrationRequiredException,
ConflictException, ServiceUnavailableException;
ConflictException, ServiceUnavailableException, NotAcceptableException;
/**
* Remove a member from the chat room.
......@@ -669,6 +671,67 @@ public interface MUCRoom {
*/
public void setLogEnabled(boolean logEnabled);
/**
* Returns true if registered users can only join the room using their registered nickname. By
* default, registered users can join the room using any nickname. A not_acceptable error
* will be returned if the user tries to join the room with a nickname different than the
* reserved nickname.
*
* @return true if registered users can only join the room using their registered nickname.
*/
public boolean isLoginRestrictedToNickname();
/**
* Sets if registered users can only join the room using their registered nickname. A
* not_acceptable error will be returned if the user tries to join the room with a nickname
* different than the reserved nickname.
*
* @param restricted if registered users can only join the room using their registered nickname.
*/
public void setLoginRestrictedToNickname(boolean restricted);
/**
* Returns true if room occupants are allowed to change their nicknames in the room. By
* default, occupants are allowed to change their nicknames. A not_acceptable error will be
* returned if an occupant tries to change his nickname and this feature is not enabled.<p>
*
* Notice that this feature is not supported by the MUC spec so answering a not_acceptable
* error may break some cliens.
*
* @return true if room occupants are allowed to change their nicknames in the room.
*/
public boolean canChangeNickname();
/**
* Sets if room occupants are allowed to change their nicknames in the room. By default,
* occupants are allowed to change their nicknames. A not_acceptable error will be returned if
* an occupant tries to change his nickname and this feature is not enabled.<p>
*
* Notice that this feature is not supported by the MUC spec so answering a not_acceptable
* error may break some cliens.
*
* @param canChange if room occupants are allowed to change their nicknames in the room.
*/
public void setChangeNickname(boolean canChange);
/**
* Returns true if users are allowed to register with the room. By default, room registration
* is enabled. A not_allowed error will be returned if a user tries to register with the room
* and this feature is disabled.
*
* @return true if users are allowed to register with the room.
*/
public boolean isRegistrationEnabled();
/**
* Sets if users are allowed to register with the room. By default, room registration
* is enabled. A not_allowed error will be returned if a user tries to register with the room
* and this feature is disabled.
*
* @param registrationEnabled if users are allowed to register with the room.
*/
public void setRegistrationEnabled(boolean registrationEnabled);
/**
* Returns the maximum number of occupants that can be simultaneously in the room. If the number
* is zero then there is no limit.
......
......@@ -114,6 +114,13 @@ class IQMUCRegisterHandler {
reply.setError(PacketError.Condition.item_not_found);
return reply;
}
else if (!room.isRegistrationEnabled()) {
// The room does not accept users to register
reply = IQ.createResultIQ(packet);
reply.setChildElement(packet.getChildElement().createCopy());
reply.setError(PacketError.Condition.not_allowed);
return reply;
}
if (IQ.Type.get == packet.getType()) {
reply = IQ.createResultIQ(packet);
......
......@@ -473,6 +473,27 @@ public class IQOwnerHandler {
room.setLogEnabled(("1".equals(booleanValue) ? true : false));
}
field = completedForm.getField("x-muc#roomconfig_reservednick");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
room.setLoginRestrictedToNickname(("1".equals(booleanValue) ? true : false));
}
field = completedForm.getField("x-muc#roomconfig_canchangenick");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
room.setChangeNickname(("1".equals(booleanValue) ? true : false));
}
field = completedForm.getField("x-muc#roomconfig_registration");
if (field != null) {
values = field.getValues();
booleanValue = (values.hasNext() ? values.next() : "1");
room.setRegistrationEnabled(("1".equals(booleanValue) ? true : false));
}
// Update the modification date to reflect the last time when the room's configuration
// was modified
room.setModificationDate(new Date());
......@@ -585,6 +606,18 @@ public class IQOwnerHandler {
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 (String jid : room.getAdmins()) {
......@@ -714,6 +747,21 @@ public class IQOwnerHandler {
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_enablelogging"));
configurationForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_reservednick");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_reservednick"));
configurationForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_canchangenick");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_canchangenick"));
configurationForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_registration");
field.setType(FormField.TYPE_BOOLEAN);
field.setLabel(LocaleUtils.getLocalizedString("muc.form.conf.owner_registration"));
configurationForm.addField(field);
field = new XFormFieldImpl();
field.setType(FormField.TYPE_FIXED);
field.addValue(LocaleUtils.getLocalizedString("muc.form.conf.roomadminsfixed"));
......
......@@ -43,8 +43,8 @@ public class MUCPersistenceManager {
private static final String LOAD_ROOM =
"SELECT roomID, creationDate, modificationDate, naturalName, description, lockedDate, " +
"emptyDate, canChangeSubject, maxUsers, publicRoom, moderated, membersOnly, canInvite, " +
"password, canDiscoverJID, logEnabled, subject, rolesToBroadcast " +
"FROM mucRoom WHERE name=?";
"password, canDiscoverJID, logEnabled, subject, rolesToBroadcast, useReservedNick, " +
"canChangeNick, canRegister FROM mucRoom WHERE name=?";
private static final String LOAD_AFFILIATIONS =
"SELECT jid, affiliation FROM mucAffiliation WHERE roomID=?";
private static final String LOAD_MEMBERS =
......@@ -55,7 +55,8 @@ public class MUCPersistenceManager {
private static final String LOAD_ALL_ROOMS =
"SELECT roomID, creationDate, modificationDate, name, naturalName, description, " +
"lockedDate, emptyDate, canChangeSubject, maxUsers, publicRoom, moderated, membersOnly, " +
"canInvite, password, canDiscoverJID, logEnabled, subject, rolesToBroadcast " +
"canInvite, password, canDiscoverJID, logEnabled, subject, rolesToBroadcast, " +
"useReservedNick, canChangeNick, canRegister " +
"FROM mucRoom WHERE emptyDate IS NULL or emptyDate > ?";
private static final String LOAD_ALL_AFFILIATIONS =
"SELECT roomID,jid,affiliation FROM mucAffiliation";
......@@ -67,8 +68,8 @@ public class MUCPersistenceManager {
private static final String UPDATE_ROOM =
"UPDATE mucRoom SET modificationDate=?, naturalName=?, description=?, " +
"canChangeSubject=?, maxUsers=?, publicRoom=?, moderated=?, membersOnly=?, " +
"canInvite=?, password=?, canDiscoverJID=?, logEnabled=?, rolesToBroadcast=? " +
"WHERE roomID=?";
"canInvite=?, password=?, canDiscoverJID=?, logEnabled=?, rolesToBroadcast=?, " +
"useReservedNick=?, canChangeNick=?, canRegister=? WHERE roomID=?";
private static final String ADD_ROOM =
"INSERT INTO mucRoom (roomID, creationDate, modificationDate, name, naturalName, " +
"description, lockedDate, emptyDate, canChangeSubject, maxUsers, publicRoom, moderated, " +
......@@ -189,6 +190,9 @@ public class MUCPersistenceManager {
rolesToBroadcast.add("visitor");
}
room.setRolesToBroadcastPresence(rolesToBroadcast);
room.setLoginRestrictedToNickname(rs.getInt(19) == 1 ? true : false);
room.setChangeNickname(rs.getInt(20) == 1 ? true : false);
room.setRegistrationEnabled(rs.getInt(21) == 1 ? true : false);
room.setPersistent(true);
rs.close();
pstmt.close();
......@@ -311,7 +315,10 @@ public class MUCPersistenceManager {
pstmt.setInt(11, (room.canAnyoneDiscoverJID() ? 1 : 0));
pstmt.setInt(12, (room.isLogEnabled() ? 1 : 0));
pstmt.setInt(13, marshallRolesToBroadcast(room));
pstmt.setLong(14, room.getID());
pstmt.setInt(14, (room.isLoginRestrictedToNickname() ? 1 : 0));
pstmt.setInt(15, (room.canChangeNickname() ? 1 : 0));
pstmt.setInt(16, (room.isRegistrationEnabled() ? 1 : 0));
pstmt.setLong(17, room.getID());
pstmt.executeUpdate();
}
else {
......@@ -341,10 +348,9 @@ public class MUCPersistenceManager {
pstmt.setInt(17, (room.isLogEnabled() ? 1 : 0));
pstmt.setString(18, room.getSubject());
pstmt.setInt(19, marshallRolesToBroadcast(room));
// TODO Replace with real values when functionality gets implemented
pstmt.setInt(20, 0);
pstmt.setInt(21, 1);
pstmt.setInt(22, 1);
pstmt.setInt(20, (room.isLoginRestrictedToNickname() ? 1 : 0));
pstmt.setInt(21, (room.canChangeNickname() ? 1 : 0));
pstmt.setInt(22, (room.isRegistrationEnabled() ? 1 : 0));
pstmt.executeUpdate();
}
}
......@@ -457,6 +463,9 @@ public class MUCPersistenceManager {
rolesToBroadcast.add("visitor");
}
room.setRolesToBroadcastPresence(rolesToBroadcast);
room.setLoginRestrictedToNickname(rs.getInt(20) == 1 ? true : false);
room.setChangeNickname(rs.getInt(21) == 1 ? true : false);
room.setRegistrationEnabled(rs.getInt(22) == 1 ? true : false);
room.setPersistent(true);
rooms.put(room.getID(), room);
}
......
......@@ -200,6 +200,24 @@ public class MUCRoomImpl implements MUCRoom {
*/
private boolean logEnabled = false;
/**
* Enables the logging of the conversation. The conversation in the room will be saved to the
* database.
*/
private boolean loginRestrictedToNickname = false;
/**
* Enables the logging of the conversation. The conversation in the room will be saved to the
* database.
*/
private boolean canChangeNickname = true;
/**
* Enables the logging of the conversation. The conversation in the room will be saved to the
* database.
*/
private boolean registrationEnabled = true;
/**
* Internal component that handles IQ packets sent by the room owners.
*/
......@@ -390,7 +408,8 @@ public class MUCRoomImpl implements MUCRoom {
public MUCRole joinRoom(String nickname, String password, HistoryRequest historyRequest,
MUCUser user, Presence presence) throws UnauthorizedException,
UserAlreadyExistsException, RoomLockedException, ForbiddenException,
RegistrationRequiredException, ConflictException, ServiceUnavailableException {
RegistrationRequiredException, ConflictException, ServiceUnavailableException,
NotAcceptableException {
MUCRoleImpl joinRole = null;
lock.writeLock().lock();
try {
......@@ -423,6 +442,12 @@ public class MUCRoomImpl implements MUCRoom {
throw new ConflictException();
}
}
if (isLoginRestrictedToNickname()) {
String reservedNickname = members.get(user.getAddress().toBareJID());
if (reservedNickname != null && !nickname.equals(reservedNickname)) {
throw new NotAcceptableException();
}
}
// Set the corresponding role based on the user's affiliation
MUCRole.Role role;
......@@ -1555,6 +1580,30 @@ public class MUCRoomImpl implements MUCRoom {
this.logEnabled = logEnabled;
}
public void setLoginRestrictedToNickname(boolean restricted) {
this.loginRestrictedToNickname = restricted;
}
public boolean isLoginRestrictedToNickname() {
return loginRestrictedToNickname;
}
public void setChangeNickname(boolean canChange) {
this.canChangeNickname = canChange;
}
public boolean canChangeNickname() {
return canChangeNickname;
}
public void setRegistrationEnabled(boolean registrationEnabled) {
this.registrationEnabled = registrationEnabled;
}
public boolean isRegistrationEnabled() {
return registrationEnabled;
}
public int getMaxUsers() {
return maxUsers;
}
......
......@@ -408,6 +408,9 @@ public class MUCUserImpl implements MUCUser {
catch (ConflictException e) {
sendErrorPacket(packet, PacketError.Condition.conflict);
}
catch (NotAcceptableException e) {
sendErrorPacket(packet, PacketError.Condition.not_acceptable);
}
}
else {
// TODO: send error message to user (can't send presence to group you
......@@ -457,8 +460,12 @@ public class MUCUserImpl implements MUCUser {
// Occupant has changed his nickname. Send two presences
// to each room occupant
// Check if occupants are allowed to change their nicknames
if (!role.getChatRoom().canChangeNickname()) {
sendErrorPacket(packet, PacketError.Condition.not_acceptable);
}
// Answer a conflic error if the new nickname is taken
if (role.getChatRoom().hasOccupant(resource)) {
else if (role.getChatRoom().hasOccupant(resource)) {
sendErrorPacket(packet, PacketError.Condition.conflict);
}
else {
......
......@@ -55,6 +55,9 @@
String allowInvites = ParamUtils.getParameter(request, "roomconfig_allowinvites");
String changeSubject = ParamUtils.getParameter(request, "roomconfig_changesubject");
String enableLog = ParamUtils.getParameter(request, "roomconfig_enablelogging");
String reservedNick = ParamUtils.getParameter(request, "roomconfig_reservednick");
String canChangeNick = ParamUtils.getParameter(request, "roomconfig_canchangenick");
String registrationEnabled = ParamUtils.getParameter(request, "roomconfig_registration");
String roomSubject = ParamUtils.getParameter(request, "room_topic");
// Handle a cancel
......@@ -207,6 +210,18 @@
field.addValue((enableLog == null) ? "0": "1");
dataForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_reservednick");
field.addValue((reservedNick == null) ? "0": "1");
dataForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_canchangenick");
field.addValue((canChangeNick == null) ? "0": "1");
dataForm.addField(field);
field = new XFormFieldImpl("x-muc#roomconfig_registration");
field.addValue((registrationEnabled == null) ? "0": "1");
dataForm.addField(field);
// Keep the existing list of admins
field = new XFormFieldImpl("muc#roomconfig_roomadmins");
for (String jid : room.getAdmins()) {
......@@ -280,6 +295,9 @@
allowInvites = Boolean.toString(room.canOccupantsInvite());
changeSubject = Boolean.toString(room.canOccupantsChangeSubject());
enableLog = Boolean.toString(room.isLogEnabled());
reservedNick = Boolean.toString(room.isLoginRestrictedToNickname());
canChangeNick = Boolean.toString(room.canChangeNickname());
registrationEnabled = Boolean.toString(room.isRegistrationEnabled());
}
}
// Formatter for dates
......@@ -492,6 +510,18 @@
<td><input type="checkbox" name="roomconfig_changesubject" value="true" id="changesubject" <% if ("true".equals(changeSubject)) out.write("checked");%>>
<LABEL FOR="changesubject"><fmt:message key="muc.room.edit.form.change_subject" /></LABEL></td>
</tr>
<tr>
<td><input type="checkbox" name="roomconfig_reservednick" value="true" id="reservednick" <% if ("true".equals(reservedNick)) out.write("checked");%>>
<LABEL FOR="reservednick"><fmt:message key="muc.room.edit.form.reservednick" /></LABEL></td>
</tr>
<tr>
<td><input type="checkbox" name="roomconfig_canchangenick" value="true" id="canchangenick" <% if ("true".equals(canChangeNick)) out.write("checked");%>>
<LABEL FOR="canchangenick"><fmt:message key="muc.room.edit.form.canchangenick" /></LABEL></td>
</tr>
<tr>
<td><input type="checkbox" name="roomconfig_registration" value="true" id="registration" <% if ("true".equals(registrationEnabled)) out.write("checked");%>>
<LABEL FOR="registration"><fmt:message key="muc.room.edit.form.registration" /></LABEL></td>
</tr>
<tr>
<td><input type="checkbox" name="roomconfig_enablelogging" value="true" id="enablelogging" <% if ("true".equals(enableLog)) out.write("checked");%>>
<LABEL FOR="enablelogging"><fmt:message key="muc.room.edit.form.log" /></td>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment