mirror of
https://github.com/plexusorg/Module-HTTPD.git
synced 2026-06-04 09:06:54 +00:00
Replace IP-based auth with XenForo OAuth2
Also, resolves the long standing issues #2 and #3
This commit is contained in:
@@ -2,6 +2,9 @@ package dev.plex.request;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import dev.plex.HTTPDModule;
|
||||
import dev.plex.authentication.AuthenticatedUser;
|
||||
import dev.plex.authentication.AuthenticationManager;
|
||||
import dev.plex.authentication.OAuth2Provider;
|
||||
import dev.plex.logging.Log;
|
||||
import jakarta.servlet.ServletException;
|
||||
import jakarta.servlet.http.HttpServlet;
|
||||
@@ -133,6 +136,26 @@ public class AbstractServlet extends HttpServlet
|
||||
return requestPath.isEmpty() ? "/" : requestPath;
|
||||
}
|
||||
|
||||
public static AuthenticatedUser currentUser(HttpServletRequest request)
|
||||
{
|
||||
AuthenticationManager manager = HTTPDModule.getAuthenticationManager();
|
||||
if (manager == null) return null;
|
||||
OAuth2Provider provider = manager.provider();
|
||||
if (provider == null) return null;
|
||||
return provider.lookup(request);
|
||||
}
|
||||
|
||||
public static AuthenticatedUser currentStaff(HttpServletRequest request)
|
||||
{
|
||||
AuthenticatedUser user = currentUser(request);
|
||||
return (user != null && user.staff()) ? user : null;
|
||||
}
|
||||
|
||||
public static String signInPrompt(String action)
|
||||
{
|
||||
return "You must <a class=\"text-primary underline\" href=\"/oauth2/login\">sign in</a> as staff " + action + ".";
|
||||
}
|
||||
|
||||
public static String readFile(InputStream filename)
|
||||
{
|
||||
String base = HTTPDModule.template;
|
||||
|
||||
Reference in New Issue
Block a user