1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 package fr.paris.lutece.plugins.identitystore.web;
35
36 import fr.paris.lutece.plugins.identitystore.business.application.ClientApplication;
37 import fr.paris.lutece.plugins.identitystore.business.application.ClientApplicationHome;
38 import fr.paris.lutece.plugins.identitystore.business.contract.ServiceContract;
39 import fr.paris.lutece.plugins.identitystore.service.contract.ServiceContractService;
40 import fr.paris.lutece.plugins.identitystore.web.exception.IdentityStoreException;
41 import fr.paris.lutece.portal.service.message.AdminMessage;
42 import fr.paris.lutece.portal.service.message.AdminMessageService;
43 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
44 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
45 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
46 import fr.paris.lutece.util.url.UrlItem;
47 import org.apache.commons.lang3.StringUtils;
48
49 import javax.servlet.http.HttpServletRequest;
50 import java.util.List;
51 import java.util.Map;
52 import java.util.stream.Collectors;
53
54
55
56
57 @Controller( controllerJsp = "ManageClientApplications.jsp", controllerPath = "jsp/admin/plugins/identitystore/", right = "IDENTITYSTORE_ADMIN_MANAGEMENT" )
58 public class ManageClientApplicationJspBean extends ManageIdentitiesJspBean
59 {
60 private static final long serialVersionUID = 1L;
61
62
63 private static final String TEMPLATE_MANAGE_CLIENTAPPLICATION = "/admin/plugins/identitystore/clientapplication/manage_clientapplications.html";
64 private static final String TEMPLATE_DISPLAY_CLIENTAPPLICATION = "/admin/plugins/identitystore/clientapplication/view_clientapplication.html";
65 private static final String TEMPLATE_CREATE_CLIENTAPPLICATION = "/admin/plugins/identitystore/clientapplication/create_clientapplication.html";
66 private static final String TEMPLATE_MODIFY_CLIENTAPPLICATION = "/admin/plugins/identitystore/clientapplication/modify_clientapplication.html";
67
68
69 private static final String QUERY_PARAM_CLIENT_APPLICATION_NAME = "client_application_name";
70 private static final String QUERY_PARAM_APPLICATION_CODE = "application_code";
71 private static final String QUERY_PARAM_CLIENT_CODE = "client_code";
72
73
74 private static final String PARAMETER_ID_CLIENTAPPLICATION = "id";
75
76 private static final String PARAMETER_CERTIFIERS_AUTH = "certif_auth";
77 private static final String PARAMETER_CERTIFIER_CODE = "certif_code";
78
79
80 private static final String PROPERTY_PAGE_TITLE_MANAGE_CLIENTAPPLICATIONS = "identitystore.manage_clientapplications.pageTitle";
81 private static final String PROPERTY_PAGE_TITLE_MODIFY_CLIENTAPPLICATION = "identitystore.modify_clientapplication.pageTitle";
82 private static final String PROPERTY_PAGE_TITLE_CREATE_CLIENTAPPLICATION = "identitystore.create_clientapplication.pageTitle";
83 private static final String PROPERTY_PAGE_TITLE_MODIFY_CLIENTAPPLICATION_CERTIFICATOR = "identitystore.modify_clientapplication_certificator.pageTitle";
84
85
86 private static final String MARK_CLIENTAPPLICATION_LIST = "clientapplication_list";
87 private static final String MARK_CLIENTAPPLICATION = "clientapplication";
88 private static final String MARK_SERVICECONTRACTS = "servicecontract_list";
89 private static final String MARK_ACTIVECONTRACT = "servicecontract_active";
90 private static final String MARK_CLIENTAPPLICATION_CERTIF_LIST = "clientapplication_certifs";
91 private static final String MARK_CLIENTAPPLICATION_CERTIF_CODE_MAP = "map_clientapplication_certifs";
92 private static final String MARK_CERTIFIERS = "certifiers";
93 private static final String MARK_CLIENTAPPLICATION_RIGHT_LIST = "clientapplication_rights_list";
94 private static final String JSP_MANAGE_CLIENTAPPLICATIONS = "jsp/admin/plugins/identitystore/ManageClientApplications.jsp";
95
96
97 private static final String MESSAGE_CONFIRM_REMOVE_CLIENTAPPLICATION = "identitystore.message.confirmRemoveClientApplication";
98
99
100 private static final String VALIDATION_ATTRIBUTES_PREFIX = "identitystore.model.entity.clientapplication.attribute.";
101
102
103 private static final String VIEW_MANAGE_CLIENTAPPLICATIONS = "manageClientApplications";
104 private static final String VIEW_DISPLAY_CLIENTAPPLICATIONS = "displayClientApplication";
105 private static final String VIEW_CREATE_CLIENTAPPLICATION = "createClientApplication";
106 private static final String VIEW_MODIFY_CLIENTAPPLICATION = "modifyClientApplication";
107 private static final String VIEW_MANAGE_CLIENTAPPLICATION_CERTIFICATOR = "manageClientApplicationCertificate";
108
109
110 private static final String ACTION_CREATE_CLIENTAPPLICATION = "createClientApplication";
111 private static final String ACTION_MODIFY_CLIENTAPPLICATION = "modifyClientApplication";
112 private static final String ACTION_MANAGE_CLIENTAPPLICATION_CERTIFICATOR = "manageClientApplicationCertificate";
113 private static final String ACTION_REMOVE_CLIENTAPPLICATION = "removeClientApplication";
114 private static final String ACTION_CONFIRM_REMOVE_CLIENTAPPLICATION = "confirmRemoveClientApplication";
115 private static final String ACTION_REMOVE_CLIENTAPPLICATION_CERTIFICATOR = "removeClientApplicationCertificate";
116
117
118 private static final String INFO_CLIENTAPPLICATION_CREATED = "identitystore.info.clientapplication.created";
119 private static final String INFO_CLIENTAPPLICATION_UPDATED = "identitystore.info.clientapplication.updated";
120 private static final String INFO_CLIENTAPPLICATION_REMOVED = "identitystore.info.clientapplication.removed";
121
122
123 private ClientApplication _clientApplication;
124
125
126
127
128
129
130
131
132 @View( value = VIEW_MANAGE_CLIENTAPPLICATIONS, defaultView = true )
133 public String getManageClientApplications( HttpServletRequest request )
134 {
135 _clientApplication = null;
136
137 final String name = request.getParameter( QUERY_PARAM_CLIENT_APPLICATION_NAME );
138 final String appCode = request.getParameter( QUERY_PARAM_APPLICATION_CODE );
139 final String clientCode = request.getParameter( QUERY_PARAM_CLIENT_CODE );
140
141 final List<ClientApplication> listClientApplications = ClientApplicationHome.selectApplicationList( ).stream( )
142 .filter( ca -> StringUtils.isBlank( name ) || ( ca.getName( ) != null && ca.getName( ).toLowerCase( ).contains( name ) ) )
143 .filter( ca -> StringUtils.isBlank( appCode )
144 || ( ca.getApplicationCode( ) != null && ca.getApplicationCode( ).toLowerCase( ).contains( appCode ) ) )
145 .filter( ca -> StringUtils.isBlank( clientCode )
146 || ( ca.getClientCode( ) != null && ca.getClientCode( ).toLowerCase( ).contains( clientCode ) ) )
147 .sorted( ( a, b ) -> {
148 final int compare = StringUtils.compare( a.getApplicationCode( ), b.getApplicationCode( ), false );
149 if ( compare == 0 )
150 {
151 return StringUtils.compare( a.getClientCode( ), b.getClientCode( ), false );
152 }
153 return compare;
154 } ).collect( Collectors.toList( ) );
155
156 Map<String, Object> model = getPaginatedListModel( request, MARK_CLIENTAPPLICATION_LIST, listClientApplications, JSP_MANAGE_CLIENTAPPLICATIONS );
157 model.put( QUERY_PARAM_CLIENT_APPLICATION_NAME, name );
158 model.put( QUERY_PARAM_CLIENT_CODE, clientCode );
159 model.put( QUERY_PARAM_APPLICATION_CODE, appCode );
160
161 return getPage( PROPERTY_PAGE_TITLE_MANAGE_CLIENTAPPLICATIONS, TEMPLATE_MANAGE_CLIENTAPPLICATION, model );
162 }
163
164
165
166
167
168
169
170
171 @View( value = VIEW_DISPLAY_CLIENTAPPLICATIONS )
172 public String getDisplayClientApplications( HttpServletRequest request )
173 {
174 _clientApplication = null;
175
176 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLIENTAPPLICATION ) );
177
178 Map<String, Object> model = getModel( );
179
180 _clientApplication = ClientApplicationHome.findByPrimaryKey( nId );
181 List<ServiceContract> serviceContracts = ClientApplicationHome.selectServiceContracts( _clientApplication );
182 _clientApplication.setServiceContracts( serviceContracts );
183
184 model.put( MARK_CLIENTAPPLICATION, _clientApplication );
185
186 return getPage( PROPERTY_PAGE_TITLE_MANAGE_CLIENTAPPLICATIONS, TEMPLATE_DISPLAY_CLIENTAPPLICATION, model );
187 }
188
189
190
191
192
193
194
195
196 @View( VIEW_CREATE_CLIENTAPPLICATION )
197 public String getCreateClientApplication( HttpServletRequest request )
198 {
199 _clientApplication = new ClientApplication( );
200
201 Map<String, Object> model = getModel( );
202 model.put( MARK_CLIENTAPPLICATION, _clientApplication );
203
204 return getPage( PROPERTY_PAGE_TITLE_CREATE_CLIENTAPPLICATION, TEMPLATE_CREATE_CLIENTAPPLICATION, model );
205 }
206
207
208
209
210
211
212
213
214 @Action( ACTION_CREATE_CLIENTAPPLICATION )
215 public String doCreateClientApplication( HttpServletRequest request )
216 {
217 populate( _clientApplication, request );
218
219
220 if ( !validateBean( _clientApplication, VALIDATION_ATTRIBUTES_PREFIX ) )
221 {
222 return redirectView( request, VIEW_CREATE_CLIENTAPPLICATION );
223 }
224
225 ClientApplicationHome.create( _clientApplication );
226
227 addInfo( INFO_CLIENTAPPLICATION_CREATED, getLocale( ) );
228
229 return redirectView( request, VIEW_MANAGE_CLIENTAPPLICATIONS );
230 }
231
232
233
234
235
236
237
238
239 @Action( ACTION_CONFIRM_REMOVE_CLIENTAPPLICATION )
240 public String getConfirmRemoveClientApplication( HttpServletRequest request )
241 {
242 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLIENTAPPLICATION ) );
243 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_CLIENTAPPLICATION ) );
244 url.addParameter( PARAMETER_ID_CLIENTAPPLICATION, nId );
245
246 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_CLIENTAPPLICATION, url.getUrl( ),
247 AdminMessage.TYPE_CONFIRMATION );
248
249 return redirect( request, strMessageUrl );
250 }
251
252
253
254
255
256
257
258
259 @Action( ACTION_REMOVE_CLIENTAPPLICATION )
260 public String doRemoveClientApplication( HttpServletRequest request )
261 {
262 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLIENTAPPLICATION ) );
263
264 ClientApplication clientApplication = ClientApplicationHome.findByPrimaryKey( nId );
265 try
266 {
267 ServiceContractService.instance( ).deleteApplication( clientApplication );
268 }
269 catch( IdentityStoreException e )
270 {
271 addError( e.getMessage( ) );
272 return redirectView( request, VIEW_MANAGE_CLIENTAPPLICATIONS );
273 }
274 addInfo( INFO_CLIENTAPPLICATION_REMOVED, getLocale( ) );
275
276 return redirectView( request, VIEW_MANAGE_CLIENTAPPLICATIONS );
277 }
278
279
280
281
282
283
284
285
286 @View( VIEW_MODIFY_CLIENTAPPLICATION )
287 public String getModifyClientApplication( HttpServletRequest request )
288 {
289 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_CLIENTAPPLICATION ) );
290
291 if ( ( _clientApplication == null ) || ( _clientApplication.getId( ) != nId ) )
292 {
293 _clientApplication = ClientApplicationHome.findByPrimaryKey( nId );
294 }
295
296 Map<String, Object> model = getModel( );
297 model.put( MARK_CLIENTAPPLICATION, _clientApplication );
298
299 return getPage( PROPERTY_PAGE_TITLE_MODIFY_CLIENTAPPLICATION, TEMPLATE_MODIFY_CLIENTAPPLICATION, model );
300 }
301
302
303
304
305
306
307
308
309 @Action( ACTION_MODIFY_CLIENTAPPLICATION )
310 public String doModifyClientApplication( HttpServletRequest request )
311 {
312 populate( _clientApplication, request );
313
314
315 if ( !validateBean( _clientApplication, VALIDATION_ATTRIBUTES_PREFIX ) )
316 {
317 return redirect( request, VIEW_MODIFY_CLIENTAPPLICATION, PARAMETER_ID_CLIENTAPPLICATION, _clientApplication.getId( ) );
318 }
319
320 ClientApplicationHome.update( _clientApplication );
321 addInfo( INFO_CLIENTAPPLICATION_UPDATED, getLocale( ) );
322
323 return redirectView( request, VIEW_MANAGE_CLIENTAPPLICATIONS );
324 }
325
326 }