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
35 package fr.paris.lutece.plugins.grukeydiversification.web;
36
37 import fr.paris.lutece.plugins.grukeydiversification.business.EncryptionKey;
38 import fr.paris.lutece.plugins.grukeydiversification.business.EncryptionKeyHome;
39 import fr.paris.lutece.plugins.grukeydiversification.business.exception.EncryptionKeyAlreadyExistException;
40 import fr.paris.lutece.portal.service.message.AdminMessage;
41 import fr.paris.lutece.portal.service.message.AdminMessageService;
42 import fr.paris.lutece.portal.util.mvc.admin.annotations.Controller;
43 import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
44 import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
45 import fr.paris.lutece.util.url.UrlItem;
46
47 import java.util.List;
48 import java.util.Map;
49 import javax.servlet.http.HttpServletRequest;
50
51
52
53
54 @Controller( controllerJsp = "ManageEncryptionKeys.jsp", controllerPath = "jsp/admin/plugins/grukeydiversification/", right = "GRUKEYDIVERSIFICATION_MANAGEMENT" )
55 public class EncryptionKeyJspBean extends AbstractManageEncryptionKeyJspBean
56 {
57
58
59
60 private static final long serialVersionUID = 3101755353106198571L;
61
62
63 private static final String TEMPLATE_MANAGE_ENCRYPTIONKEYS = "/admin/plugins/grukeydiversification/manage_encryptionkeys.html";
64 private static final String TEMPLATE_CREATE_ENCRYPTIONKEY = "/admin/plugins/grukeydiversification/create_encryptionkey.html";
65 private static final String TEMPLATE_MODIFY_ENCRYPTIONKEY = "/admin/plugins/grukeydiversification/modify_encryptionkey.html";
66
67
68 private static final String PARAMETER_ID_ENCRYPTIONKEY = "id";
69
70
71 private static final String PROPERTY_PAGE_TITLE_MANAGE_ENCRYPTIONKEYS = "grukeydiversification.manage_encryptionkeys.pageTitle";
72 private static final String PROPERTY_PAGE_TITLE_MODIFY_ENCRYPTIONKEY = "grukeydiversification.modify_encryptionkey.pageTitle";
73 private static final String PROPERTY_PAGE_TITLE_CREATE_ENCRYPTIONKEY = "grukeydiversification.create_encryptionkey.pageTitle";
74
75
76 private static final String MARK_ENCRYPTIONKEY_LIST = "encryptionkey_list";
77 private static final String MARK_ENCRYPTIONKEY = "encryptionkey";
78
79 private static final String JSP_MANAGE_ENCRYPTIONKEYS = "jsp/admin/plugins/grukeydiversification/ManageEncryptionKeys.jsp";
80
81
82 private static final String MESSAGE_CONFIRM_REMOVE_ENCRYPTIONKEY = "grukeydiversification.message.confirmRemoveEncryptionKey";
83
84
85 private static final String VALIDATION_ATTRIBUTES_PREFIX = "grukeydiversification.model.entity.encryptionkey.attribute.";
86
87
88 private static final String VIEW_MANAGE_ENCRYPTIONKEYS = "manageEncryptionKeys";
89 private static final String VIEW_CREATE_ENCRYPTIONKEY = "createEncryptionKey";
90 private static final String VIEW_MODIFY_ENCRYPTIONKEY = "modifyEncryptionKey";
91
92
93 private static final String ACTION_CREATE_ENCRYPTIONKEY = "createEncryptionKey";
94 private static final String ACTION_MODIFY_ENCRYPTIONKEY = "modifyEncryptionKey";
95 private static final String ACTION_REMOVE_ENCRYPTIONKEY = "removeEncryptionKey";
96 private static final String ACTION_CONFIRM_REMOVE_ENCRYPTIONKEY = "confirmRemoveEncryptionKey";
97
98
99 private static final String INFO_ENCRYPTIONKEY_CREATED = "grukeydiversification.info.encryptionkey.created";
100 private static final String INFO_ENCRYPTIONKEY_UPDATED = "grukeydiversification.info.encryptionkey.updated";
101 private static final String INFO_ENCRYPTIONKEY_REMOVED = "grukeydiversification.info.encryptionkey.removed";
102
103
104 private static final String ERROR_ENCRYPTIONKEY_ALREADY_EXISTS = "grukeydiversification.error.encryptionkey.alreadyExists";
105
106
107 private EncryptionKey _encryptionkey;
108
109
110
111
112
113
114
115
116 @View( value = VIEW_MANAGE_ENCRYPTIONKEYS, defaultView = true )
117 public String getManageEncryptionKeys( HttpServletRequest request )
118 {
119 _encryptionkey = null;
120 List<EncryptionKey> listEncryptionKeys = EncryptionKeyHome.getEncryptionKeysList( );
121 Map<String, Object> model = getPaginatedListModel( request, MARK_ENCRYPTIONKEY_LIST, listEncryptionKeys, JSP_MANAGE_ENCRYPTIONKEYS );
122
123 return getPage( PROPERTY_PAGE_TITLE_MANAGE_ENCRYPTIONKEYS, TEMPLATE_MANAGE_ENCRYPTIONKEYS, model );
124 }
125
126
127
128
129
130
131
132
133 @View( VIEW_CREATE_ENCRYPTIONKEY )
134 public String getCreateEncryptionKey( HttpServletRequest request )
135 {
136 _encryptionkey = ( _encryptionkey != null ) ? _encryptionkey : new EncryptionKey( );
137
138 Map<String, Object> model = getModel( );
139 model.put( MARK_ENCRYPTIONKEY, _encryptionkey );
140
141 return getPage( PROPERTY_PAGE_TITLE_CREATE_ENCRYPTIONKEY, TEMPLATE_CREATE_ENCRYPTIONKEY, model );
142 }
143
144
145
146
147
148
149
150
151 @Action( ACTION_CREATE_ENCRYPTIONKEY )
152 public String doCreateEncryptionKey( HttpServletRequest request )
153 {
154 populate( _encryptionkey, request );
155
156
157 if ( !validateBean( _encryptionkey, VALIDATION_ATTRIBUTES_PREFIX ) )
158 {
159 return redirectView( request, VIEW_CREATE_ENCRYPTIONKEY );
160 }
161
162 try
163 {
164 EncryptionKeyHome.create( _encryptionkey );
165 }
166 catch( EncryptionKeyAlreadyExistException e )
167 {
168 addError( ERROR_ENCRYPTIONKEY_ALREADY_EXISTS, getLocale( ) );
169 return redirectView( request, VIEW_CREATE_ENCRYPTIONKEY );
170 }
171
172 addInfo( INFO_ENCRYPTIONKEY_CREATED, getLocale( ) );
173
174 return redirectView( request, VIEW_MANAGE_ENCRYPTIONKEYS );
175 }
176
177
178
179
180
181
182
183
184 @Action( ACTION_CONFIRM_REMOVE_ENCRYPTIONKEY )
185 public String getConfirmRemoveEncryptionKey( HttpServletRequest request )
186 {
187 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ENCRYPTIONKEY ) );
188 UrlItem url = new UrlItem( getActionUrl( ACTION_REMOVE_ENCRYPTIONKEY ) );
189 url.addParameter( PARAMETER_ID_ENCRYPTIONKEY, nId );
190
191 String strMessageUrl = AdminMessageService.getMessageUrl( request, MESSAGE_CONFIRM_REMOVE_ENCRYPTIONKEY, url.getUrl( ), AdminMessage.TYPE_CONFIRMATION );
192
193 return redirect( request, strMessageUrl );
194 }
195
196
197
198
199
200
201
202
203 @Action( ACTION_REMOVE_ENCRYPTIONKEY )
204 public String doRemoveEncryptionKey( HttpServletRequest request )
205 {
206 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ENCRYPTIONKEY ) );
207 EncryptionKeyHome.remove( nId );
208 addInfo( INFO_ENCRYPTIONKEY_REMOVED, getLocale( ) );
209
210 return redirectView( request, VIEW_MANAGE_ENCRYPTIONKEYS );
211 }
212
213
214
215
216
217
218
219
220 @View( VIEW_MODIFY_ENCRYPTIONKEY )
221 public String getModifyEncryptionKey( HttpServletRequest request )
222 {
223 int nId = Integer.parseInt( request.getParameter( PARAMETER_ID_ENCRYPTIONKEY ) );
224
225 if ( _encryptionkey == null || ( _encryptionkey.getId( ) != nId ) )
226 {
227 _encryptionkey = EncryptionKeyHome.findByPrimaryKey( nId );
228 }
229
230 Map<String, Object> model = getModel( );
231 model.put( MARK_ENCRYPTIONKEY, _encryptionkey );
232
233 return getPage( PROPERTY_PAGE_TITLE_MODIFY_ENCRYPTIONKEY, TEMPLATE_MODIFY_ENCRYPTIONKEY, model );
234 }
235
236
237
238
239
240
241
242
243 @Action( ACTION_MODIFY_ENCRYPTIONKEY )
244 public String doModifyEncryptionKey( HttpServletRequest request )
245 {
246 populate( _encryptionkey, request );
247
248
249 if ( !validateBean( _encryptionkey, VALIDATION_ATTRIBUTES_PREFIX ) )
250 {
251 return redirect( request, VIEW_MODIFY_ENCRYPTIONKEY, PARAMETER_ID_ENCRYPTIONKEY, _encryptionkey.getId( ) );
252 }
253
254 try
255 {
256 EncryptionKeyHome.update( _encryptionkey );
257 }
258 catch( EncryptionKeyAlreadyExistException e )
259 {
260 addError( ERROR_ENCRYPTIONKEY_ALREADY_EXISTS, getLocale( ) );
261 return redirect( request, VIEW_MODIFY_ENCRYPTIONKEY, PARAMETER_ID_ENCRYPTIONKEY, _encryptionkey.getId( ) );
262 }
263
264 addInfo( INFO_ENCRYPTIONKEY_UPDATED, getLocale( ) );
265
266 return redirectView( request, VIEW_MANAGE_ENCRYPTIONKEYS );
267 }
268 }