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.portal.service.accesscontrol;
35
36 import java.util.Locale;
37
38 import javax.servlet.http.HttpServletRequest;
39
40 import org.springframework.beans.factory.BeanDefinitionStoreException;
41 import org.springframework.beans.factory.CannotLoadBeanClassException;
42 import org.springframework.beans.factory.NoSuchBeanDefinitionException;
43
44 import fr.paris.lutece.api.user.User;
45 import fr.paris.lutece.portal.business.accesscontrol.AccessControlSessionData;
46 import fr.paris.lutece.portal.service.plugin.PluginService;
47 import fr.paris.lutece.portal.service.spring.SpringContextService;
48 import fr.paris.lutece.portal.web.xpages.XPage;
49 import fr.paris.lutece.util.ReferenceList;
50
51
52
53
54 public final class AccessControlService
55 {
56 private static AccessControlService _singleton;
57 private boolean _bServiceAvailable = true;
58 private IAccessControlServiceProvider _provider;
59
60
61
62
63 private AccessControlService( )
64 {
65 try
66 {
67 _provider = SpringContextService.getBean( "accesscontrol.accessControlServiceProvider" );
68 _bServiceAvailable = ( _provider != null );
69 }
70 catch( CannotLoadBeanClassException | NoSuchBeanDefinitionException | BeanDefinitionStoreException e )
71 {
72 _bServiceAvailable = false;
73 }
74 }
75
76
77
78
79
80
81
82
83
84
85 public boolean isAvailable( )
86 {
87 return _bServiceAvailable && ( _provider != null ) && PluginService.isPluginEnable( "accesscontrol" );
88 }
89
90
91
92
93
94
95 public static synchronized AccessControlService getInstance( )
96 {
97 if ( _singleton == null )
98 {
99 _singleton = new AccessControlService( );
100 }
101 return _singleton;
102 }
103
104
105
106
107
108
109
110
111
112
113 public ReferenceList getAccessControlsEnabled( User user, Locale locale )
114 {
115 return isAvailable( ) ? _provider.getAccessControlsEnabled( user, locale ) : null;
116 }
117
118
119
120
121
122
123
124
125 public int findAccessControlForResource( int idResource, String resourceType )
126 {
127 return isAvailable( ) ? _provider.findAccessControlForResource( idResource, resourceType ) : -1;
128 }
129
130
131
132
133
134
135
136
137
138 public void linkResourceToAccessControl( int idResource, String resourceType, int idAccessControl )
139 {
140 if ( isAvailable( ) )
141 {
142 _provider.createOrUpdateAccessControlResource( idResource, resourceType, idAccessControl );
143 }
144 }
145
146
147
148
149
150
151
152
153
154 public XPage doExecuteAccessControl( HttpServletRequest request, int idResource, String resourceType, Object destination )
155 {
156 if ( isAvailable( ) )
157 {
158 int idAccessControl = findAccessControlForResource( idResource, resourceType );
159 if ( idAccessControl != -1 )
160 {
161 AccessControlSessionData sessionData = _provider.getSessionDataForResource( request, idResource, resourceType );
162 if ( sessionData == null || !sessionData.isAccessControlResult( ) )
163 {
164 return _provider.redirectToAccessControlXPage( request, idResource, resourceType, idAccessControl );
165 }
166 if ( sessionData.isAccessControlResult( ) )
167 {
168 _provider.applyPersistentData( sessionData, destination );
169 }
170 }
171 }
172 return null;
173 }
174
175
176
177
178
179
180
181
182 public void cleanSessionData( HttpServletRequest request, int idResource, String resourceType )
183 {
184 if ( isAvailable( ) )
185 {
186 _provider.deleteSessionDataForResource( request, idResource, resourceType );
187 }
188 }
189 }