我使用 UserService 来管理我的注册(联合和 OAuth - 混合)。我在应用程序内部的“各个”位置(非 servlet)使用 User.getCurrentUser 来确定当前用户是谁。
我正在分发我的 API 以允许用户调用一些使用 getCurrentUser 的方法。我可以添加一个过滤器并控制我的身份验证,但我不能强制 UserService 登录一个可以在应用程序的其余部分使用的用户 - User.getCurrentUser。
我很难过,现在不知道如何继续。
请帮忙。
我使用 UserService 来管理我的注册(联合和 OAuth - 混合)。我在应用程序内部的“各个”位置(非 servlet)使用 User.getCurrentUser 来确定当前用户是谁。
我正在分发我的 API 以允许用户调用一些使用 getCurrentUser 的方法。我可以添加一个过滤器并控制我的身份验证,但我不能强制 UserService 登录一个可以在应用程序的其余部分使用的用户 - User.getCurrentUser。
我很难过,现在不知道如何继续。
请帮忙。
If you redirect to the createLoginURL method, it will force the user to signin.
You have to wrap your getCurrentUser() API method to detect if it sees a null user and
force a login in that case.
like:
UserService userService = UserServiceFactory.getUserService();
User user = userService.getCurrentUser();
if (user == null) {
session.setAttribute("isLoggedIn", true);
session.setAttribute("authenticatingSite", "google");
try {
response.sendRedirect(userService.createLoginURL(redirectURLAfterLogin);