Revision eb224aa5
Added by Andreas Müller over 1 year ago
cdmlib-services/src/main/java/eu/etaxonomy/cdm/api/application/CdmApplicationController.java | ||
---|---|---|
6 | 6 |
* The contents of this file are subject to the Mozilla Public License Version 1.1 |
7 | 7 |
* See LICENSE.TXT at the top of this package for the full license terms. |
8 | 8 |
*/ |
9 |
|
|
10 | 9 |
package eu.etaxonomy.cdm.api.application; |
11 | 10 |
|
12 |
import java.util.EnumSet; |
|
13 | 11 |
import java.util.List; |
14 | 12 |
import java.util.Properties; |
15 | 13 |
import java.util.UUID; |
... | ... | |
24 | 22 |
import org.springframework.context.support.AbstractApplicationContext; |
25 | 23 |
import org.springframework.core.io.ClassPathResource; |
26 | 24 |
import org.springframework.core.io.Resource; |
27 |
import org.springframework.security.authentication.ProviderManager; |
|
28 |
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken; |
|
29 |
import org.springframework.security.core.Authentication; |
|
30 |
import org.springframework.security.core.context.SecurityContext; |
|
31 |
import org.springframework.security.core.context.SecurityContextHolder; |
|
32 | 25 |
import org.springframework.transaction.PlatformTransactionManager; |
33 | 26 |
import org.springframework.transaction.TransactionStatus; |
34 | 27 |
|
35 | 28 |
import eu.etaxonomy.cdm.api.conversation.ConversationHolder; |
36 |
import eu.etaxonomy.cdm.api.service.IAgentService; |
|
37 |
import eu.etaxonomy.cdm.api.service.IAnnotationService; |
|
38 |
import eu.etaxonomy.cdm.api.service.IClassificationService; |
|
39 |
import eu.etaxonomy.cdm.api.service.ICollectionService; |
|
40 |
import eu.etaxonomy.cdm.api.service.ICommonService; |
|
41 |
import eu.etaxonomy.cdm.api.service.IDatabaseService; |
|
42 |
import eu.etaxonomy.cdm.api.service.IDescriptionElementService; |
|
43 |
import eu.etaxonomy.cdm.api.service.IDescriptionService; |
|
44 |
import eu.etaxonomy.cdm.api.service.IDescriptiveDataSetService; |
|
45 |
import eu.etaxonomy.cdm.api.service.IEntityConstraintViolationService; |
|
46 |
import eu.etaxonomy.cdm.api.service.IEntityValidationService; |
|
47 |
import eu.etaxonomy.cdm.api.service.IEventBaseService; |
|
48 |
import eu.etaxonomy.cdm.api.service.IGrantedAuthorityService; |
|
49 |
import eu.etaxonomy.cdm.api.service.IGroupService; |
|
50 |
import eu.etaxonomy.cdm.api.service.IIdentificationKeyService; |
|
51 |
import eu.etaxonomy.cdm.api.service.ILocationService; |
|
52 |
import eu.etaxonomy.cdm.api.service.IMediaService; |
|
53 |
import eu.etaxonomy.cdm.api.service.IMetadataService; |
|
54 |
import eu.etaxonomy.cdm.api.service.INameService; |
|
55 |
import eu.etaxonomy.cdm.api.service.IOccurrenceService; |
|
56 |
import eu.etaxonomy.cdm.api.service.IPolytomousKeyNodeService; |
|
57 |
import eu.etaxonomy.cdm.api.service.IPolytomousKeyService; |
|
58 |
import eu.etaxonomy.cdm.api.service.IPreferenceService; |
|
59 |
import eu.etaxonomy.cdm.api.service.IProgressMonitorService; |
|
60 |
import eu.etaxonomy.cdm.api.service.IReferenceService; |
|
61 |
import eu.etaxonomy.cdm.api.service.IRegistrationService; |
|
62 |
import eu.etaxonomy.cdm.api.service.IRightsService; |
|
63 |
import eu.etaxonomy.cdm.api.service.ITaxonNodeService; |
|
64 |
import eu.etaxonomy.cdm.api.service.ITaxonService; |
|
65 |
import eu.etaxonomy.cdm.api.service.ITermNodeService; |
|
66 |
import eu.etaxonomy.cdm.api.service.ITermService; |
|
67 |
import eu.etaxonomy.cdm.api.service.ITermTreeService; |
|
68 |
import eu.etaxonomy.cdm.api.service.IUserService; |
|
69 |
import eu.etaxonomy.cdm.api.service.IVocabularyService; |
|
70 |
import eu.etaxonomy.cdm.api.service.longrunningService.ILongRunningTasksService; |
|
71 |
import eu.etaxonomy.cdm.api.service.media.MediaInfoFactory; |
|
72 |
import eu.etaxonomy.cdm.api.service.molecular.IAmplificationService; |
|
73 |
import eu.etaxonomy.cdm.api.service.molecular.IPrimerService; |
|
74 |
import eu.etaxonomy.cdm.api.service.molecular.ISequenceService; |
|
75 |
import eu.etaxonomy.cdm.api.service.registration.IRegistrationWorkingSetService; |
|
76 |
import eu.etaxonomy.cdm.api.service.security.IAccountRegistrationService; |
|
77 |
import eu.etaxonomy.cdm.api.service.security.IPasswordResetService; |
|
78 | 29 |
import eu.etaxonomy.cdm.common.monitor.IProgressMonitor; |
79 | 30 |
import eu.etaxonomy.cdm.common.monitor.NullProgressMonitor; |
80 | 31 |
import eu.etaxonomy.cdm.common.monitor.SubProgressMonitor; |
... | ... | |
82 | 33 |
import eu.etaxonomy.cdm.database.DataSourceNotFoundException; |
83 | 34 |
import eu.etaxonomy.cdm.database.DbSchemaValidation; |
84 | 35 |
import eu.etaxonomy.cdm.database.ICdmDataSource; |
85 |
import eu.etaxonomy.cdm.model.common.CdmBase; |
|
86 |
import eu.etaxonomy.cdm.model.permission.CRUD; |
|
87 | 36 |
import eu.etaxonomy.cdm.model.term.DefinedTermBase; |
88 | 37 |
import eu.etaxonomy.cdm.persistence.hibernate.HibernateConfiguration; |
89 |
import eu.etaxonomy.cdm.persistence.permission.ICdmPermissionEvaluator; |
|
90 | 38 |
|
91 | 39 |
/** |
92 | 40 |
* @author a.mueller |
93 | 41 |
*/ |
94 |
public class CdmApplicationController implements ICdmRepository { |
|
42 |
public class CdmApplicationController |
|
43 |
extends CdmApplicationControllerBase<ICdmApplication> |
|
44 |
implements ICdmApplication { |
|
95 | 45 |
|
96 |
private static final Logger logger = LogManager.getLogger(CdmApplicationController.class);
|
|
46 |
private static final Logger logger = LogManager.getLogger(); |
|
97 | 47 |
|
98 | 48 |
public static final String DEFAULT_APPLICATION_CONTEXT_RESOURCE = "/eu/etaxonomy/cdm/defaultApplicationContext.xml"; |
99 | 49 |
|
100 | 50 |
public AbstractApplicationContext applicationContext; |
101 |
protected ICdmRepository configuration; |
|
102 | 51 |
private final Resource applicationContextResource; |
103 | 52 |
|
104 | 53 |
private final IProgressMonitor progressMonitor; |
... | ... | |
348 | 297 |
return setNewDataSource(dataSource, dbSchemaValidation, null, false, null); |
349 | 298 |
} |
350 | 299 |
|
351 |
|
|
352 | 300 |
/** |
353 | 301 |
* Changes the ApplicationContext to the new dataSource |
354 | 302 |
* |
... | ... | |
361 | 309 |
return setNewDataSource(dataSource, dbSchemaValidation, null, omitTermLoading, null); |
362 | 310 |
} |
363 | 311 |
|
364 |
|
|
365 | 312 |
/** |
366 | 313 |
* Changes the ApplicationContext to the new dataSource |
367 | 314 |
* |
... | ... | |
427 | 374 |
logger.info(beanName); |
428 | 375 |
} |
429 | 376 |
} |
430 |
configuration = (ICdmRepository) applicationContext.getBean("cdmRepository");
|
|
377 |
configuration = (ICdmApplication) applicationContext.getBean("cdmRepository");
|
|
431 | 378 |
try { |
432 |
//FIXME:Remoting catching exection to allow for remoting
|
|
379 |
//FIXME:Remoting catching exception to allow for remoting
|
|
433 | 380 |
getDatabaseService().setApplicationController(this); |
434 | 381 |
} |
435 | 382 |
catch (UnsupportedOperationException uoe) { |
... | ... | |
437 | 384 |
} |
438 | 385 |
} |
439 | 386 |
|
440 |
|
|
441 |
/* ****** Services ******** */ |
|
442 |
@Override |
|
443 |
public final IAnnotationService getAnnotationService(){ |
|
444 |
return configuration.getAnnotationService(); |
|
445 |
} |
|
446 |
|
|
447 |
@Override |
|
448 |
public final INameService getNameService(){ |
|
449 |
return configuration.getNameService(); |
|
450 |
} |
|
451 |
|
|
452 |
|
|
453 |
@Override |
|
454 |
public final ITaxonService getTaxonService(){ |
|
455 |
return configuration.getTaxonService(); |
|
456 |
} |
|
457 |
|
|
458 |
|
|
459 |
@Override |
|
460 |
public final IClassificationService getClassificationService(){ |
|
461 |
return configuration.getClassificationService(); |
|
462 |
} |
|
463 |
|
|
464 |
@Override |
|
465 |
public final ILongRunningTasksService getLongRunningTasksService(){ |
|
466 |
return configuration.getLongRunningTasksService(); |
|
467 |
} |
|
468 |
|
|
469 |
|
|
470 |
@Override |
|
471 |
public final ITaxonNodeService getTaxonNodeService(){ |
|
472 |
try{ |
|
473 |
return configuration.getTaxonNodeService(); |
|
474 |
} catch (Exception e){ |
|
475 |
e.printStackTrace(); |
|
476 |
} |
|
477 |
return null; |
|
478 |
} |
|
479 |
|
|
480 |
|
|
481 |
@Override |
|
482 |
public final IReferenceService getReferenceService(){ |
|
483 |
return configuration.getReferenceService(); |
|
484 |
} |
|
485 |
|
|
486 |
|
|
487 |
@Override |
|
488 |
public final IAgentService getAgentService(){ |
|
489 |
return configuration.getAgentService(); |
|
490 |
} |
|
491 |
|
|
492 |
|
|
493 |
@Override |
|
494 |
public final IDatabaseService getDatabaseService(){ |
|
495 |
return configuration.getDatabaseService(); |
|
496 |
} |
|
497 |
|
|
498 |
|
|
499 |
@Override |
|
500 |
public final ITermService getTermService(){ |
|
501 |
return configuration.getTermService(); |
|
502 |
} |
|
503 |
|
|
504 |
@Override |
|
505 |
public final IDescriptionService getDescriptionService(){ |
|
506 |
return configuration.getDescriptionService(); |
|
507 |
} |
|
508 |
|
|
509 |
@Override |
|
510 |
public final IDescriptionElementService getDescriptionElementService(){ |
|
511 |
return configuration.getDescriptionElementService(); |
|
512 |
} |
|
513 |
|
|
514 |
@Override |
|
515 |
public final IOccurrenceService getOccurrenceService(){ |
|
516 |
return configuration.getOccurrenceService(); |
|
517 |
} |
|
518 |
|
|
519 |
@Override |
|
520 |
public IAmplificationService getAmplificationService(){ |
|
521 |
return configuration.getAmplificationService(); |
|
522 |
} |
|
523 |
|
|
524 |
@Override |
|
525 |
public ISequenceService getSequenceService(){ |
|
526 |
return configuration.getSequenceService(); |
|
527 |
} |
|
528 |
|
|
529 |
@Override |
|
530 |
public IEventBaseService getEventBaseService() { |
|
531 |
return configuration.getEventBaseService(); |
|
532 |
} |
|
533 |
|
|
534 |
|
|
535 |
|
|
536 |
@Override |
|
537 |
public final IPrimerService getPrimerService(){ |
|
538 |
return configuration.getPrimerService(); |
|
539 |
} |
|
540 |
|
|
541 |
|
|
542 |
@Override |
|
543 |
public final IMediaService getMediaService(){ |
|
544 |
return configuration.getMediaService(); |
|
545 |
} |
|
546 |
|
|
547 |
|
|
548 |
@Override |
|
549 |
public final IMetadataService getMetadataService(){ |
|
550 |
return configuration.getMetadataService(); |
|
551 |
} |
|
552 |
|
|
553 |
|
|
554 |
@Override |
|
555 |
public final ICommonService getCommonService(){ |
|
556 |
return configuration.getCommonService(); |
|
557 |
} |
|
558 |
|
|
559 |
|
|
560 |
@Override |
|
561 |
public final ILocationService getLocationService(){ |
|
562 |
return configuration.getLocationService(); |
|
563 |
} |
|
564 |
|
|
565 |
|
|
566 |
@Override |
|
567 |
public final IUserService getUserService(){ |
|
568 |
return configuration.getUserService(); |
|
569 |
} |
|
570 |
|
|
571 |
|
|
572 |
@Override |
|
573 |
public final IGrantedAuthorityService getGrantedAuthorityService(){ |
|
574 |
return configuration.getGrantedAuthorityService(); |
|
575 |
} |
|
576 |
|
|
577 |
|
|
578 |
@Override |
|
579 |
public IGroupService getGroupService(){ |
|
580 |
return configuration.getGroupService(); |
|
581 |
} |
|
582 |
|
|
583 |
|
|
584 |
@Override |
|
585 |
public final ICollectionService getCollectionService(){ |
|
586 |
return configuration.getCollectionService(); |
|
587 |
} |
|
588 |
|
|
589 |
@Override |
|
590 |
public final ITermTreeService getTermTreeService(){ |
|
591 |
return configuration.getTermTreeService(); |
|
592 |
} |
|
593 |
|
|
594 |
@Override |
|
595 |
public final IPreferenceService getPreferenceService(){ |
|
596 |
return configuration.getPreferenceService(); |
|
597 |
} |
|
598 |
|
|
599 |
@Override |
|
600 |
public final ITermNodeService getTermNodeService(){ |
|
601 |
return configuration.getTermNodeService(); |
|
602 |
} |
|
603 |
|
|
604 |
@Override |
|
605 |
public final IVocabularyService getVocabularyService(){ |
|
606 |
return configuration.getVocabularyService(); |
|
607 |
} |
|
608 |
|
|
609 |
@Override |
|
610 |
public final IIdentificationKeyService getIdentificationKeyService(){ |
|
611 |
return configuration.getIdentificationKeyService(); |
|
612 |
} |
|
613 |
|
|
614 |
@Override |
|
615 |
public final IPolytomousKeyService getPolytomousKeyService(){ |
|
616 |
return configuration.getPolytomousKeyService(); |
|
617 |
} |
|
618 |
|
|
619 |
@Override |
|
620 |
public final IPolytomousKeyNodeService getPolytomousKeyNodeService(){ |
|
621 |
return configuration.getPolytomousKeyNodeService(); |
|
622 |
} |
|
623 |
|
|
624 |
@Override |
|
625 |
public IProgressMonitorService getProgressMonitorService() { |
|
626 |
return configuration.getProgressMonitorService(); |
|
627 |
} |
|
628 |
|
|
629 |
@Override |
|
630 |
public IEntityValidationService getEntityValidationService(){ |
|
631 |
return configuration.getEntityValidationService(); |
|
632 |
} |
|
633 |
|
|
634 |
@Override |
|
635 |
public IEntityConstraintViolationService getEntityConstraintViolationService(){ |
|
636 |
return configuration.getEntityConstraintViolationService(); |
|
637 |
} |
|
638 |
|
|
639 |
@Override |
|
640 |
public final IDescriptiveDataSetService getDescriptiveDataSetService(){ |
|
641 |
return configuration.getDescriptiveDataSetService(); |
|
642 |
} |
|
643 |
|
|
644 | 387 |
@Override |
645 | 388 |
public final ConversationHolder NewConversation(){ |
646 | 389 |
//return (ConversationHolder)applicationContext.getBean("conversationHolder"); |
647 | 390 |
return configuration.NewConversation(); |
648 | 391 |
} |
649 | 392 |
|
650 |
@Override |
|
651 |
public IRightsService getRightsService() { |
|
652 |
return configuration.getRightsService(); |
|
653 |
} |
|
654 |
|
|
655 |
@Override |
|
656 |
public IRegistrationService getRegistrationService() { |
|
657 |
return configuration.getRegistrationService(); |
|
658 |
} |
|
659 |
|
|
660 |
@Override |
|
661 |
public IRegistrationWorkingSetService getRegistrationWorkingSetService() { |
|
662 |
return configuration.getRegistrationWorkingSetService(); |
|
663 |
} |
|
664 |
|
|
665 |
@Override |
|
666 |
public MediaInfoFactory getMediaInfoFactory() { |
|
667 |
return configuration.getMediaInfoFactory(); |
|
668 |
} |
|
669 |
|
|
670 |
@Override |
|
671 |
public IPasswordResetService getPasswordResetService() { |
|
672 |
return configuration.getPasswordResetService(); |
|
673 |
} |
|
674 |
|
|
675 |
@Override |
|
676 |
public IAccountRegistrationService getAccountRegistrationService() { |
|
677 |
return configuration.getAccountRegistrationService(); |
|
678 |
} |
|
679 |
|
|
680 |
/* **** Security ***** */ |
|
681 |
|
|
682 |
@Override |
|
683 |
public void authenticate(String username, String password){ |
|
684 |
UsernamePasswordAuthenticationToken tokenForUser = new UsernamePasswordAuthenticationToken(username, password); |
|
685 |
Authentication authentication = this.getAuthenticationManager().authenticate(tokenForUser); |
|
686 |
SecurityContext context = SecurityContextHolder.getContext(); |
|
687 |
context.setAuthentication(authentication); |
|
688 |
} |
|
689 |
|
|
690 |
@Override |
|
691 |
public final ProviderManager getAuthenticationManager(){ |
|
692 |
return configuration.getAuthenticationManager(); |
|
693 |
} |
|
694 |
|
|
695 |
@Override |
|
696 |
public ICdmPermissionEvaluator getPermissionEvaluator(){ |
|
697 |
return configuration.getPermissionEvaluator(); |
|
698 |
} |
|
699 |
|
|
700 |
/** |
|
701 |
* @see org.springframework.security.access.PermissionEvaluator#hasPermission(org.springframework.security.core.Authentication, |
|
702 |
* java.lang.Object, java.lang.Object) |
|
703 |
* |
|
704 |
* @param targetDomainObject |
|
705 |
* @param permission |
|
706 |
* @return |
|
707 |
*/ |
|
708 |
public boolean currentAuthentiationHasPermissions(CdmBase targetDomainObject, EnumSet<CRUD> permission){ |
|
709 |
SecurityContext context = SecurityContextHolder.getContext(); |
|
710 |
return getPermissionEvaluator().hasPermission(context.getAuthentication(), targetDomainObject, permission); |
|
711 |
} |
|
712 |
|
|
713 | 393 |
@Override |
714 | 394 |
public final PlatformTransactionManager getTransactionManager(){ |
715 | 395 |
return configuration.getTransactionManager(); |
Also available in: Unified diff
ref #10189 split CdmApplicationController into repository and application part in cdmlib