View Javadoc
1   /*
2    * Copyright (c) 2002-2022, 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.genericattributes.service.entrytype;
35  
36  import java.util.List;
37  import java.util.Locale;
38  
39  import javax.servlet.http.HttpServletRequest;
40  
41  import fr.paris.lutece.plugins.genericattributes.business.Entry;
42  import fr.paris.lutece.plugins.genericattributes.business.GenericAttributeError;
43  import fr.paris.lutece.plugins.genericattributes.business.Response;
44  import fr.paris.lutece.portal.service.i18n.I18nService;
45  import fr.paris.lutece.portal.service.plugin.Plugin;
46  import fr.paris.lutece.portal.service.security.LuteceUser;
47  import fr.paris.lutece.portal.service.security.SecurityService;
48  import fr.paris.lutece.portal.service.security.UserNotSignedException;
49  import fr.paris.lutece.portal.service.util.AppLogService;
50  import fr.paris.lutece.util.ReferenceList;
51  
52  /**
53   * Abstract entry type for MyLutece users
54   */
55  public abstract class AbstractEntryTypeMyLuteceUser extends EntryTypeService
56  {
57      private static final String PROPERTY_ENTRY_TITLE = "genericattributes.entryTypeMyLuteceUser.title";
58      private static final String EMPTY_STRING = "";
59  
60      /**
61       * {@inheritDoc}
62       */
63      @Override
64      public String getTemplateCreate( Entry entry, boolean bDisplayFront )
65      {
66          return null;
67      }
68  
69      /**
70       * {@inheritDoc}
71       */
72      @Override
73      public String getTemplateModify( Entry entry, boolean bDisplayFront )
74      {
75          return null;
76      }
77  
78      /**
79       * {@inheritDoc}
80       */
81      @Override
82      public String getRequestData( Entry entry, HttpServletRequest request, Locale locale )
83      {
84          initCommonRequestData( entry, request );
85          String strIndexed = request.getParameter( PARAMETER_INDEXED );
86  
87          entry.setTitle( I18nService.getLocalizedString( PROPERTY_ENTRY_TITLE, locale ) );
88  
89          String strCode = request.getParameter( PARAMETER_ENTRY_CODE );
90          entry.setHelpMessage( EMPTY_STRING );
91          entry.setComment( EMPTY_STRING );
92          entry.setIndexed( strIndexed != null );
93  
94          entry.setCode( strCode );
95          return null;
96      }
97  
98      /**
99       * {@inheritDoc}
100      */
101     @Override
102     public ReferenceList getReferenceListRegularExpression( Entry entry, Plugin plugin )
103     {
104         return null;
105     }
106 
107     /**
108      * {@inheritDoc}
109      */
110     @Override
111     public GenericAttributeError getResponseData( Entry entry, HttpServletRequest request, List<Response> listResponse, Locale locale )
112     {
113         LuteceUser user = SecurityService.getInstance( ).getRegisteredUser( request );
114 
115         if ( SecurityService.isAuthenticationEnable( ) && SecurityService.getInstance( ).isExternalAuthentication( ) && user == null )
116         {
117             try
118             {
119                 user = SecurityService.getInstance( ).getRemoteUser( request );
120             }
121             catch( UserNotSignedException e )
122             {
123                 AppLogService.error( e.getMessage( ), e );
124             }
125         }
126 
127         if ( user == null )
128         {
129             GenericAttributeErrortributes/business/GenericAttributeError.html#GenericAttributeError">GenericAttributeError error = new GenericAttributeError( );
130             error.setMandatoryError( false );
131             error.setTitleQuestion( entry.getTitle( ) );
132             error.setErrorMessage( I18nService.getLocalizedString( MESSAGE_MYLUTECE_AUTHENTIFICATION_REQUIRED, request.getLocale( ) ) );
133 
134             return error;
135         }
136 
137         Response/genericattributes/business/Response.html#Response">Response response = new Response( );
138         response.setEntry( entry );
139         response.setResponseValue( user.getName( ) );
140         response.setIterationNumber( getResponseIterationValue( request ) );
141 
142         listResponse.add( response );
143 
144         return null;
145     }
146 
147     /**
148      * {@inheritDoc}
149      */
150     @Override
151     public String getResponseValueForExport( Entry entry, HttpServletRequest request, Response response, Locale locale )
152     {
153         return response.getResponseValue( );
154     }
155 
156     /**
157      * {@inheritDoc}
158      */
159     @Override
160     public String getResponseValueForRecap( Entry entry, HttpServletRequest request, Response response, Locale locale )
161     {
162         return null;
163     }
164 }