Add Admin Interceptors
This commit is contained in:
parent
8041ddb470
commit
68dd312a42
3 changed files with 20 additions and 5 deletions
Binary file not shown.
|
@ -2,6 +2,7 @@ package dev.peerat.backend;
|
|||
|
||||
import static dev.peerat.framework.RequestType.OPTIONS;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Matcher;
|
||||
|
@ -37,11 +38,12 @@ import dev.peerat.framework.Context;
|
|||
import dev.peerat.framework.HttpReader;
|
||||
import dev.peerat.framework.HttpWriter;
|
||||
import dev.peerat.framework.Locker;
|
||||
import dev.peerat.framework.Locker.Key;
|
||||
import dev.peerat.framework.RequestType;
|
||||
import dev.peerat.framework.Response;
|
||||
import dev.peerat.framework.Route;
|
||||
import dev.peerat.framework.RouteInterceptor;
|
||||
import dev.peerat.framework.Router;
|
||||
import dev.peerat.framework.Locker.Key;
|
||||
|
||||
public class Main{
|
||||
public static void main(String[] args) throws Exception{
|
||||
|
@ -83,6 +85,22 @@ public class Main{
|
|||
|
||||
initRoutes(router, repo, config);
|
||||
|
||||
router.addInterceptor(new RouteInterceptor(){
|
||||
@Override
|
||||
public boolean intercept(Matcher matcher, Context context, HttpReader reader, HttpWriter writer, Method method){
|
||||
if(method.getDeclaringClass().getPackage().getName().endsWith("admins")){
|
||||
try {
|
||||
Group group = repo.getPlayerGroup(context.<PeerAtUser>getUser().getId(), 1);
|
||||
if(!group.getName().equalsIgnoreCase("Quarter-Master - Battles PAC x CEI")) return false;
|
||||
}catch(Exception ex){
|
||||
ex.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
});
|
||||
|
||||
new Thread(new Runnable(){
|
||||
public void run(){
|
||||
Key key = new Key();
|
||||
|
@ -103,7 +121,7 @@ public class Main{
|
|||
locker.remove(key);
|
||||
}
|
||||
}).start();
|
||||
|
||||
|
||||
if(config.useSsl()) router.configureSSL(config.getSslKeystore(), config.getSslKeystorePasswd());
|
||||
router.listen(config.getTcpPort(), config.useSsl());
|
||||
}
|
||||
|
|
|
@ -30,9 +30,6 @@ public class DynamicLogs implements Response{
|
|||
|
||||
@Route(path = "^/admin/logs$", needLogin = true, websocket = true)
|
||||
public void exec(Matcher matcher, Context context, HttpReader reader, HttpWriter writer) throws Exception{
|
||||
Group group = this.repo.getPlayerGroup(context.<PeerAtUser>getUser().getId(), 1);
|
||||
if(!group.getName().equalsIgnoreCase("Quarter-Master - Battles PAC x CEI")) return;
|
||||
|
||||
Key key = new Key();
|
||||
|
||||
locker.init(key);
|
||||
|
|
Loading…
Add table
Reference in a new issue