View Javadoc
1   /*
2    * Copyright (c) 2002-2021, 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.plugins.ctv.util;
35  
36  import java.lang.reflect.Field;
37  import java.text.MessageFormat;
38  import java.util.ArrayList;
39  import java.util.Arrays;
40  import java.util.HashMap;
41  import java.util.List;
42  import java.util.Map;
43  import java.util.Set;
44  
45  import javax.servlet.http.HttpServletRequest;
46  import javax.validation.ConstraintViolation;
47  
48  import org.apache.commons.logging.Log;
49  import org.apache.commons.logging.LogFactory;
50  
51  import fr.paris.lutece.plugins.ctv.bo.EntiteDemande;
52  import fr.paris.lutece.plugins.ctv.bo.NotNull;
53  import fr.paris.lutece.plugins.ctv.bo.Required;
54  import fr.paris.lutece.portal.service.datastore.DatastoreService;
55  import fr.paris.lutece.portal.service.security.LuteceUser;
56  import fr.paris.lutece.portal.service.security.SecurityService;
57  import fr.paris.lutece.portal.service.security.UserNotSignedException;
58  import fr.paris.lutece.util.beanvalidation.BeanValidationUtil;
59  
60  public class Utils
61  {
62  
63      private static String    PATH_LABEL_KEY       = "sitelabels.site_property.demande.occupation.etape.recapitulatif.erreur.";
64      private static String    PATH_LABEL_KEY_CHAMP = ".champ.";
65  
66      private final static Log LOGGER               = LogFactory.getLog( Utils.class );
67  
68      public static void controlRequiredFields( String key, Object objectToControl, HashMap<String, List<String>> requiredFielsInError )
69      {
70          if ( objectToControl != null )
71          {
72              List<String> requiredFieldsNameInError = new ArrayList<String>( );
73              Class<?> class1 = objectToControl.getClass( );
74              List<Field> fieldList = new ArrayList<Field>( );
75  
76              fieldList = getAllFields( fieldList, class1 );
77  
78              // fieldList.addAll(Arrays.asList(class1.getSuperclass().getDeclaredFields()));
79              // fieldList.addAll(Arrays.asList(class1.getDeclaredFields()));
80  
81              for ( Field field : fieldList )
82              {
83                  if ( field.isAnnotationPresent( Required.class ) )
84                  {
85                      Required annotationRequired = field.getAnnotation( Required.class );
86                      String conditionalPropertyName = annotationRequired.conditionalPropertyName( );
87                      if ( !"".equals( conditionalPropertyName ) )
88                      {
89                          controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, Required.class );
90                      } else
91                      {
92                          control( objectToControl, field, requiredFieldsNameInError, Required.class );
93                      }
94                  } else if ( field.isAnnotationPresent( NotNull.class ) )
95                  {
96                      NotNull annotationNotNull = field.getAnnotation( NotNull.class );
97                      String conditionalPropertyName = annotationNotNull.conditionalPropertyName( );
98                      if ( !"".equals( conditionalPropertyName ) )
99                      {
100                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, NotNull.class );
101                     } else
102                     {
103                         control( objectToControl, field, requiredFieldsNameInError, NotNull.class );
104                     }
105 
106                 }
107             }
108             if ( !requiredFieldsNameInError.isEmpty( ) )
109             {
110                 requiredFielsInError.put( key, requiredFieldsNameInError );
111             }
112         }
113     }
114 
115     public static void controlRequiredFieldsIntExecutant( String key, Object objectToControl, HashMap<String, List<String>> requiredFielsInError )
116     {
117         if ( objectToControl != null )
118         {
119             List<String> requiredFieldsNameInError = new ArrayList<String>( );
120             Class<?> class1 = objectToControl.getClass( );
121             List<Field> fieldList = new ArrayList<Field>( );
122 
123             fieldList = getAllFields( fieldList, class1 );
124 
125             // fieldList.addAll(Arrays.asList(class1.getSuperclass().getDeclaredFields()));
126             // fieldList.addAll(Arrays.asList(class1.getDeclaredFields()));
127 
128             for ( Field field : fieldList )
129             {
130 
131                 if ( field.isAnnotationPresent( Required.class ) )
132                 {
133                     if ( ( field.getName( ) == "contactCourrielConnexion" ) || ( field.getName( ) == "formeJuridique" ) || ( field.getName( ) == "siegeSocial" )
134                             || ( field.getName( ) == "reprensentantLieuNaissance" ) || ( field.getName( ) == "reprensentantDateNaissance" ) )
135                     {
136                         continue;
137                     }
138                     Required annotationRequired = field.getAnnotation( Required.class );
139                     String conditionalPropertyName = annotationRequired.conditionalPropertyName( );
140                     if ( !"".equals( conditionalPropertyName ) )
141                     {
142                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, Required.class );
143                     } else
144                     {
145                         control( objectToControl, field, requiredFieldsNameInError, Required.class );
146                     }
147                 } else if ( field.isAnnotationPresent( NotNull.class ) )
148                 {
149                     NotNull annotationNotNull = field.getAnnotation( NotNull.class );
150                     String conditionalPropertyName = annotationNotNull.conditionalPropertyName( );
151                     if ( !"".equals( conditionalPropertyName ) )
152                     {
153                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, NotNull.class );
154                     } else
155                     {
156                         control( objectToControl, field, requiredFieldsNameInError, NotNull.class );
157                     }
158 
159                 }
160             }
161             if ( !requiredFieldsNameInError.isEmpty( ) )
162             {
163 
164                 requiredFielsInError.put( key, requiredFieldsNameInError );
165             }
166         }
167     }
168 
169     public static void controlRequiredFieldsIntDemandeur( String key, Object objectToControl, HashMap<String, List<String>> requiredFielsInError )
170     {
171         if ( objectToControl != null )
172         {
173             List<String> requiredFieldsNameInError = new ArrayList<String>( );
174             Class<?> class1 = objectToControl.getClass( );
175             List<Field> fieldList = new ArrayList<Field>( );
176 
177             fieldList = getAllFields( fieldList, class1 );
178 
179             // fieldList.addAll(Arrays.asList(class1.getSuperclass().getDeclaredFields()));
180             // fieldList.addAll(Arrays.asList(class1.getDeclaredFields()));
181 
182             for ( Field field : fieldList )
183             {
184 
185                 if ( field.isAnnotationPresent( Required.class ) )
186                 {
187                     if ( ( field.getName( ) == "contactCourrielConnexion" ) || ( field.getName( ) == "formeJuridique" ) || ( field.getName( ) == "siegeSocial" ) )
188                     {
189                         continue;
190                     }
191 
192                     Required annotationRequired = field.getAnnotation( Required.class );
193                     String conditionalPropertyName = annotationRequired.conditionalPropertyName( );
194                     if ( !"".equals( conditionalPropertyName ) )
195                     {
196                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, Required.class );
197                     } else
198                     {
199                         control( objectToControl, field, requiredFieldsNameInError, Required.class );
200                     }
201                 } else if ( field.isAnnotationPresent( NotNull.class ) )
202                 {
203                     NotNull annotationNotNull = field.getAnnotation( NotNull.class );
204                     String conditionalPropertyName = annotationNotNull.conditionalPropertyName( );
205                     if ( !"".equals( conditionalPropertyName ) )
206                     {
207                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, NotNull.class );
208                     } else
209                     {
210                         control( objectToControl, field, requiredFieldsNameInError, NotNull.class );
211                     }
212 
213                 }
214             }
215             if ( !requiredFieldsNameInError.isEmpty( ) )
216             {
217 
218                 requiredFielsInError.put( key, requiredFieldsNameInError );
219             }
220         }
221     }
222 
223     public static void controlRequiredFieldsOccupationExecutant( String key, Object objectToControl, HashMap<String, List<String>> requiredFielsInError )
224     {
225         if ( objectToControl != null )
226         {
227             List<String> requiredFieldsNameInError = new ArrayList<String>( );
228             Class<?> class1 = objectToControl.getClass( );
229             List<Field> fieldList = new ArrayList<Field>( );
230 
231             fieldList = getAllFields( fieldList, class1 );
232 
233             // fieldList.addAll(Arrays.asList(class1.getSuperclass().getDeclaredFields()));
234             // fieldList.addAll(Arrays.asList(class1.getDeclaredFields()));
235 
236             for ( Field field : fieldList )
237             {
238                 if ( ( field.getName( ) == "contactCourrielConnexion" ) || ( field.getName( ) == "reprensentantLieuNaissance" ) || ( field.getName( ) == "reprensentantDateNaissance" ) || ( field.getName( ) == "raisonSociale" ) )
239                 {
240                     continue;
241                 }
242                 if ( field.isAnnotationPresent( Required.class ) )
243                 {
244                     Required annotationRequired = field.getAnnotation( Required.class );
245                     String conditionalPropertyName = annotationRequired.conditionalPropertyName( );
246                     if ( !"".equals( conditionalPropertyName ) )
247                     {
248                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, Required.class );
249                     } else
250                     {
251                         control( objectToControl, field, requiredFieldsNameInError, Required.class );
252                     }
253                 } else if ( field.isAnnotationPresent( NotNull.class ) )
254                 {
255                     NotNull annotationNotNull = field.getAnnotation( NotNull.class );
256                     String conditionalPropertyName = annotationNotNull.conditionalPropertyName( );
257                     if ( !"".equals( conditionalPropertyName ) )
258                     {
259                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, NotNull.class );
260                     } else
261                     {
262                         control( objectToControl, field, requiredFieldsNameInError, NotNull.class );
263                     }
264 
265                 }
266             }
267             if ( !requiredFieldsNameInError.isEmpty( ) )
268             {
269 
270                 requiredFielsInError.put( key, requiredFieldsNameInError );
271             }
272         }
273     }
274 
275     public static void controlRequiredFieldsOccupationDemandeur( String key, Object objectToControl, HashMap<String, List<String>> requiredFielsInError )
276     {
277         if ( objectToControl != null )
278         {
279             List<String> requiredFieldsNameInError = new ArrayList<String>( );
280             Class<?> class1 = objectToControl.getClass( );
281             List<Field> fieldList = new ArrayList<Field>( );
282 
283             fieldList = getAllFields( fieldList, class1 );
284 
285             // fieldList.addAll(Arrays.asList(class1.getSuperclass().getDeclaredFields()));
286             // fieldList.addAll(Arrays.asList(class1.getDeclaredFields()));
287 
288             for ( Field field : fieldList )
289             {
290 
291                 if ( field.isAnnotationPresent( Required.class ) )
292                 {
293                     if ( "raisonSociale".equals(field.getName( ) ) )
294                     {
295                         continue;
296                     }
297                     Required annotationRequired = field.getAnnotation( Required.class );
298                     String conditionalPropertyName = annotationRequired.conditionalPropertyName( );
299                     if ( !"".equals( conditionalPropertyName ) )
300                     {
301                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, Required.class );
302                     } else
303                     {
304                         control( objectToControl, field, requiredFieldsNameInError, Required.class );
305                     }
306                 } else if ( field.isAnnotationPresent( NotNull.class ) )
307                 {
308                     NotNull annotationNotNull = field.getAnnotation( NotNull.class );
309                     String conditionalPropertyName = annotationNotNull.conditionalPropertyName( );
310                     if ( !"".equals( conditionalPropertyName ) )
311                     {
312                         controlConditionnal( objectToControl, requiredFieldsNameInError, class1, field, conditionalPropertyName, NotNull.class );
313                     } else
314                     {
315                         control( objectToControl, field, requiredFieldsNameInError, NotNull.class );
316                     }
317 
318                 }
319             }
320             if ( !requiredFieldsNameInError.isEmpty( ) )
321             {
322 
323                 requiredFielsInError.put( key, requiredFieldsNameInError );
324             }
325         }
326     }
327 
328     private static void controlConditionnal( Object objectToControl, List<String> requiredFieldsNameInError, Class<?> class1, Field field, String conditionalPropertyName, Class<?> annotationClass )
329     {
330         String conditionalPropertyValue = "";
331         if ( annotationClass.equals( Required.class ) )
332         {
333             Required annotationRequired = field.getAnnotation( Required.class );
334             conditionalPropertyValue = annotationRequired.conditionalPropertyValue( );
335         } else if ( annotationClass.equals( NotNull.class ) )
336         {
337             NotNull annotationRequired = field.getAnnotation( NotNull.class );
338             conditionalPropertyValue = annotationRequired.conditionalPropertyValue( );
339         }
340         boolean hasClassChild = false;
341 
342         String[] fields = conditionalPropertyName.split( "\\." );
343         String conditionalPropertyNameClassChild = null;
344         if ( ( fields != null ) && ( fields.length > 1 ) )
345         {
346             conditionalPropertyNameClassChild = fields[0];
347             hasClassChild = true;
348         }
349 
350         Field fieldConditionnal = getField( class1, hasClassChild ? conditionalPropertyNameClassChild : conditionalPropertyName );
351         Object fieldConditionalValue = getFieldValue( objectToControl, fieldConditionnal );
352 
353         if ( hasClassChild )
354         {
355             fieldConditionnal = getField( fieldConditionnal.getType( ), fields[1] );
356             fieldConditionalValue = getFieldValue( fieldConditionalValue, fieldConditionnal );
357         }
358 
359         if ( ( fieldConditionnal != null ) && fieldConditionnal.getType( ).equals( Map.class ) )
360         {
361             if ( fieldConditionalValue != null )
362             {
363                 Map fieldConditionalValueMap = ( Map ) fieldConditionalValue;
364                 List<String> keys = new ArrayList<String>( );
365                 for ( Object key : fieldConditionalValueMap.keySet( ) )
366                 {
367                     keys.add( key.toString( ) );
368                 }
369                 if ( keys.contains( conditionalPropertyValue ) )
370                 {
371                     control( objectToControl, field, requiredFieldsNameInError, annotationClass );
372                 }
373             }
374         } else
375         {
376             if ( fieldConditionalValue == null )
377             {
378                 fieldConditionalValue = "";
379             }
380             if ( conditionalPropertyValue.equals( fieldConditionalValue.toString( ) ) )
381             {
382                 control( objectToControl, field, requiredFieldsNameInError, annotationClass );
383             }
384         }
385     }
386 
387     private static void control( Object objectToControl, Field field, List<String> requiredFieldsNameInError, Class<?> annotationClass )
388     {
389         Object fieldValue = getFieldValue( objectToControl, field );
390 
391         if ( annotationClass.equals( Required.class ) )
392         {
393             if ( fieldValue == null )
394             {
395                 requiredFieldsNameInError.add( field.getName( ) );
396             } else if ( field.getType( ).equals( String.class ) )
397             {
398                 String fieldValueString = ( String ) fieldValue;
399                 if ( "".equals( fieldValueString.trim( ) ) )
400                 {
401                     requiredFieldsNameInError.add( field.getName( ) );
402                 }
403             } else if ( field.getType( ).equals( Double.class ) )
404             {
405                 Double fieldValueDouble = ( Double ) fieldValue;
406                 if ( fieldValueDouble <= 0 )
407                 {
408                     requiredFieldsNameInError.add( field.getName( ) );
409                 }
410             }
411         } else if ( annotationClass.equals( NotNull.class ) )
412         {
413             if ( fieldValue == null )
414             {
415                 requiredFieldsNameInError.add( field.getName( ) );
416             } else if ( field.getType( ).equals( Double.class ) )
417             {
418                 Double fieldValueDouble = ( Double ) fieldValue;
419                 if ( fieldValueDouble < 0 )
420                 {
421                     requiredFieldsNameInError.add( field.getName( ) );
422                 }
423             }
424         }
425 
426     }
427 
428     private static Object getFieldValue( Object object, Field field )
429     {
430         Object fieldConditionalValue = null;
431         if ( ( object != null ) && ( field != null ) )
432         {
433             try
434             {
435                 field.setAccessible( true );
436                 fieldConditionalValue = field.get( object );
437                 field.setAccessible( false );
438             } catch ( IllegalArgumentException | IllegalAccessException e )
439             {
440                 fieldConditionalValue = null;
441             }
442         }
443         return fieldConditionalValue;
444     }
445 
446     private static Field getField( Class<?> class1, String conditionalPropertyName )
447     {
448         Field field = null;
449         boolean hasError = false;
450         try
451         {
452             field = class1.getDeclaredField( conditionalPropertyName );
453         } catch ( NoSuchFieldException | SecurityException e )
454         {
455             hasError = true;
456         }
457         if ( hasError )
458         {
459             try
460             {
461                 field = class1.getSuperclass( ).getDeclaredField( conditionalPropertyName );
462             } catch ( NoSuchFieldException | SecurityException e1 )
463             {
464                 LOGGER.info( e1 );
465             }
466         }
467         return field;
468     }
469 
470     /**
471      * Vérification des champs d'un bean, selon le group de vérification défini
472      *
473      * @param key
474      * @param objectToControl
475      * @param fieldsInError
476      * @param validationGroup
477      */
478     public static <T> void checkFields( String key, T objectToControl, Map<String, Map<String, String>> fieldsInError, Class<?> validationGroup, List<Object> msgArgs )
479     {
480         if ( null != objectToControl )
481         {
482             if ( null == msgArgs )
483             {
484                 msgArgs = new ArrayList<>( );
485             }
486             Map<String, String> errorsList = new HashMap<>( );
487             Set<ConstraintViolation<T>> errors = BeanValidationUtil.getValidator( ).validate( objectToControl, validationGroup );
488             for ( ConstraintViolation<T> constraint : errors )
489             {
490                 String property = constraint.getPropertyPath( ).toString( );
491                 String message = constraint.getMessage( );
492                 message = DatastoreService.replaceKeys( message );
493                 // Récupération du libellé du champ
494                 String attributeLabel = getAttributeLabel( key, property );
495                 Object maxProperty = constraint.getConstraintDescriptor( ).getAttributes( ).get( "max" );
496                 // Remplacement des variables
497                 if ( null != maxProperty )
498                 {
499                     msgArgs.add( 0, attributeLabel );
500                     msgArgs.add( 1, maxProperty );
501                 }
502                 if ( !msgArgs.isEmpty( ) )
503                 {
504                     Object[] args = msgArgs.toArray( );
505                     message = MessageFormat.format( message, args );
506                 }
507                 errorsList.put( constraint.getPropertyPath( ).toString( ), message );
508             }
509             if ( !errorsList.isEmpty( ) )
510             {
511                 fieldsInError.put( key, errorsList );
512             }
513         }
514     }
515 
516     public static void checkFieldsOccuption( String key, EntiteDemande objectToControl, Map<String, Map<String, String>> fieldsInError, Class<?> validationGroup, List<Object> msgArgs )
517     {
518         if ( null != objectToControl )
519         {
520 
521             if ( null == msgArgs )
522             {
523                 msgArgs = new ArrayList<>( );
524             }
525             Map<String, String> errorsList = new HashMap<>( );
526             Set<ConstraintViolation<EntiteDemande>> errors = BeanValidationUtil.getValidator( ).validate( objectToControl, validationGroup );
527             for ( ConstraintViolation<EntiteDemande> constraint : errors )
528             {
529 
530                 String property = constraint.getPropertyPath( ).toString( );
531                 String message = constraint.getMessage( );
532                 boolean messageEquals = "#dskey{sitelabels.site_property.formulaire.lieuNaissance.format}".equals( message );
533                 boolean lieuEquals = "".equals( objectToControl.getReprensentantLieuNaissance( ) );
534                 if ( messageEquals  && lieuEquals  )
535                 {
536                     continue;
537                 }
538                 message = DatastoreService.replaceKeys( message );
539                 // Récupération du libellé du champ
540                 String attributeLabel = getAttributeLabel( key, property );
541 
542                 Object maxProperty = constraint.getConstraintDescriptor( ).getAttributes( ).get( "max" );
543                 // Remplacement des variables
544                 if ( null != maxProperty )
545                 {
546                     msgArgs.add( 0, attributeLabel );
547                     msgArgs.add( 1, maxProperty );
548                 }
549                 if ( !msgArgs.isEmpty( ) )
550                 {
551                     Object[] args = msgArgs.toArray( );
552                     message = MessageFormat.format( message, args );
553                 }
554                 errorsList.put( constraint.getPropertyPath( ).toString( ), message );
555             }
556             if ( !errorsList.isEmpty( ) )
557             {
558                 fieldsInError.put( key, errorsList );
559             }
560         }
561     }
562 
563     public static void insertRequiredErrors( Map<String, Map<String, String>> emprisesInError, HashMap<String, List<String>> requiredFielsEmprisesInError )
564     {
565         if ( !requiredFielsEmprisesInError.isEmpty( ) )
566         {
567             for ( String key : requiredFielsEmprisesInError.keySet( ) )
568             {
569                 String num = key.split( "_" )[1];
570                 Map<String, String> map = emprisesInError.get( num );
571                 if ( map == null )
572                 {
573                     emprisesInError.put( num, new HashMap<String, String>( ) );
574                     map = emprisesInError.get( num );
575                 }
576                 List<String> filedsNames = requiredFielsEmprisesInError.get( key );
577                 for ( String fieldName : filedsNames )
578                 {
579                     map.put( fieldName, getAttributeLabel( "emprises", fieldName ) );
580                 }
581             }
582         }
583     }
584 
585     /**
586      * Récupère le label du champ en fonction de l'étape et du nom de l'attribut
587      *
588      * @param key
589      * @param property
590      * @return
591      */
592     private static String getAttributeLabel( String key, String property )
593     {
594         String dsKey = PATH_LABEL_KEY + key + PATH_LABEL_KEY_CHAMP + property;
595         String attributeLabel = DatastoreService.getDataValue( dsKey, "" );
596         if ( null == attributeLabel )
597         {
598             attributeLabel = "";
599         }
600         return attributeLabel;
601     }
602 
603     public static LuteceUser getUser( HttpServletRequest request ) throws UserNotSignedException
604     {
605         return getUser( request, true );
606     }
607 
608     /**
609      * Return authified user throw exception if requestAuthent=true null otherwise.
610      *
611      * @param request
612      *            http request
613      * @param requestAuthent
614      *            {@link Boolean}
615      * @return user lutece
616      * @throws UserNotSignedException
617      *             if the user is not logged in
618      */
619     protected static LuteceUser getUser( HttpServletRequest request, boolean requestAuthent ) throws UserNotSignedException
620     {
621         LuteceUser user = null;
622         if ( SecurityService.isAuthenticationEnable( ) )
623         {
624             user = SecurityService.getInstance( ).getRemoteUser( request );
625             if ( requestAuthent && ( user == null ) )
626             {
627                 throw new UserNotSignedException( );
628             }
629         }
630         return user;
631 
632     }
633 
634     /**
635      * recursive method that gets all the field from super class
636      *
637      * @param fields
638      * @param type
639      * @return
640      */
641     public static List<Field> getAllFields( List<Field> fields, Class<?> type )
642     {
643         fields.addAll( Arrays.asList( type.getDeclaredFields( ) ) );
644 
645         if ( type.getSuperclass( ) != null )
646         {
647             fields = getAllFields( fields, type.getSuperclass( ) );
648         }
649 
650         return fields;
651     }
652 
653 }