2525import org .jivesoftware .openfire .plugin .rest .entity .*;
2626import org .jivesoftware .openfire .plugin .rest .exceptions .ExceptionType ;
2727import org .jivesoftware .openfire .plugin .rest .exceptions .ServiceException ;
28+ import org .jivesoftware .openfire .plugin .rest .utils .LoggingUtils ;
2829import org .jivesoftware .openfire .plugin .rest .utils .MUCRoomUtils ;
2930import org .jivesoftware .openfire .plugin .rest .utils .UserUtils ;
3031import org .jivesoftware .util .AlreadyExistsException ;
3637import org .xmpp .packet .Presence ;
3738
3839import javax .annotation .Nonnull ;
39- import javax .servlet .ServletException ;
4040import javax .ws .rs .core .Response ;
4141import java .lang .reflect .InvocationTargetException ;
4242import java .util .*;
@@ -166,7 +166,11 @@ protected static MUCRoom getRoom(@Nonnull final String serviceName, @Nonnull fin
166166 */
167167 public MUCRoomEntities getChatRooms (String serviceName , String channelType , String roomSearch , boolean expand ) throws ServiceException
168168 {
169- log ("Get the chat rooms" );
169+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_LIST_ROOMS ,
170+ "serviceName" , serviceName ,
171+ "channelType" , channelType ,
172+ "roomSearch" , roomSearch ,
173+ "expand" , expand );
170174 final MultiUserChatService service = getService (serviceName );
171175 Set <String > roomNames = service .getAllRoomNames ();
172176
@@ -207,7 +211,10 @@ public MUCRoomEntities getChatRooms(String serviceName, String channelType, Stri
207211 * the service exception
208212 */
209213 public MUCRoomEntity getChatRoom (String roomName , String serviceName , boolean expand ) throws ServiceException {
210- log ("Get the chat room: " + roomName );
214+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_GET_ROOM ,
215+ "roomName" , roomName ,
216+ "serviceName" , serviceName ,
217+ "expand" , expand );
211218 final MUCRoom chatRoom = getRoom (serviceName , roomName );
212219 return convertToMUCRoomEntity (chatRoom , expand );
213220 }
@@ -223,7 +230,9 @@ public MUCRoomEntity getChatRoom(String roomName, String serviceName, boolean ex
223230 * the service exception
224231 */
225232 public void deleteChatRoom (String roomName , String serviceName ) throws ServiceException {
226- log ("Delete the chat room: " + roomName );
233+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_DELETE_ROOM ,
234+ "roomName" , roomName ,
235+ "serviceName" , serviceName );
227236 final MUCRoom chatRoom = getRoom (serviceName , roomName );
228237 chatRoom .destroyRoom (null , null );
229238 }
@@ -239,7 +248,9 @@ public void deleteChatRoom(String roomName, String serviceName) throws ServiceEx
239248 * the service exception
240249 */
241250 public void createChatRoom (String serviceName , MUCRoomEntity mucRoomEntity ) throws ServiceException {
242- log ("Create a chat room: " + mucRoomEntity .getRoomName ());
251+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_CREATE_ROOM ,
252+ "serviceName" , serviceName ,
253+ "mucRoomEntity" , mucRoomEntity );
243254 try {
244255 createRoom (mucRoomEntity , serviceName );
245256 } catch (NotAllowedException | ForbiddenException e ) {
@@ -268,7 +279,10 @@ public void createChatRoom(String serviceName, MUCRoomEntity mucRoomEntity) thro
268279 */
269280 public void updateChatRoom (String roomName , String serviceName , MUCRoomEntity mucRoomEntity )
270281 throws ServiceException {
271- log ("Update a chat room: " + mucRoomEntity .getRoomName ());
282+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_UPDATE_ROOM ,
283+ "roomName" , roomName ,
284+ "serviceName" , serviceName ,
285+ "mucRoomEntity" , mucRoomEntity );
272286 try {
273287 // If the room name is different throw exception
274288 if (!roomName .equals (mucRoomEntity .getRoomName ())) {
@@ -409,7 +423,9 @@ private boolean equalToAffiliations(MUCRoom room, MUCRoomEntity mucRoomEntity) {
409423 */
410424 public ParticipantEntities getRoomParticipants (String roomName , String serviceName ) throws ServiceException
411425 {
412- log ("Get room participants for room: " + roomName );
426+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_GET_PARTICIPANT_LIST ,
427+ "roomName" , roomName ,
428+ "serviceName" , serviceName );
413429 ParticipantEntities participantEntities = new ParticipantEntities ();
414430 List <ParticipantEntity > participants = new ArrayList <>();
415431
@@ -439,7 +455,9 @@ public ParticipantEntities getRoomParticipants(String roomName, String serviceNa
439455 */
440456 public OccupantEntities getRoomOccupants (String roomName , String serviceName ) throws ServiceException
441457 {
442- log ("Get room occupants for room: " + roomName );
458+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_GET_OCCUPANT_LIST ,
459+ "roomName" , roomName ,
460+ "serviceName" , serviceName );
443461 OccupantEntities occupantEntities = new OccupantEntities ();
444462 List <OccupantEntity > occupants = new ArrayList <>();
445463
@@ -469,7 +487,9 @@ public OccupantEntities getRoomOccupants(String roomName, String serviceName) th
469487 * @return the room chat history
470488 */
471489 public MUCRoomMessageEntities getRoomHistory (String roomName , String serviceName ) throws ServiceException {
472- log ("Get room history for room: " + roomName );
490+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_GET_ROOM_HISTORY ,
491+ "roomName" , roomName ,
492+ "serviceName" , serviceName );
473493 MUCRoomMessageEntities mucRoomMessageEntities = new MUCRoomMessageEntities ();
474494 List <MUCRoomMessageEntity > listMessages = new ArrayList <>();
475495
@@ -517,6 +537,11 @@ public MUCRoomMessageEntities getRoomHistory(String roomName, String serviceName
517537 */
518538 public void inviteUser (String serviceName , String roomName , String jid , MUCInvitationEntity mucInvitationEntity )
519539 throws ServiceException {
540+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_INVITE_USER ,
541+ "roomName" , roomName ,
542+ "serviceName" , serviceName ,
543+ "jid" , jid ,
544+ "invitation" , mucInvitationEntity );
520545 MUCRoom room = getRoom (serviceName , roomName );
521546
522547 try {
@@ -664,6 +689,7 @@ private void setRoles(MUCRoom room, MUCRoomEntity mucRoomEntity) throws Forbidde
664689 * the service exception
665690 */
666691 public void addAdmin (String serviceName , String roomName , String jid ) throws ServiceException {
692+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_ADD_AFFILIATED_USER_OR_GROUP_AS_ADMIN , serviceName , roomName , jid );
667693 MUCRoom room = getRoom (serviceName , roomName );
668694 try {
669695 room .addAdmin (UserUtils .checkAndGetJID (jid ), room .getRole ());
@@ -687,6 +713,7 @@ public void addAdmin(String serviceName, String roomName, String jid) throws Ser
687713 * the service exception
688714 */
689715 public void addOwner (String serviceName , String roomName , String jid ) throws ServiceException {
716+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_ADD_AFFILIATED_USER_OR_GROUP_AS_OWNER , serviceName , roomName , jid );
690717 MUCRoom room = getRoom (serviceName , roomName );
691718 try {
692719 room .addOwner (UserUtils .checkAndGetJID (jid ), room .getRole ());
@@ -708,6 +735,7 @@ public void addOwner(String serviceName, String roomName, String jid) throws Ser
708735 * the service exception
709736 */
710737 public void addMember (String serviceName , String roomName , String jid ) throws ServiceException {
738+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_ADD_AFFILIATED_USER_OR_GROUP_AS_MEMBER , serviceName , roomName , jid );
711739 MUCRoom room = getRoom (serviceName , roomName );
712740 try {
713741 room .addMember (UserUtils .checkAndGetJID (jid ), null , room .getRole ());
@@ -729,6 +757,7 @@ public void addMember(String serviceName, String roomName, String jid) throws Se
729757 * the service exception
730758 */
731759 public void addOutcast (String serviceName , String roomName , String jid ) throws ServiceException {
760+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_ADD_AFFILIATED_USER_OR_GROUP_AS_OUTCAST , serviceName , roomName , jid );
732761 MUCRoom room = getRoom (serviceName , roomName );
733762 try {
734763 room .addOutcast (UserUtils .checkAndGetJID (jid ), null , room .getRole ());
@@ -753,6 +782,7 @@ public void addOutcast(String serviceName, String roomName, String jid) throws S
753782 */
754783 public Collection <JID > getByAffiliation (@ Nonnull final String serviceName , @ Nonnull final String roomName , @ Nonnull final MUCRole .Affiliation affiliation ) throws ServiceException
755784 {
785+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_LIST_AFFILIATED_USERS_FOR_AFFILIATION , serviceName , roomName , affiliation );
756786 final MUCRoom room = getRoom (serviceName , roomName );
757787 switch (affiliation ) {
758788 case admin :
@@ -789,6 +819,7 @@ public Collection<JID> getByAffiliation(@Nonnull final String serviceName, @Nonn
789819 */
790820 public void replaceAffiliatedUsers (@ Nonnull final String serviceName , @ Nonnull final String roomName , @ Nonnull final MUCRole .Affiliation affiliation , @ Nonnull final Collection <String > jids ) throws ServiceException
791821 {
822+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_REPLACE_AFFILIATED_USERS_FOR_AFFILIATION , serviceName , roomName , affiliation , jids );
792823 final Collection <JID > replacements = new HashSet <>();
793824
794825 // Input validation.
@@ -864,6 +895,7 @@ public void replaceAffiliatedUsers(@Nonnull final String serviceName, @Nonnull f
864895 */
865896 public void addAffiliatedUsers (@ Nonnull final String serviceName , @ Nonnull final String roomName , @ Nonnull final MUCRole .Affiliation affiliation , @ Nonnull final Collection <String > jids ) throws ServiceException
866897 {
898+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_ADD_AFFILIATED_USERS_FOR_AFFILIATION , serviceName , roomName , affiliation , jids );
867899 final Collection <JID > additions = new HashSet <>();
868900
869901 // Input validation.
@@ -927,6 +959,7 @@ public void addAffiliatedUsers(@Nonnull final String serviceName, @Nonnull final
927959 * the service exception
928960 */
929961 public void deleteAffiliation (String serviceName , String roomName , String jid ) throws ServiceException {
962+ LoggingUtils .auditEvent (LoggingUtils .AuditEvent .MUC_REMOVE_AFFILIATED_USER_OR_GROUP_FOR_AFFILIATION , serviceName , roomName , jid );
930963 MUCRoom room = getRoom (serviceName , roomName );
931964 try {
932965 JID userJid = UserUtils .checkAndGetJID (jid );
0 commit comments