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.paybox.web;
35
36 import java.io.IOException;
37 import java.util.List;
38
39 import javax.servlet.ServletException;
40 import javax.servlet.http.HttpServlet;
41 import javax.servlet.http.HttpServletRequest;
42 import javax.servlet.http.HttpServletResponse;
43
44 import fr.paris.lutece.plugins.paybox.PayboxUtil;
45 import fr.paris.lutece.plugins.paybox.service.PayboxLogService;
46 import fr.paris.lutece.plugins.paybox.service.PayboxPlugin;
47 import fr.paris.lutece.plugins.paybox.service.PayboxService;
48 import fr.paris.lutece.portal.service.plugin.PluginService;
49 import fr.paris.lutece.portal.service.spring.SpringContextService;
50 import fr.paris.lutece.portal.service.util.AppLogService;
51 import fr.paris.lutece.portal.service.util.AppPropertiesService;
52
53
54
55
56
57 public class PayboxServlet extends HttpServlet
58 {
59
60 private static final long serialVersionUID = 1L;
61
62
63 private final PayboxLogService _payboxLogService = SpringContextService.getBean( "paybox.payboxLogService" );
64
65
66
67
68
69
70
71
72 @Override
73 protected void doGet( final HttpServletRequest req, final HttpServletResponse resp )
74 throws ServletException, IOException
75 {
76 this.doPost( req, resp );
77 }
78
79
80
81
82
83
84
85
86 @Override
87 protected void doPost( final HttpServletRequest request, final HttpServletResponse response )
88 throws ServletException, IOException
89 {
90 if ( !AppPropertiesService.getPropertyBoolean( "paybox.check.sign.callback", true )
91 || PayboxUtil.checkSignature( request.getQueryString( ) ) )
92 {
93
94 this._payboxLogService.removeLog( request.getParameter( "reference" ),
95 PluginService.getPlugin( PayboxPlugin.PLUGIN_NAME ) );
96
97 this.delagate( request, response );
98 }
99 else
100 {
101 AppLogService.error( "Problème de vérification de la signature." );
102 }
103
104 response.setStatus( 200 );
105 }
106
107
108
109
110
111
112
113 private void delagate( final HttpServletRequest request, final HttpServletResponse response )
114 {
115
116 final List<PayboxService> listPayboxServices = SpringContextService.getBeansOfType( PayboxService.class );
117
118 if ( ( listPayboxServices == null ) || listPayboxServices.isEmpty( ) )
119 {
120 AppLogService.error( "No PayboxService bean defined. Please check your Spring configuration." );
121 }
122 else if ( listPayboxServices.size( ) > 1 )
123 {
124 AppLogService.error( "Multiple PayboxService beans defined. Please check your Spring configuration." );
125 }
126 else
127 {
128 final PayboxService payboxService = listPayboxServices.get( 0 );
129 AppLogService.debug( "Using " + payboxService.getClass( ) + " as PayboxService" );
130
131 try
132 {
133 payboxService.handlePayboxReturn( request, response );
134 }
135 catch ( final Exception e )
136 {
137 AppLogService.error( e );
138 }
139 }
140 }
141 }