Skip to content

Commit d6b8161

Browse files
author
Jeremy Deloche
committed
LUT-30818 : Addition of a listener interface for user deletion
1 parent 6b71455 commit d6b8161

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
/*
2+
* Copyright (c) 2002-2025, City of Paris
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice
10+
* and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice
13+
* and the following disclaimer in the documentation and/or other materials
14+
* provided with the distribution.
15+
*
16+
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17+
* contributors may be used to endorse or promote products derived from
18+
* this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
* License 1.0
33+
*/
34+
package fr.paris.lutece.portal.service.user;
35+
36+
public interface IUserAdminRemovalListener {
37+
38+
/**
39+
* Notify the listener for a user deletion
40+
*
41+
* @param nIdUser
42+
* the id of deleted user.
43+
* @throws UserAdminErrorException
44+
*/
45+
void notify( int nIdUser ) throws UserAdminErrorException;
46+
47+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* Copyright (c) 2002-2025, City of Paris
3+
* All rights reserved.
4+
*
5+
* Redistribution and use in source and binary forms, with or without
6+
* modification, are permitted provided that the following conditions
7+
* are met:
8+
*
9+
* 1. Redistributions of source code must retain the above copyright notice
10+
* and the following disclaimer.
11+
*
12+
* 2. Redistributions in binary form must reproduce the above copyright notice
13+
* and the following disclaimer in the documentation and/or other materials
14+
* provided with the distribution.
15+
*
16+
* 3. Neither the name of 'Mairie de Paris' nor 'Lutece' nor the names of its
17+
* contributors may be used to endorse or promote products derived from
18+
* this software without specific prior written permission.
19+
*
20+
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21+
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23+
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE
24+
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25+
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26+
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27+
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28+
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29+
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30+
* POSSIBILITY OF SUCH DAMAGE.
31+
*
32+
* License 1.0
33+
*/
34+
package fr.paris.lutece.portal.service.user;
35+
36+
public class UserAdminErrorException extends RuntimeException
37+
{
38+
39+
private static final long serialVersionUID = -1497353239794053049L;
40+
41+
private final String _strI18nErrorMessage;
42+
private final Object[] _messageArgs;
43+
44+
/**
45+
* Constructor
46+
*
47+
* @param strI18nErrorMessage
48+
* the I18n key error message
49+
*/
50+
public UserAdminErrorException(String strI18nErrorMessage, Object[] messageArgs)
51+
{
52+
_strI18nErrorMessage = strI18nErrorMessage;
53+
_messageArgs = messageArgs;
54+
}
55+
56+
/**
57+
* @return the _strI18nErrorMessage
58+
*/
59+
public String getI18nErrorMessage( )
60+
{
61+
return _strI18nErrorMessage;
62+
}
63+
64+
/**
65+
* @return message args
66+
*/
67+
public Object[] getMessageArgs( )
68+
{
69+
return _messageArgs;
70+
}
71+
72+
}

src/java/fr/paris/lutece/portal/web/user/AdminUserJspBean.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import javax.servlet.http.HttpServletRequest;
4949
import javax.servlet.http.HttpServletResponse;
5050

51+
import fr.paris.lutece.portal.service.user.IUserAdminRemovalListener;
52+
import fr.paris.lutece.portal.service.user.UserAdminErrorException;
5153
import org.apache.commons.fileupload.FileItem;
5254
import org.apache.commons.lang3.StringUtils;
5355

@@ -1469,6 +1471,15 @@ public String doRemoveAdminUser( HttpServletRequest request ) throws AccessDenie
14691471
throw new AccessDeniedException( ERROR_INVALID_TOKEN );
14701472
}
14711473

1474+
try
1475+
{
1476+
checkRemoveListener(nUserId);
1477+
}
1478+
catch (UserAdminErrorException e)
1479+
{
1480+
return AdminMessageService.getMessageUrl( request, e.getI18nErrorMessage(), e.getMessageArgs() ,AdminMessage.TYPE_ERROR );
1481+
}
1482+
14721483
AdminUser currentUser = AdminUserService.getAdminUser( request );
14731484

14741485
if ( !isUserAuthorizedToModifyUser( currentUser, user ) )
@@ -2763,4 +2774,21 @@ private boolean isUserLevelModified( AdminUser user, String strSelectedUserLevel
27632774
}
27642775
return false;
27652776
}
2777+
2778+
/**
2779+
* Notifies all registered listeners about the attempt to remove a user.
2780+
*
2781+
* @param nUserId the ID of the user
2782+
* @throws UserAdminErrorException if an error occurs during listener notification
2783+
*/
2784+
private void checkRemoveListener( int nUserId ) throws UserAdminErrorException
2785+
{
2786+
// Notify registered listener
2787+
List<IUserAdminRemovalListener> listRemovalListener = SpringContextService.getBeansOfType( IUserAdminRemovalListener.class );
2788+
for ( IUserAdminRemovalListener removalLister : listRemovalListener )
2789+
{
2790+
removalLister.notify( nUserId );
2791+
}
2792+
}
2793+
27662794
}

0 commit comments

Comments
 (0)