View Javadoc
1   /*
2    * Copyright (c) 2002-2017, Mairie de 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  
35  package fr.paris.lutece.plugins.appcenter.modules.openam.web;
36  
37  import java.util.Map;
38  
39  import javax.servlet.http.HttpServletRequest;
40  
41  import fr.paris.lutece.plugins.appcenter.business.Application;
42  import fr.paris.lutece.plugins.appcenter.business.Environment;
43  import fr.paris.lutece.plugins.appcenter.modules.openam.business.OpenamAgentsData;
44  import fr.paris.lutece.plugins.appcenter.modules.openam.business.OpenamDemand;
45  import fr.paris.lutece.plugins.appcenter.service.ApplicationService;
46  import fr.paris.lutece.plugins.appcenter.service.DemandService;
47  import fr.paris.lutece.plugins.appcenter.service.UserService;
48  import fr.paris.lutece.plugins.appcenter.web.AppCenterDemandXPage;
49  import fr.paris.lutece.plugins.appcenter.web.Constants;
50  import static fr.paris.lutece.plugins.appcenter.web.Constants.MARK_USER;
51  import fr.paris.lutece.portal.service.admin.AccessDeniedException;
52  import fr.paris.lutece.portal.service.message.SiteMessageException;
53  import fr.paris.lutece.portal.service.security.UserNotSignedException;
54  import fr.paris.lutece.portal.util.mvc.commons.annotations.Action;
55  import fr.paris.lutece.portal.util.mvc.commons.annotations.View;
56  import fr.paris.lutece.portal.util.mvc.xpage.annotations.Controller;
57  import fr.paris.lutece.portal.web.xpages.XPage;
58  
59  /**
60   * SourcesXPage
61   */
62  @Controller( xpageName = "openam", pageTitleI18nKey = "module.appcenter.openam.xpage.openam.pageTitle", pagePathI18nKey = "module.appcenter.openam.xpage.openam.pagePathLabel" )
63  public class OpenamAgentsXPage extends AppCenterDemandXPage
64  {
65      // Templates
66      private static final String TEMPLATE_MANAGE_AGENTS = "/skin/plugins/appcenter/modules/openam/manage_openam_agents.html";
67  
68      // VIEW
69      private static final String VIEW_MANAGE_AGENTS = "manageagents";
70  
71      // ACTION
72      private static final String ACTION_ADD_AGENT = "addAgent";
73      
74          //Permissions
75      private static final String PERMISSION_VIEW_OPENAM_DEMANDS = "PERMISSION_VIEW_OPENAM_DEMANDS";
76      private static final String PERMISSION_CREATE_OPENAM_DEMAND = "PERMISSION_CREATE_OPENAM_DEMAND";
77      
78      @View( value = VIEW_MANAGE_AGENTS, defaultView = true )
79      public XPage getManageAgents( HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
80      {
81          try
82          {
83              checkPermission( request, PERMISSION_VIEW_OPENAM_DEMANDS, getActiveEnvironment( request).getPrefix( ) );
84          }
85          catch ( AccessDeniedException e )
86          {
87              getUnauthorizedAccessMessage( request );
88          }
89          Map<String, Object> model = getModel( );
90          fillAppCenterCommons( model, request );
91          fillDisplayPermission( model, request, PERMISSION_CREATE_OPENAM_DEMAND , getActiveEnvironment( request).getPrefix( ) );
92  
93          return getXPage( TEMPLATE_MANAGE_AGENTS, request.getLocale( ), model );
94      }
95  
96      @Action( ACTION_ADD_AGENT )
97      public XPage doAddAgent( HttpServletRequest request ) throws UserNotSignedException, SiteMessageException
98      {
99          try
100         {
101             checkPermission( request, PERMISSION_CREATE_OPENAM_DEMAND, getActiveEnvironment( request).getPrefix( ) );
102         }
103         catch ( AccessDeniedException e )
104         {
105             getUnauthorizedAccessMessage( request );
106         }
107         
108         int nId = Integer.parseInt( request.getParameter(Constants.PARAM_ID_APPLICATION ) );
109 
110         OpenamDemandcenter/modules/openam/business/OpenamDemand.html#OpenamDemand">OpenamDemand agentDemand = new OpenamDemand( );
111         agentDemand.setIdApplication( _application.getId( ) );
112 
113         populate( agentDemand, request );
114         // Check constraints
115         if ( !validateBean( agentDemand, getLocale( request ) ) )
116         {
117             return redirectView( request, VIEW_MANAGE_AGENTS );
118         }
119 
120         DemandService.saveDemand( agentDemand, _application );
121 
122         return redirect(request, VIEW_MANAGE_AGENTS, Constants.PARAM_ID_APPLICATION, nId );
123     }
124 
125     @Override
126     protected String getDemandType()
127     {
128         return OpenamDemand.DEMAND_TYPE;
129     }
130 
131     @Override
132     protected Class getDemandClass()
133     {
134         return OpenamDemand.class;
135     }
136 
137     @Override
138     protected String getDatasName()
139     {
140         return OpenamAgentsData.DATA_OPENAM_AGENTS_NAME;
141     }
142 
143     @Override
144     protected Class getDatasClass()
145     {
146         return OpenamAgentsData.class;
147     }
148 
149 }