我的简单@Controller要求从请求到某些资源进行身份验证。
@PreAuthorize("hasRole('ROLE_ADMIN')")
@RequestMapping(value = "/confidential**", method = RequestMethod.GET)
public String confidential(Model model) {
return "confidential";
}如果我没有登录并尝试访问/confidential,那么将显示我的自定义登录页面。这完全没问题。我可以键入我的凭据,我将被重定向到机密页面。
@Controller
@RequestMapping(LoginController.ROOT_MAPPING)
public class LoginController {
@RequestMapping("/login**")
public String login(HttpServletRequest request, Model model) {
// model.addAttribute("requestedResource", requestedResource);
return "login";
}
}现在我有了另一个要求。我需要知道登录()方法级别上请求的资源地址(如"/confidential")。我需要这个来创建redirection_uri用于Facebook OAuth2身份验证,我的登录页面必须支持这个身份验证。
HttpServletRequest对象只包含有关当前请求("/login")及其参数的信息。
发布于 2015-04-23 09:36:09
我不知道如何只有"/confidential“请求,但是使用这段代码,您应该拥有整个初始url:
@Controller
@RequestMapping(LoginController.ROOT_MAPPING)
public class LoginController {
@RequestMapping("/login**")
public String login(HttpServletRequest request, Model model) {
// model.addAttribute("requestedResource", requestedResource);
SavedRequest savedRequest =
new HttpSessionRequestCache().getRequest(request, response);
String url = savedRequest.getRedirectUrl();
// do what you want with url variable and OAuth...
return "login";
}
}您应该提取URI、上下文、服务器名、.如果您只需要url的一部分,可以使用regex。
https://stackoverflow.com/questions/29818658
复制相似问题