Dieser Commit ist enthalten in:
Ursprung
1a54476cbe
Commit
14052c5d01
47
src/de/steamwar/bungeecore/api/AuthUtils.java
Normale Datei
47
src/de/steamwar/bungeecore/api/AuthUtils.java
Normale Datei
@ -0,0 +1,47 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.api;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
import spark.Request;
|
||||
import spark.Response;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@UtilityClass
|
||||
public class AuthUtils {
|
||||
|
||||
public static Optional<Token> isAuthorized(Request request, Response response) {
|
||||
String authorization = request.headers("Authorization");
|
||||
if (authorization == null) {
|
||||
response.type("application/json");
|
||||
response.status(401);
|
||||
return Optional.empty();
|
||||
}
|
||||
|
||||
try {
|
||||
return Optional.of(Token.decrypt(authorization));
|
||||
} catch (SecurityException e) {
|
||||
response.type("application/json");
|
||||
response.status(401);
|
||||
return Optional.empty();
|
||||
}
|
||||
}
|
||||
}
|
@ -23,6 +23,7 @@ import com.google.gson.JsonObject;
|
||||
import com.google.gson.JsonParser;
|
||||
import com.google.gson.stream.JsonWriter;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
import lombok.Getter;
|
||||
|
||||
import javax.crypto.Cipher;
|
||||
import java.io.*;
|
||||
@ -34,6 +35,7 @@ import java.security.spec.DSAPublicKeySpec;
|
||||
import java.util.Base64;
|
||||
import java.util.UUID;
|
||||
|
||||
@Getter
|
||||
public class Token {
|
||||
|
||||
private static KeyPair pair;
|
||||
|
@ -21,6 +21,8 @@ package de.steamwar.bungeecore.api;
|
||||
|
||||
import de.steamwar.bungeecore.api.v1.ServerStatusEndPoint;
|
||||
import de.steamwar.bungeecore.api.v1.ServerTeamEndPoint;
|
||||
import de.steamwar.bungeecore.api.v1.user.GetUUIDEndPoint;
|
||||
import de.steamwar.bungeecore.api.v1.user.GetUserNameEndPoint;
|
||||
|
||||
import static spark.Spark.port;
|
||||
|
||||
@ -31,5 +33,7 @@ public class WebAPI {
|
||||
|
||||
new ServerStatusEndPoint().ignite();
|
||||
new ServerTeamEndPoint().ignite();
|
||||
new GetUserNameEndPoint().ignite();
|
||||
new GetUUIDEndPoint().ignite();
|
||||
}
|
||||
}
|
||||
|
50
src/de/steamwar/bungeecore/api/v1/user/GetUUIDEndPoint.java
Normale Datei
50
src/de/steamwar/bungeecore/api/v1/user/GetUUIDEndPoint.java
Normale Datei
@ -0,0 +1,50 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.api.v1.user;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.bungeecore.api.AuthUtils;
|
||||
import de.steamwar.bungeecore.api.EndPoint;
|
||||
import de.steamwar.bungeecore.api.Token;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static spark.Spark.post;
|
||||
|
||||
public class GetUUIDEndPoint implements EndPoint {
|
||||
|
||||
@Override
|
||||
public void ignite() {
|
||||
post("/v1/user/token_to_uuid", (request, response) -> {
|
||||
Optional<Token> optionalToken = AuthUtils.isAuthorized(request, response);
|
||||
if (!optionalToken.isPresent()) {
|
||||
return "{}";
|
||||
}
|
||||
Token token = optionalToken.get();
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("uuid", token.getUuid().toString());
|
||||
|
||||
response.type("application/json");
|
||||
response.status(200);
|
||||
return jsonObject.toString();
|
||||
});
|
||||
}
|
||||
}
|
51
src/de/steamwar/bungeecore/api/v1/user/GetUserNameEndPoint.java
Normale Datei
51
src/de/steamwar/bungeecore/api/v1/user/GetUserNameEndPoint.java
Normale Datei
@ -0,0 +1,51 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.api.v1.user;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
import de.steamwar.bungeecore.api.AuthUtils;
|
||||
import de.steamwar.bungeecore.api.EndPoint;
|
||||
import de.steamwar.bungeecore.api.Token;
|
||||
import de.steamwar.bungeecore.sql.SteamwarUser;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
import static spark.Spark.post;
|
||||
|
||||
public class GetUserNameEndPoint implements EndPoint {
|
||||
|
||||
@Override
|
||||
public void ignite() {
|
||||
post("/v1/user/token_to_username", (request, response) -> {
|
||||
Optional<Token> optionalToken = AuthUtils.isAuthorized(request, response);
|
||||
if (!optionalToken.isPresent()) {
|
||||
return "{}";
|
||||
}
|
||||
Token token = optionalToken.get();
|
||||
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("username", SteamwarUser.get(token.getUuid()).getUserName());
|
||||
|
||||
response.type("application/json");
|
||||
response.status(200);
|
||||
return jsonObject.toString();
|
||||
});
|
||||
}
|
||||
}
|
30
src/de/steamwar/bungeecore/api/v1/website/LoginEndPoint.java
Normale Datei
30
src/de/steamwar/bungeecore/api/v1/website/LoginEndPoint.java
Normale Datei
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.api.v1.website;
|
||||
|
||||
import de.steamwar.bungeecore.api.EndPoint;
|
||||
|
||||
public class LoginEndPoint implements EndPoint {
|
||||
|
||||
@Override
|
||||
public void ignite() {
|
||||
|
||||
}
|
||||
}
|
30
src/de/steamwar/bungeecore/api/v1/website/LogoutEndPoint.java
Normale Datei
30
src/de/steamwar/bungeecore/api/v1/website/LogoutEndPoint.java
Normale Datei
@ -0,0 +1,30 @@
|
||||
/*
|
||||
* This file is a part of the SteamWar software.
|
||||
*
|
||||
* Copyright (C) 2020 SteamWar.de-Serverteam
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package de.steamwar.bungeecore.api.v1.website;
|
||||
|
||||
import de.steamwar.bungeecore.api.EndPoint;
|
||||
|
||||
public class LogoutEndPoint implements EndPoint {
|
||||
|
||||
@Override
|
||||
public void ignite() {
|
||||
|
||||
}
|
||||
}
|
In neuem Issue referenzieren
Einen Benutzer sperren