Override default overrides in Spring Social

I am trying to override the default behavior of Spring Social to redirect to "connect / {providerId} Connected" after connecting to the provider (Twitter, Facebook, etc.).

So I am trying to override the default behavior by overriding the protected java.lang.String connectedView (java.lang.String providerId) method

So, I subclassed ConnectController and tried to override:

@Controller public class CustomConnectController extends ConnectController{ @Inject public CustomConnectController( ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) { super(connectionFactoryLocator, connectionRepository); } @Override protected String connectedView(String providerId){ //Do some logic return "redirect:/foo/bar; } } 

See controller class documentation: http://static.springsource.org/spring-social/docs/1.0.x/api/org/springframework/social/connect/web/ConnectController.html

But I get the following error:

Called: java.lang.IllegalStateException: An ambiguous mapping was detected. Cannot match 'org.springframework.social.connect.web.ConnectController # 0' bean method public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect (java.lang.String , org.springframework.web.context.request.NativeWebRequest) in {[/ Connect / {providerId}], methods = [POST], PARAMS = [], headers = [], consumes = [], produces = [], custom = []}: The customConnectController bean method already exists public org.springframework.web.servlet.view.RedirectView org.springframework.social.connect.web.ConnectController.connect (java.lang.String, org.springframework.web.context .request.NativeWebRequest) are mapped.

Someone can advise. My requirement is as follows: 1. After the user connects to the social account (Twitter, Facebook, etc.), 2. Do some business logic 3. Redirect to the / foo / bar page

Please, help.

+4
source share
2 answers

Ok, I found a solution myself. Providing an answer for everyone so that someone who struggled with a stupid thing can take advantage of:

Actually, I had a ConnectController configured in my configuration, and now the user controller has stepped on this, and therefore it is already displayed. Problem removing configuration from configuration.

In my case, deleting the following code:

 <bean class="org.springframework.social.connect.web.ConnectController"> relies on by-type autowiring for the constructor-args <property name="applicationUrl" value="${application.url}" /> </bean> 
+7
source

Well, you did everything right, but forgot to add

  @RequestMapping("/connect") 

If you work with Spring boot and don't have spring -config.xml files, you can use the code below.

This code helped

 @Controller @RequestMapping("/connect") public class ChangeDefaultFlowController extends ConnectController { public ChangeDefaultFlowController(ConnectionFactoryLocator connectionFactoryLocator, ConnectionRepository connectionRepository) { super(connectionFactoryLocator, connectionRepository); } @Override protected String connectedView(String providerId) { return "redirect:/"+providerId; } } 

This link offers more explanation on changing the direction of redirection to a page or other break controller.

0
source

Source: https://habr.com/ru/post/1442617/


All Articles