I have a spring controller method. It’s meant to programmatically sign up user (through a single sign on process from another system within the product). It works by getting user data, validating it, creating a user account if it doesnot exist, communicate back to the other system a shared token, and then authenticating the user. There is a handshake process going on, but to get to to the bottom of the problem. I want the same method to return a string if the user is not existing in the system, and return a ModelAndView if they are already registered.
Possible solutions (but cannot execute them):
- The returned string (in the case of the first time user) is going to be read using an
HttpURLConnectioninput stream. So if there is a way to put data in ModelAndView object, and then read it using the input stream, then I am set. - I can return the string and read it OK using the input stream by making the return type as
@ResponseBody String, however, I cannot return a view when it is an existing user.
Ideally, I would return a model and view, but the other system is not spring, and so it won’t understand it.
To summarize, one method that does two things, if the user the a first time user, it returns a string to another system with an encryption token, which the other system will use in an iframe to authenticate the user.
Need to return a string in one case to be read using an input stream reader in another system, and in the case of an existing user, a view needs to be returned to be read using spring itself.
Please let me know if any of this isnot clear.
EDIT: Is there a way to return an http response (something like http servlet response) that is generic enough and works inside and outside of spring. This will also solve my problem.
a method can have only one return type, so you will need to forward the request to another controller method. Which controller method can depend on the result of your authentication …