if (req.getRemoteUser() == null) {
String token = LoginServlet.getRememberMeTokenCookie(req);
if (token != null) {
ExoContainer container = getContainer();
CookieTokenService tokenservice = container.getComponentInstanceOfType(CookieTokenService.class);
Credentials credentials = tokenservice.validateToken(token, false);
if (credentials != null) {
ServletContainer servletContainer = ServletContainerFactory.getServletContainer();
try {
servletContainer.login(req, resp, credentials);
} catch (Exception e) {
// Could not authenticate
}
}
}
// Clear token cookie if we did not authenticate
if (req.getRemoteUser() == null) {
Cookie cookie = new Cookie(LoginServlet.COOKIE_NAME, "");
cookie.setPath(req.getContextPath());
cookie.setMaxAge(0);
resp.addCookie(cookie);
}
}
//Process oauth rememberMe
if(req.getRemoteUser() == null) {
String token = LoginServlet.getOauthRememberMeTokenCookie(req);
if(token != null) {
ExoContainer container = getContainer();
CookieTokenService tokenService = container.getComponentInstanceOfType(CookieTokenService.class);
Credentials credentials = tokenService.validateToken(token, false);
AuthenticationRegistry authRegistry = container.getComponentInstanceOfType(AuthenticationRegistry.class);
OrganizationService orgService = container.getComponentInstanceOfType(OrganizationService.class);
if (credentials != null) {
ServletContainer servletContainer = ServletContainerFactory.getServletContainer();
try {
String username = credentials.getUsername();
User portalUser = orgService.getUserHandler().findUserByName(username, UserStatus.ENABLED);
if(portalUser != null) {
authRegistry.setAttributeOfClient(req, ATTRIBUTE_AUTHENTICATED_PORTAL_USER_FOR_JAAS, portalUser);