9 |
9 |
|
10 |
10 |
package eu.etaxonomy.cdm.api.application;
|
11 |
11 |
|
|
12 |
import java.util.ArrayList;
|
|
13 |
import java.util.Arrays;
|
|
14 |
import java.util.HashMap;
|
|
15 |
import java.util.List;
|
|
16 |
import java.util.Map;
|
|
17 |
|
12 |
18 |
import org.apache.log4j.Logger;
|
13 |
19 |
import org.springframework.beans.BeansException;
|
14 |
20 |
import org.springframework.context.ApplicationContext;
|
15 |
21 |
import org.springframework.context.ApplicationContextAware;
|
|
22 |
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
|
|
23 |
import org.springframework.remoting.httpinvoker.HttpInvokerRequestExecutor;
|
|
24 |
import org.springframework.security.access.AccessDecisionVoter;
|
|
25 |
import org.springframework.security.authentication.AuthenticationProvider;
|
16 |
26 |
import org.springframework.security.authentication.ProviderManager;
|
17 |
27 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
|
28 |
import org.springframework.security.authentication.dao.DaoAuthenticationProvider;
|
|
29 |
import org.springframework.security.authentication.dao.ReflectionSaltSource;
|
|
30 |
import org.springframework.security.authentication.encoding.Md5PasswordEncoder;
|
18 |
31 |
import org.springframework.security.core.Authentication;
|
19 |
32 |
import org.springframework.security.core.context.SecurityContext;
|
20 |
33 |
import org.springframework.security.core.context.SecurityContextHolder;
|
... | ... | |
48 |
61 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
49 |
62 |
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
50 |
63 |
import eu.etaxonomy.cdm.api.service.ITermService;
|
|
64 |
import eu.etaxonomy.cdm.api.service.ITestService;
|
51 |
65 |
import eu.etaxonomy.cdm.api.service.IUserService;
|
52 |
66 |
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
53 |
67 |
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
... | ... | |
55 |
69 |
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService;
|
56 |
70 |
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
|
57 |
71 |
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
|
72 |
import eu.etaxonomy.cdm.io.service.IIOService;
|
58 |
73 |
import eu.etaxonomy.cdm.model.common.CdmBase;
|
|
74 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.CdmPermissionEvaluator;
|
59 |
75 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator;
|
|
76 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.UnanimousBasedUnrevokable;
|
|
77 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.voter.DescriptionBaseVoter;
|
|
78 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.voter.DescriptionElementVoter;
|
|
79 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.voter.GrantAlwaysVoter;
|
|
80 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.voter.TaxonBaseVoter;
|
|
81 |
import eu.etaxonomy.cdm.persistence.hibernate.permission.voter.TaxonNodeVoter;
|
|
82 |
import eu.etaxonomy.taxeditor.remoting.source.ICdmRemoteSource;
|
|
83 |
import eu.etaxonomy.taxeditor.service.CachedCommonServiceImpl;
|
|
84 |
import eu.etaxonomy.taxeditor.service.CdmServiceRequestExecutor;
|
60 |
85 |
import eu.etaxonomy.taxeditor.service.ICachedCommonService;
|
|
86 |
import eu.etaxonomy.taxeditor.service.TermServiceRequestExecutor;
|
|
87 |
import eu.etaxonomy.taxeditor.session.CdmEntitySessionManager;
|
61 |
88 |
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
|
62 |
89 |
|
63 |
90 |
|
... | ... | |
74 |
101 |
|
75 |
102 |
protected ApplicationContext applicationContext;
|
76 |
103 |
|
|
104 |
private ICdmRemoteSource remoteSource;
|
|
105 |
|
|
106 |
private Map serviceMap = new HashMap<Class<IService>, IService>();
|
|
107 |
|
|
108 |
private ICdmEntitySessionManager cdmEntitySessionManager;
|
|
109 |
|
|
110 |
private CdmPermissionEvaluator cdmPermissionEvaluator;
|
|
111 |
|
|
112 |
private ProviderManager authenticationManager;
|
|
113 |
|
|
114 |
private ICachedCommonService cachedCommonService;
|
77 |
115 |
|
78 |
116 |
public CdmApplicationRemoteConfiguration() {}
|
79 |
117 |
|
|
118 |
public CdmApplicationRemoteConfiguration(ICdmRemoteSource remoteSource) {
|
|
119 |
this.remoteSource = remoteSource;
|
|
120 |
}
|
|
121 |
|
|
122 |
public void setRemoteSource(ICdmRemoteSource remoteSource) {
|
|
123 |
this.remoteSource = remoteSource;
|
|
124 |
}
|
|
125 |
|
|
126 |
private Object getService(Class<?> clazz, String serviceSuffix, HttpInvokerRequestExecutor executor) {
|
|
127 |
if(serviceMap.containsKey(clazz)) {
|
|
128 |
return serviceMap.get(clazz);
|
|
129 |
}
|
|
130 |
String baseUrl;
|
|
131 |
if(remoteSource.getContextPath() == null || remoteSource.getContextPath().equals("")) {
|
|
132 |
baseUrl = "http://" + remoteSource.getServer() + ":" + String.valueOf(remoteSource.getPort());
|
|
133 |
} else {
|
|
134 |
baseUrl = "http://" + remoteSource.getServer() + ":" + String.valueOf(remoteSource.getPort()) + "/" + remoteSource.getContextPath();
|
|
135 |
}
|
|
136 |
HttpInvokerProxyFactoryBean proxy = new HttpInvokerProxyFactoryBean();
|
|
137 |
proxy.setServiceInterface(clazz);
|
|
138 |
proxy.setServiceUrl(baseUrl + serviceSuffix);
|
|
139 |
if(executor != null) {
|
|
140 |
proxy.setHttpInvokerRequestExecutor(executor);
|
|
141 |
}
|
|
142 |
proxy.afterPropertiesSet();
|
|
143 |
Object service = proxy.getObject();
|
|
144 |
serviceMap.put(clazz, service);
|
|
145 |
return service;
|
|
146 |
}
|
|
147 |
|
80 |
148 |
// ****************************** APPLICATION CONTEXT *************************************************/
|
81 |
149 |
|
82 |
150 |
@Override
|
... | ... | |
98 |
166 |
* @return
|
99 |
167 |
*/
|
100 |
168 |
public IEditGeoService getEditGeoService() {
|
101 |
|
return (IEditGeoService)getBean("editGeoService");
|
|
169 |
return (IEditGeoService) getService(IEditGeoService.class, "/remoting/editgeo.service", new CdmServiceRequestExecutor());
|
102 |
170 |
}
|
103 |
171 |
|
104 |
172 |
/**
|
105 |
173 |
* @return
|
106 |
174 |
*/
|
107 |
175 |
public ICachedCommonService getCachedCommonService(){
|
108 |
|
return (ICachedCommonService) getBean("cachedCommonService");
|
|
176 |
if(cachedCommonService == null) {
|
|
177 |
cachedCommonService = new CachedCommonServiceImpl();
|
|
178 |
}
|
|
179 |
return cachedCommonService;
|
109 |
180 |
}
|
110 |
181 |
|
111 |
182 |
|
112 |
183 |
public ICdmEntitySessionManager getCdmEntitySessionManager() {
|
113 |
|
return (ICdmEntitySessionManager) getBean("cdmEntitySessionManager");
|
|
184 |
if(cdmEntitySessionManager == null) {
|
|
185 |
cdmEntitySessionManager = new CdmEntitySessionManager();
|
|
186 |
}
|
|
187 |
return cdmEntitySessionManager;
|
114 |
188 |
}
|
115 |
189 |
|
116 |
190 |
|
... | ... | |
122 |
196 |
|
123 |
197 |
@Override
|
124 |
198 |
public final Object getBean(String name){
|
125 |
|
return this.applicationContext.getBean(name);
|
|
199 |
throw new UnsupportedOperationException("getBean is not implemented for CdmApplicationRemoteConfiguration");
|
126 |
200 |
}
|
127 |
201 |
|
128 |
202 |
@Override
|
129 |
203 |
public IAgentService getAgentService(){
|
130 |
|
return (IAgentService) getBean("agentService");
|
|
204 |
return (IAgentService) getService(IAgentService.class, "/remoting/agent.service", new CdmServiceRequestExecutor());
|
131 |
205 |
}
|
132 |
206 |
|
133 |
207 |
@Override
|
134 |
208 |
public IDatabaseService getDatabaseService(){
|
135 |
|
return (IDatabaseService) getBean("databaseService");
|
|
209 |
return (IDatabaseService) getService(IDatabaseService.class, "/remoting/database.service", new CdmServiceRequestExecutor());
|
136 |
210 |
}
|
137 |
211 |
|
138 |
212 |
@Override
|
139 |
213 |
public INameService getNameService(){
|
140 |
|
return (INameService) getBean("nameService");
|
|
214 |
return (INameService) getService(INameService.class, "/remoting/name.service", new CdmServiceRequestExecutor());
|
141 |
215 |
}
|
142 |
216 |
|
143 |
217 |
@Override
|
144 |
218 |
public IReferenceService getReferenceService(){
|
145 |
|
return (IReferenceService) getBean("referenceService");
|
|
219 |
return (IReferenceService) getService(IReferenceService.class, "/remoting/reference.service", new CdmServiceRequestExecutor());
|
146 |
220 |
}
|
147 |
221 |
|
148 |
222 |
@Override
|
149 |
223 |
public ITaxonService getTaxonService(){
|
150 |
|
return (ITaxonService) getBean("taxonService");
|
|
224 |
return (ITaxonService) getService(ITaxonService.class, "/remoting/taxon.service", new CdmServiceRequestExecutor());
|
151 |
225 |
}
|
152 |
226 |
|
153 |
227 |
@Override
|
154 |
228 |
public IClassificationService getClassificationService(){
|
155 |
|
return (IClassificationService) getBean("classificationService");
|
|
229 |
return (IClassificationService) getService(IClassificationService.class, "/remoting/classification.service", new CdmServiceRequestExecutor());
|
156 |
230 |
}
|
157 |
231 |
|
158 |
232 |
@Override
|
159 |
233 |
public ITaxonNodeService getTaxonNodeService(){
|
160 |
|
return (ITaxonNodeService) getBean("taxonNodeService");
|
|
234 |
return (ITaxonNodeService) getService(ITaxonNodeService.class, "/remoting/taxonnode.service", new CdmServiceRequestExecutor());
|
161 |
235 |
}
|
162 |
236 |
|
163 |
237 |
@Override
|
164 |
238 |
public IDescriptionService getDescriptionService(){
|
165 |
|
return (IDescriptionService) getBean("descriptionService");
|
|
239 |
return (IDescriptionService) getService(IDescriptionService.class, "/remoting/description.service", new CdmServiceRequestExecutor());
|
166 |
240 |
}
|
167 |
241 |
|
168 |
242 |
@Override
|
169 |
243 |
public IOccurrenceService getOccurrenceService(){
|
170 |
|
return (IOccurrenceService) getBean("occurrenceService");
|
|
244 |
return (IOccurrenceService) getService(IOccurrenceService.class, "/remoting/occurrence.service", new CdmServiceRequestExecutor());
|
171 |
245 |
}
|
172 |
246 |
|
173 |
247 |
@Override
|
174 |
248 |
public IPrimerService getPrimerService(){
|
175 |
|
return (IPrimerService) getBean("primerService");
|
|
249 |
return (IPrimerService) getService(IPrimerService.class, "/remoting/primer.service", new CdmServiceRequestExecutor());
|
176 |
250 |
}
|
177 |
251 |
|
178 |
252 |
@Override
|
179 |
253 |
public IAmplificationService getAmplificationService(){
|
180 |
|
return (IAmplificationService) getBean("amplificationService");
|
|
254 |
return (IAmplificationService) getService(IAmplificationService.class, "/remoting/amplification.service", new CdmServiceRequestExecutor());
|
181 |
255 |
}
|
182 |
256 |
|
183 |
257 |
@Override
|
184 |
258 |
public ISequenceService getSequenceService(){
|
185 |
|
return (ISequenceService) getBean("sequenceService");
|
|
259 |
return (ISequenceService) getService(ISequenceService.class, "/remoting/sequence.service", new CdmServiceRequestExecutor());
|
186 |
260 |
}
|
187 |
261 |
|
188 |
262 |
@Override
|
189 |
263 |
public IMediaService getMediaService(){
|
190 |
|
return (IMediaService) getBean("mediaService");
|
|
264 |
return (IMediaService) getService(IMediaService.class, "/remoting/media.service", new CdmServiceRequestExecutor());
|
191 |
265 |
}
|
192 |
266 |
|
193 |
267 |
@Override
|
194 |
268 |
public ITermService getTermService(){
|
195 |
|
return (ITermService) getBean("termService");
|
|
269 |
return (ITermService) getService(ITermService.class, "/remoting/term.service", new TermServiceRequestExecutor());
|
196 |
270 |
}
|
197 |
271 |
|
198 |
272 |
@Override
|
199 |
273 |
public ICommonService getCommonService(){
|
200 |
|
return (ICommonService) getBean("commonService");
|
|
274 |
return (ICommonService) getService(ICommonService.class, "/remoting/common.service", new CdmServiceRequestExecutor());
|
201 |
275 |
}
|
202 |
276 |
|
203 |
277 |
@Override
|
204 |
278 |
public ILocationService getLocationService(){
|
205 |
|
return (ILocationService) getBean("locationService");
|
|
279 |
return (ILocationService) getService(ILocationService.class, "/remoting/location.service", new CdmServiceRequestExecutor());
|
206 |
280 |
}
|
207 |
281 |
|
208 |
282 |
@Override
|
209 |
283 |
public IUserService getUserService(){
|
210 |
|
return (IUserService) getBean("userService");
|
|
284 |
return (IUserService) getService(IUserService.class, "/remoting-public/user.service", new CdmServiceRequestExecutor());
|
211 |
285 |
}
|
212 |
286 |
|
213 |
287 |
@Override
|
214 |
288 |
public IGrantedAuthorityService getGrantedAuthorityService(){
|
215 |
|
return (IGrantedAuthorityService) getBean("grantedAuthorityService");
|
|
289 |
return (IGrantedAuthorityService) getService(IGrantedAuthorityService.class, "/remoting/grantedauthority.service", new CdmServiceRequestExecutor());
|
216 |
290 |
}
|
217 |
291 |
|
218 |
292 |
@Override
|
219 |
293 |
public IService<CdmBase> getMainService(){
|
220 |
|
return (IService<CdmBase>) getBean("mainService");
|
|
294 |
return null;
|
221 |
295 |
}
|
222 |
296 |
|
223 |
297 |
|
224 |
298 |
@Override
|
225 |
299 |
public ProviderManager getAuthenticationManager(){
|
226 |
|
return (ProviderManager) getBean("authenticationManager");
|
|
300 |
if(authenticationManager != null) {
|
|
301 |
return authenticationManager;
|
|
302 |
}
|
|
303 |
Md5PasswordEncoder passwordEncoder = new Md5PasswordEncoder();
|
|
304 |
ReflectionSaltSource saltSource = new ReflectionSaltSource();
|
|
305 |
saltSource.setUserPropertyToUse("getUsername");
|
|
306 |
|
|
307 |
DaoAuthenticationProvider daoAuthenticationProvider = new DaoAuthenticationProvider();
|
|
308 |
daoAuthenticationProvider.setUserDetailsService(getUserService());
|
|
309 |
daoAuthenticationProvider.setSaltSource(saltSource);
|
|
310 |
daoAuthenticationProvider.setPasswordEncoder(passwordEncoder);
|
|
311 |
|
|
312 |
authenticationManager = new ProviderManager(Arrays.asList((AuthenticationProvider)daoAuthenticationProvider));
|
|
313 |
return authenticationManager;
|
227 |
314 |
}
|
228 |
315 |
|
229 |
316 |
|
... | ... | |
234 |
321 |
|
235 |
322 |
@Override
|
236 |
323 |
public ICollectionService getCollectionService(){
|
237 |
|
return (ICollectionService) getBean("collectionService");
|
|
324 |
return (ICollectionService) getService(ICollectionService.class, "/remoting/collection.service", new CdmServiceRequestExecutor());
|
238 |
325 |
}
|
239 |
326 |
|
240 |
327 |
@Override
|
241 |
328 |
public IFeatureTreeService getFeatureTreeService(){
|
242 |
|
return (IFeatureTreeService) getBean("featureTreeService");
|
|
329 |
return (IFeatureTreeService) getService(IFeatureTreeService.class, "/remoting/featuretree.service", new CdmServiceRequestExecutor());
|
243 |
330 |
}
|
244 |
331 |
|
245 |
332 |
@Override
|
246 |
333 |
public IFeatureNodeService getFeatureNodeService(){
|
247 |
|
return (IFeatureNodeService) getBean("featureNodeService");
|
|
334 |
return (IFeatureNodeService) getService(IFeatureNodeService.class, "/remoting/featurenode.service", new CdmServiceRequestExecutor());
|
248 |
335 |
}
|
249 |
336 |
|
250 |
337 |
@Override
|
251 |
338 |
public IVocabularyService getVocabularyService(){
|
252 |
|
return (IVocabularyService) getBean("vocabularyService");
|
|
339 |
return (IVocabularyService) getService(IVocabularyService.class, "/remoting/vocabulary.service", new CdmServiceRequestExecutor());
|
253 |
340 |
}
|
254 |
341 |
|
255 |
342 |
@Override
|
256 |
343 |
public IIdentificationKeyService getIdentificationKeyService(){
|
257 |
|
return (IIdentificationKeyService) getBean("identificationKeyService");
|
|
344 |
return (IIdentificationKeyService) getService(IIdentificationKeyService.class, "/remoting/identificationkey.service", new CdmServiceRequestExecutor());
|
258 |
345 |
}
|
259 |
346 |
|
260 |
347 |
@Override
|
261 |
348 |
public IPolytomousKeyService getPolytomousKeyService(){
|
262 |
|
return (IPolytomousKeyService) getBean("polytomousKeyService");
|
|
349 |
return (IPolytomousKeyService) getService(IPolytomousKeyService.class, "/remoting/polytomouskey.service", new CdmServiceRequestExecutor());
|
263 |
350 |
}
|
264 |
351 |
|
265 |
352 |
|
266 |
353 |
@Override
|
267 |
354 |
public IPolytomousKeyNodeService getPolytomousKeyNodeService(){
|
268 |
|
return (IPolytomousKeyNodeService) getBean("polytomousKeyNodeService");
|
|
355 |
return (IPolytomousKeyNodeService) getService(IPolytomousKeyNodeService.class, "/remoting/polytomouskeynode.service", new CdmServiceRequestExecutor());
|
269 |
356 |
}
|
270 |
357 |
|
271 |
358 |
@Override
|
272 |
359 |
public IWorkingSetService getWorkingSetService(){
|
273 |
|
return (IWorkingSetService) getBean("workingSetService");
|
|
360 |
return (IWorkingSetService) getService(IWorkingSetService.class, "/remoting/workingset.service", new CdmServiceRequestExecutor());
|
274 |
361 |
}
|
275 |
362 |
|
276 |
363 |
@Override
|
277 |
364 |
public IGroupService getGroupService(){
|
278 |
|
return (IGroupService) getBean("groupService");
|
|
365 |
return (IGroupService) getService(IGroupService.class, "/remoting/group.service", new CdmServiceRequestExecutor());
|
279 |
366 |
}
|
280 |
367 |
|
281 |
368 |
|
282 |
369 |
@Override
|
283 |
370 |
public IEntityValidationService getEntityValidationService(){
|
284 |
|
return (IEntityValidationService) getBean("entityValidationService");
|
|
371 |
return (IEntityValidationService) getService(IEntityValidationService.class, "/remoting/entityvalidation.service", new CdmServiceRequestExecutor());
|
285 |
372 |
}
|
286 |
373 |
|
287 |
374 |
|
288 |
375 |
@Override
|
289 |
376 |
public IEntityConstraintViolationService getEntityConstraintViolationService(){
|
290 |
|
return (IEntityConstraintViolationService) getBean("entityConstraintViolationService");
|
|
377 |
return (IEntityConstraintViolationService) getService(IEntityConstraintViolationService.class, "/remoting/entityconstraintviolation.service", new CdmServiceRequestExecutor());
|
291 |
378 |
}
|
292 |
379 |
|
293 |
380 |
@Override
|
294 |
381 |
public ICdmPermissionEvaluator getPermissionEvaluator(){
|
295 |
|
return (ICdmPermissionEvaluator) getBean("cdmPermissionEvaluator");
|
|
382 |
|
|
383 |
if(cdmPermissionEvaluator != null) {
|
|
384 |
return cdmPermissionEvaluator;
|
|
385 |
}
|
|
386 |
List<AccessDecisionVoter> decisionVoters = new ArrayList<AccessDecisionVoter>();
|
|
387 |
decisionVoters.add(new GrantAlwaysVoter());
|
|
388 |
decisionVoters.add(new TaxonNodeVoter());
|
|
389 |
decisionVoters.add(new TaxonBaseVoter());
|
|
390 |
decisionVoters.add(new DescriptionBaseVoter());
|
|
391 |
decisionVoters.add(new DescriptionElementVoter());
|
|
392 |
UnanimousBasedUnrevokable accessDecisionManager = new UnanimousBasedUnrevokable(decisionVoters);
|
|
393 |
|
|
394 |
cdmPermissionEvaluator = new CdmPermissionEvaluator();
|
|
395 |
cdmPermissionEvaluator.setAccessDecisionManager(accessDecisionManager);
|
|
396 |
|
|
397 |
return cdmPermissionEvaluator;
|
296 |
398 |
}
|
297 |
399 |
|
298 |
400 |
|
... | ... | |
319 |
421 |
SecurityContext context = SecurityContextHolder.getContext();
|
320 |
422 |
context.setAuthentication(authentication);
|
321 |
423 |
}
|
|
424 |
|
|
425 |
public IIOService getIOService() {
|
|
426 |
return (IIOService) getService(IIOService.class, "/remoting/io.service", new CdmServiceRequestExecutor());
|
|
427 |
}
|
|
428 |
|
|
429 |
public ITestService getTestService() {
|
|
430 |
return (ITestService) getService(ITestService.class, "/remoting/test.service", new CdmServiceRequestExecutor());
|
|
431 |
}
|
322 |
432 |
}
|
Replace spring application context loading with programmatic loading