1
|
/**
|
2
|
* Copyright (C) 2014 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
|
10
|
package eu.etaxonomy.cdm.api.application;
|
11
|
|
12
|
import org.apache.log4j.Logger;
|
13
|
import org.springframework.beans.BeansException;
|
14
|
import org.springframework.context.ApplicationContext;
|
15
|
import org.springframework.context.ApplicationContextAware;
|
16
|
import org.springframework.security.authentication.ProviderManager;
|
17
|
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
|
18
|
import org.springframework.security.core.Authentication;
|
19
|
import org.springframework.security.core.context.SecurityContext;
|
20
|
import org.springframework.security.core.context.SecurityContextHolder;
|
21
|
import org.springframework.stereotype.Component;
|
22
|
import org.springframework.transaction.PlatformTransactionManager;
|
23
|
import org.springframework.transaction.TransactionStatus;
|
24
|
|
25
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
26
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolderMock;
|
27
|
import eu.etaxonomy.cdm.api.service.IAgentService;
|
28
|
import eu.etaxonomy.cdm.api.service.IClassificationService;
|
29
|
import eu.etaxonomy.cdm.api.service.ICollectionService;
|
30
|
import eu.etaxonomy.cdm.api.service.ICommonService;
|
31
|
import eu.etaxonomy.cdm.api.service.IDatabaseService;
|
32
|
import eu.etaxonomy.cdm.api.service.IDescriptionService;
|
33
|
import eu.etaxonomy.cdm.api.service.IEntityConstraintViolationService;
|
34
|
import eu.etaxonomy.cdm.api.service.IEntityValidationService;
|
35
|
import eu.etaxonomy.cdm.api.service.IFeatureNodeService;
|
36
|
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
|
37
|
import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService;
|
38
|
import eu.etaxonomy.cdm.api.service.IGroupService;
|
39
|
import eu.etaxonomy.cdm.api.service.IIdentificationKeyService;
|
40
|
import eu.etaxonomy.cdm.api.service.ILocationService;
|
41
|
import eu.etaxonomy.cdm.api.service.IMediaService;
|
42
|
import eu.etaxonomy.cdm.api.service.INameService;
|
43
|
import eu.etaxonomy.cdm.api.service.IOccurrenceService;
|
44
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService;
|
45
|
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService;
|
46
|
import eu.etaxonomy.cdm.api.service.IReferenceService;
|
47
|
import eu.etaxonomy.cdm.api.service.IService;
|
48
|
import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
|
49
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
50
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
51
|
import eu.etaxonomy.cdm.api.service.IUserService;
|
52
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
53
|
import eu.etaxonomy.cdm.api.service.IWorkingSetService;
|
54
|
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService;
|
55
|
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService;
|
56
|
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService;
|
57
|
import eu.etaxonomy.cdm.ext.geo.IEditGeoService;
|
58
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
59
|
import eu.etaxonomy.cdm.persistence.hibernate.permission.ICdmPermissionEvaluator;
|
60
|
import eu.etaxonomy.taxeditor.service.ICachedCommonService;
|
61
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionManager;
|
62
|
|
63
|
|
64
|
/**
|
65
|
* CDM Application Configuration class which manages the configuration for remoting
|
66
|
* clients
|
67
|
*
|
68
|
*/
|
69
|
@Component
|
70
|
public class CdmApplicationRemoteConfiguration implements ICdmApplicationConfiguration, ApplicationContextAware {
|
71
|
|
72
|
@SuppressWarnings("unused")
|
73
|
private static final Logger logger = Logger.getLogger(CdmApplicationRemoteConfiguration.class);
|
74
|
|
75
|
protected ApplicationContext applicationContext;
|
76
|
|
77
|
|
78
|
public CdmApplicationRemoteConfiguration() {}
|
79
|
|
80
|
// ****************************** APPLICATION CONTEXT *************************************************/
|
81
|
|
82
|
@Override
|
83
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException{
|
84
|
this.applicationContext = applicationContext;
|
85
|
}
|
86
|
|
87
|
/* (non-Javadoc)
|
88
|
* @see eu.etaxonomy.cdm.api.application.CdmApplicationDefaultConfiguration#getTransactionManager()
|
89
|
*/
|
90
|
@Override
|
91
|
public PlatformTransactionManager getTransactionManager() throws UnsupportedOperationException {
|
92
|
throw new UnsupportedOperationException("getTransactionManager is not implemented for CdmApplicationRemoteConfiguration");
|
93
|
}
|
94
|
|
95
|
|
96
|
|
97
|
/**
|
98
|
* @return
|
99
|
*/
|
100
|
public IEditGeoService getEditGeoService() {
|
101
|
return (IEditGeoService)getBean("editGeoService");
|
102
|
}
|
103
|
|
104
|
/**
|
105
|
* @return
|
106
|
*/
|
107
|
public ICachedCommonService getCachedCommonService(){
|
108
|
return (ICachedCommonService) getBean("cachedCommonService");
|
109
|
}
|
110
|
|
111
|
|
112
|
public ICdmEntitySessionManager getCdmEntitySessionManager() {
|
113
|
return (ICdmEntitySessionManager) getBean("cdmEntitySessionManager");
|
114
|
}
|
115
|
|
116
|
|
117
|
|
118
|
|
119
|
|
120
|
|
121
|
// ****************************** GETTER *************************************************/
|
122
|
|
123
|
@Override
|
124
|
public final Object getBean(String name){
|
125
|
return this.applicationContext.getBean(name);
|
126
|
}
|
127
|
|
128
|
@Override
|
129
|
public IAgentService getAgentService(){
|
130
|
return (IAgentService) getBean("agentService");
|
131
|
}
|
132
|
|
133
|
@Override
|
134
|
public IDatabaseService getDatabaseService(){
|
135
|
return (IDatabaseService) getBean("databaseService");
|
136
|
}
|
137
|
|
138
|
@Override
|
139
|
public INameService getNameService(){
|
140
|
return (INameService) getBean("nameService");
|
141
|
}
|
142
|
|
143
|
@Override
|
144
|
public IReferenceService getReferenceService(){
|
145
|
return (IReferenceService) getBean("referenceService");
|
146
|
}
|
147
|
|
148
|
@Override
|
149
|
public ITaxonService getTaxonService(){
|
150
|
return (ITaxonService) getBean("taxonService");
|
151
|
}
|
152
|
|
153
|
@Override
|
154
|
public IClassificationService getClassificationService(){
|
155
|
return (IClassificationService) getBean("classificationService");
|
156
|
}
|
157
|
|
158
|
@Override
|
159
|
public ITaxonNodeService getTaxonNodeService(){
|
160
|
return (ITaxonNodeService) getBean("taxonNodeService");
|
161
|
}
|
162
|
|
163
|
@Override
|
164
|
public IDescriptionService getDescriptionService(){
|
165
|
return (IDescriptionService) getBean("descriptionService");
|
166
|
}
|
167
|
|
168
|
@Override
|
169
|
public IOccurrenceService getOccurrenceService(){
|
170
|
return (IOccurrenceService) getBean("occurrenceService");
|
171
|
}
|
172
|
|
173
|
@Override
|
174
|
public IPrimerService getPrimerService(){
|
175
|
return (IPrimerService) getBean("primerService");
|
176
|
}
|
177
|
|
178
|
@Override
|
179
|
public IAmplificationService getAmplificationService(){
|
180
|
return (IAmplificationService) getBean("amplificationService");
|
181
|
}
|
182
|
|
183
|
@Override
|
184
|
public ISequenceService getSequenceService(){
|
185
|
return (ISequenceService) getBean("sequenceService");
|
186
|
}
|
187
|
|
188
|
@Override
|
189
|
public IMediaService getMediaService(){
|
190
|
return (IMediaService) getBean("mediaService");
|
191
|
}
|
192
|
|
193
|
@Override
|
194
|
public ITermService getTermService(){
|
195
|
return (ITermService) getBean("termService");
|
196
|
}
|
197
|
|
198
|
@Override
|
199
|
public ICommonService getCommonService(){
|
200
|
return (ICommonService) getBean("commonService");
|
201
|
}
|
202
|
|
203
|
@Override
|
204
|
public ILocationService getLocationService(){
|
205
|
return (ILocationService) getBean("locationService");
|
206
|
}
|
207
|
|
208
|
@Override
|
209
|
public IUserService getUserService(){
|
210
|
return (IUserService) getBean("userService");
|
211
|
}
|
212
|
|
213
|
@Override
|
214
|
public IGrantedAuthorityService getGrantedAuthorityService(){
|
215
|
return (IGrantedAuthorityService) getBean("grantedAuthorityService");
|
216
|
}
|
217
|
|
218
|
@Override
|
219
|
public IService<CdmBase> getMainService(){
|
220
|
return (IService<CdmBase>) getBean("mainService");
|
221
|
}
|
222
|
|
223
|
|
224
|
@Override
|
225
|
public ProviderManager getAuthenticationManager(){
|
226
|
return (ProviderManager) getBean("authenticationManager");
|
227
|
}
|
228
|
|
229
|
|
230
|
@Override
|
231
|
public ConversationHolder NewConversation() {
|
232
|
return new ConversationHolderMock();
|
233
|
}
|
234
|
|
235
|
@Override
|
236
|
public ICollectionService getCollectionService(){
|
237
|
return (ICollectionService) getBean("collectionService");
|
238
|
}
|
239
|
|
240
|
@Override
|
241
|
public IFeatureTreeService getFeatureTreeService(){
|
242
|
return (IFeatureTreeService) getBean("featureTreeService");
|
243
|
}
|
244
|
|
245
|
@Override
|
246
|
public IFeatureNodeService getFeatureNodeService(){
|
247
|
return (IFeatureNodeService) getBean("featureNodeService");
|
248
|
}
|
249
|
|
250
|
@Override
|
251
|
public IVocabularyService getVocabularyService(){
|
252
|
return (IVocabularyService) getBean("vocabularyService");
|
253
|
}
|
254
|
|
255
|
@Override
|
256
|
public IIdentificationKeyService getIdentificationKeyService(){
|
257
|
return (IIdentificationKeyService) getBean("identificationKeyService");
|
258
|
}
|
259
|
|
260
|
@Override
|
261
|
public IPolytomousKeyService getPolytomousKeyService(){
|
262
|
return (IPolytomousKeyService) getBean("polytomousKeyService");
|
263
|
}
|
264
|
|
265
|
|
266
|
@Override
|
267
|
public IPolytomousKeyNodeService getPolytomousKeyNodeService(){
|
268
|
return (IPolytomousKeyNodeService) getBean("polytomousKeyNodeService");
|
269
|
}
|
270
|
|
271
|
@Override
|
272
|
public IWorkingSetService getWorkingSetService(){
|
273
|
return (IWorkingSetService) getBean("workingSetService");
|
274
|
}
|
275
|
|
276
|
@Override
|
277
|
public IGroupService getGroupService(){
|
278
|
return (IGroupService) getBean("groupService");
|
279
|
}
|
280
|
|
281
|
|
282
|
@Override
|
283
|
public IEntityValidationService getEntityValidationService(){
|
284
|
return (IEntityValidationService) getBean("entityValidationService");
|
285
|
}
|
286
|
|
287
|
|
288
|
@Override
|
289
|
public IEntityConstraintViolationService getEntityConstraintViolationService(){
|
290
|
return (IEntityConstraintViolationService) getBean("entityConstraintViolationService");
|
291
|
}
|
292
|
|
293
|
@Override
|
294
|
public ICdmPermissionEvaluator getPermissionEvaluator(){
|
295
|
return (ICdmPermissionEvaluator) getBean("cdmPermissionEvaluator");
|
296
|
}
|
297
|
|
298
|
|
299
|
@Override
|
300
|
public TransactionStatus startTransaction() throws UnsupportedOperationException {
|
301
|
throw new UnsupportedOperationException("startTransaction is not implemented for CdmApplicationRemoteConfiguration");
|
302
|
}
|
303
|
|
304
|
@Override
|
305
|
public TransactionStatus startTransaction(Boolean readOnly) throws UnsupportedOperationException {
|
306
|
throw new UnsupportedOperationException("startTransaction is not implemented for CdmApplicationRemoteConfiguration");
|
307
|
}
|
308
|
|
309
|
|
310
|
@Override
|
311
|
public void commitTransaction(TransactionStatus txStatus) throws UnsupportedOperationException {
|
312
|
throw new UnsupportedOperationException("commitTransaction is not implemented for CdmApplicationRemoteConfiguration");
|
313
|
}
|
314
|
|
315
|
@Override
|
316
|
public void authenticate(String username, String password){
|
317
|
UsernamePasswordAuthenticationToken tokenForUser = new UsernamePasswordAuthenticationToken(username, password);
|
318
|
Authentication authentication = this.getAuthenticationManager().authenticate(tokenForUser);
|
319
|
SecurityContext context = SecurityContextHolder.getContext();
|
320
|
context.setAuthentication(authentication);
|
321
|
}
|
322
|
}
|