Announcement Announcement Module
Collapse
No announcement yet.
ConnectionRepository-Proxy bypassed in ProviderSignInAttempt? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • ConnectionRepository-Proxy bypassed in ProviderSignInAttempt?

    I want to use JPA for the implementation of ConnectionRepository and UsersConnectionRepository so, I had me a little concerned with the innards of Spring-Social and especially the factory-method for creating a ConnectionRepository instance.
    Note that t's perfectly clear that I receive a request-scoped proxy of ConnectionRepository if I inject such instance, e.g. in a Controller. But what if UsersConnectionRepository.createConnectionReposito ry() is used directly, how do I ensure that a proxy is generated and hence autowiring and transcation handling is performed?
    Searching through Spring-Social's codebase I found several lines of code where a ConnectionRepository instance is created directly and _not_ used via injection, for example:
    Code:
    static ProviderSignInUtils.handlePostSignUp(String userId, RequestAttributes request)
     -> ProviderSignInAttempt.addConnection(String userId)
       -> UsersConnectionRepository.createConnectionRepository(String userId)
         -> ConnectionRepository.addConnection()
    As far as I understand (and if my debugger is right) this code doesn't use any proxy and hence no transaction would be active. In my case that would be a problem since JPA requires a transaction for updates and an (injected) EntityManager instance is needed which would be unset in this case.
    I've read about using @Bean annotation in normal @Compoment instances and the "lite" configuration mode but I can't get this to work, my current solution is to use some of Spring's internals:
    Code:
    @Override
    public ConnectionRepository createConnectionRepository(String userId) {
      if (userId == null) {
        throw new IllegalArgumentException("userId cannot be null");
      }
      ConnectionRepository repository = new JpaConnectionRepository(userId, getTextEncryptor());
      AutowireCapableBeanFactory autowireCapableBeanFactory = applicationContext.getAutowireCapableBeanFactory();
      autowireCapableBeanFactory.autowireBean(repository);
      return (ConnectionRepository) autowireCapableBeanFactory.applyBeanPostProcessorsAfterInitialization(repository, "connectionRepository");
    }
    So can anybody tell me how to resolve this situation or allay my concerns?
    Regarding the design, wouldn't it be better (and more Spring like) to remove the factory-method createConnectionRepository() from UsersConnectionRepository and completely rely on injection?
Working...
X