Announcement Announcement Module
Collapse
No announcement yet.
Redirect to the original URL after signin????? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Redirect to the original URL after signin?????

    Spring social and security experts,

    I have the following use case:
    1. User requests a specific URL like http://www.foobar.com/foo/1001
    2. Anonymous user can see this page but cannot post a comment in this page. Comment posting part is secured by Spring security.
    3. User clicks login. It pops up a login window or redirect it to login page.
    4. The user chooses to sign in with Facebook ID.
    5. After user signed in using FB, it redirects the user to http://www.foobar.com/foo/1001 with authorization.

    I was wondering how I can do that using Spring Social. Thanks a lot!!

  • #2
    Nobody is interested in this question??? I thought that was a reasonable use case.

    Comment


    • #3
      It's certainly reasonable and I'm not ignoring it. However, it's the kind of question that's going to require some time on my part to give it a proper review and answer. That's time that, in the past 1.5 days since you asked the question, I've not had available. Bear with me and I will get back to you on it.

      Comment


      • #4
        Thank you for your attention, habuma. I agree the answer would require some thinking. I tried to investigate signin controller for /signin/authenticate mapping to see if I can add redirect URL as request parameter but didn't get luck. Thank you for taking time to solve the issue. Look forward to see your answer. :-)

        Comment


        • #5
          Hi everybody.

          I solved problem that that follow.

          First, I extends ConnectController to override connectedView method.
          Second, before you redirect to "connect/facebook" I load in httpSession one parameter with actual url.
          After login, I redirect to another method might resolve with another redirect.

          Example.

          My own ConnectController implementation.
          Code:
          @Controller("facebookController")
          public class FacebookController extends ConnectController {
          
              private final static Log logger = LogFactory.getLog(FacebookController.class);
              private ConnectionRepository connectionRepository;
          
              @Autowired
              public FacebookController(ConnectionFactoryLocator connectionFactoryLocator,
                      ConnectionRepository connectionRepository) {
          
                  super(connectionFactoryLocator, connectionRepository);
          
                  this.connectionRepository = connectionRepository;
          
              }
          
              @Override
              protected String connectedView(String providerId) {
          
                  return "redirect:/connect/" + providerId + "/response";
              }
          
              @RequestMapping(value = "/facebook/response")
              public String serverPage(Model model, HttpServletRequest request) {
          
                  String page = (String) request.getSession(false).getAttribute("page");
          
                  if (page == null) {
          
                      return "redirect:/xx/xx/xx";
                  } else {
          
                      request.getSession(false).removeAttribute("page");
          
                      return page;
                  }
              }
          
          }
          Any other method from any Controller.
          Code:
              @RequestMapping(value = "/xxx", method = RequestMethod.POST)
              public String sendMessage(HttpServletRequest request) throws IOException {
          
                  Connection<Facebook> connection = this.connectionRepository.findPrimaryConnection(Facebook.class);
          
                  if (connection == null) {
                   
                      request.getSession(true).setAttribute("page", "your/request/value");
                      
                      return "redirect:/connect/facebook";
                  }
          
                  //TODO
              }

          Comment


          • #6
            Thanks for sharing the answer, MiLLeN. I haven't tried your answer but I am using Spring Social showcase as an example so I guess the signin part was taken care by SimpleSignInAdapter and *SigninController (Sorry I forgot the name but it is part of Spring Social ). I don't know how I can integrate your answer into existing showcase example. Maybe Habuma will use a different approach to address this issue.

            Comment


            • #7
              Originally posted by dreamdust View Post
              Thanks for sharing the answer, MiLLeN. I haven't tried your answer but I am using Spring Social showcase as an example so I guess the signin part was taken care by SimpleSignInAdapter and *SigninController (Sorry I forgot the name but it is part of Spring Social ). I don't know how I can integrate your answer into existing showcase example. Maybe Habuma will use a different approach to address this issue.
              In provider ProviderSignInController you have.

              https://github.com/SpringSource/spri...ontroller.java

              Code:
              private String postSignInUrl = "/";
              
                        /**
               	 * Sets the default URL to redirect the user to after signing in using a provider.
               	 * Defaults to "/".
              	 * @param postSignInUrl the postSignIn URL
              	 */
              	public void setPostSignInUrl(String postSignInUrl) {
              		this.postSignInUrl = postSignInUrl;
              	}
              To change postSignInUrl in runtime, you should extends this Controller and use any technique as mine above with ConnectController.

              Comment

              Working...
              X