Spring security tomcat getRemoteUser method
I have two applications in one cat. one of these apps uses spring security for authentication. I would like the getRemoteUser method to return the correct username in the second application on first login.
Is there an easy way to achieve this? can you point me to a simple possible solution that will do this?
thanks for answers
I donโt believe that application 2 can access the security information of application 1. Not necessarily anyway, perhaps using remote access or web services will allow you to do this. However, I don't think there is a place in spring security where you can view applications and get information only with Java code.
source to share
This will return the local currently logged in user:
String username = SecurityContextHolder.getContext()
.getAuthentication().getName();
So, if appA logs into appB , then the demo of that controller will return the username that appA uses to log into appB. Which appA should know already, mmmm:
public class UserController extends AbstractController {
@Override
protected ModelAndView handleRequestInternal(HttpServletRequest req,
HttpServletResponse res) throws Exception {
String username = SecurityContextHolder.getContext()
.getAuthentication().getName();
ModelAndView mv = new ModelAndView("jsonResponse");
mv.addObject("username", username);
return mv;
}
}
source to share