Browse Source

new front update 5

master
gsd 1 year ago
parent
commit
01b61e12f8
  1. 25
      src/main/java/app/controllers/auth/AuthSteamController.java
  2. 46
      src/main/java/app/controllers/other/CryptoController.java
  3. 8
      src/main/java/app/services/StatsService.java
  4. 6
      src/main/java/app/services/steam/SteamSignIn.java

25
src/main/java/app/controllers/auth/AuthSteamController.java

@ -18,12 +18,15 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
@RestController @RestController
@RequestMapping("/api/auth") @RequestMapping("/api/auth")
public class AuthSteamController { public class AuthSteamController {
private List<String> subDomains = new ArrayList<>(){{add("tf2"); add("tf3");}};
private SteamSignIn steamSignIn; private SteamSignIn steamSignIn;
private SaltedCookie saltedCookie; private SaltedCookie saltedCookie;
private SteamWebApi steamWebApi; private SteamWebApi steamWebApi;
@ -38,20 +41,22 @@ public class AuthSteamController {
} }
@GetMapping("login") @GetMapping("login")
public ResponseEntity<Void> Login(@RequestParam(value = "authentication_discord", required = false, defaultValue = "false") boolean authentication_discord){ public ResponseEntity<Void> Login(@RequestParam(value = "authentication_discord", required = false, defaultValue = "false") boolean authentication_discord,
return steamSignIn.ConstructURLAndRedirect(authentication_discord); @RequestParam(required = false, defaultValue = "tf2") String subdomain){
return steamSignIn.ConstructURLAndRedirect(authentication_discord, this.subDomains.contains(subdomain)?subdomain:"tf2");
} }
@GetMapping("logout") @GetMapping("logout")
public ResponseEntity<?> Logout(HttpServletResponse response){ public ResponseEntity<?> Logout(HttpServletResponse response, @RequestParam(required = false, defaultValue = "tf2") String subdomain){
String domain = this.subDomains.contains(subdomain)?subdomain+".pblr-nyk.pro":"tf2.pblr-nyk.pro";
Cookie cookie_steam64 = new Cookie("steam64",""); Cookie cookie_steam64 = new Cookie("steam64","");
cookie_steam64.setMaxAge(0); cookie_steam64.setMaxAge(0);
cookie_steam64.setPath("/"); cookie_steam64.setPath("/");
cookie_steam64.setDomain("tf2.pblr-nyk.pro"); cookie_steam64.setDomain(domain);
response.addCookie(cookie_steam64); response.addCookie(cookie_steam64);
Cookie cookie_steam64_secured = new Cookie("steam64_secured", ""); Cookie cookie_steam64_secured = new Cookie("steam64_secured", "");
cookie_steam64_secured.setMaxAge(0); cookie_steam64_secured.setMaxAge(0);
cookie_steam64_secured.setDomain("tf2.pblr-nyk.pro"); cookie_steam64_secured.setDomain(domain);
cookie_steam64_secured.setPath("/"); cookie_steam64_secured.setPath("/");
response.addCookie(cookie_steam64_secured); response.addCookie(cookie_steam64_secured);
return ResponseEntity.status(HttpStatus.FOUND). return ResponseEntity.status(HttpStatus.FOUND).
@ -59,21 +64,23 @@ public class AuthSteamController {
.build(); .build();
} }
@GetMapping("processlogin/{after}") @GetMapping("processlogin/{after}/{subdomain}")
public ResponseEntity<?> ProcessLogin(@RequestParam Map<String, String> auth_result, HttpServletResponse response, @PathVariable String after){ public ResponseEntity<?> ProcessLogin(@RequestParam Map<String, String> auth_result, HttpServletResponse response, @PathVariable String after, @PathVariable(required = false) String subdomain){
System.out.println(auth_result); System.out.println(auth_result);
Long steam64 = steamSignIn.ValidateResults(auth_result); Long steam64 = steamSignIn.ValidateResults(auth_result);
if(steam64 == null){ if(steam64 == null){
return new ResponseEntity<>("returned steam is not valid",HttpStatus.FORBIDDEN); return new ResponseEntity<>("returned steam is not valid",HttpStatus.FORBIDDEN);
} }
String domain = this.subDomains.contains(subdomain)?subdomain+".pblr-nyk.pro":"tf2.pblr-nyk.pro";
Cookie cookie_steam64 = new Cookie("steam64", steam64.toString()); Cookie cookie_steam64 = new Cookie("steam64", steam64.toString());
cookie_steam64.setPath("/"); cookie_steam64.setPath("/");
cookie_steam64.setDomain("tf2.pblr-nyk.pro"); cookie_steam64.setDomain(domain);
response.addCookie(cookie_steam64); response.addCookie(cookie_steam64);
Cookie cookie_steam64_secured = new Cookie("steam64_secured", saltedCookie.Hashed(steam64.toString())); Cookie cookie_steam64_secured = new Cookie("steam64_secured", saltedCookie.Hashed(steam64.toString()));
cookie_steam64_secured.setPath("/"); cookie_steam64_secured.setPath("/");
cookie_steam64_secured.setDomain("tf2.pblr-nyk.pro"); cookie_steam64_secured.setDomain(domain);
response.addCookie(cookie_steam64_secured); response.addCookie(cookie_steam64_secured);
String move = Objects.equals(after, "disco")?"/authentication_discord.html":"/"; String move = Objects.equals(after, "disco")?"/authentication_discord.html":"/";

46
src/main/java/app/controllers/other/CryptoController.java

@ -0,0 +1,46 @@
package app.controllers.other;
import app.annotations.interfaces.CheckPermitionFlag;
import app.annotations.interfaces.CheckWebAccess;
import app.utils.CryptedCookie;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
@RestController
@RequestMapping("/api/crypto")
public class CryptoController {
private CryptedCookie cryptedCookie;
@Autowired
public CryptoController(CryptedCookie cryptedCookie) {
this.cryptedCookie = cryptedCookie;
}
@GetMapping
@CheckWebAccess
@CheckPermitionFlag
public HashMap<String, String> crypt(@RequestBody HashMap<String, String> need_crypt) {
return new HashMap<>() {{
need_crypt.entrySet().stream()
.map((item) -> Map.of("key", item.getKey(), "value", cryptedCookie.Hashed(item.getValue())))
.toList()
.forEach((m) -> put(m.get("key"), m.get("value")));
}};
}
@PostMapping
@CheckWebAccess
@CheckPermitionFlag
public HashMap<String, String> decrypt(@RequestBody HashMap<String, String> need_decrypt) {
return new HashMap<>() {{
need_decrypt.entrySet().stream()
.map((item) -> Map.of("key", item.getKey(), "value", cryptedCookie.ReadCh(item.getValue())))
.toList()
.forEach((m) -> put(m.get("key"), m.get("value")));
}};
}
}

8
src/main/java/app/services/StatsService.java

@ -5,6 +5,7 @@ import app.entities.other.SteamID;
import app.entities.server.PlayOn; import app.entities.server.PlayOn;
import app.entities.server.Server; import app.entities.server.Server;
import app.entities.server.players.RCONPlayer; import app.entities.server.players.RCONPlayer;
import app.utils.CryptedCookie;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
@ -15,9 +16,12 @@ import java.util.Map;
public class StatsService { public class StatsService {
Stats stats; Stats stats;
private CryptedCookie cryptedCookie;
@Autowired @Autowired
public StatsService (Stats stats) { public StatsService (Stats stats, CryptedCookie cryptedCookie) {
this.stats = stats; this.stats = stats;
this.cryptedCookie = cryptedCookie;
} }
public PlayOn searchPlayer(SteamID steamID){ public PlayOn searchPlayer(SteamID steamID){
@ -26,7 +30,7 @@ public class StatsService {
if (player != null) return new PlayOn( if (player != null) return new PlayOn(
stringServerEntry.getKey(), stringServerEntry.getKey(),
player.getId(), player.getId(),
player.getIp(), cryptedCookie.Hashed(player.getIp()),
player.getName()); player.getName());
} }
return null; return null;

6
src/main/java/app/services/steam/SteamSignIn.java

@ -63,7 +63,7 @@ public class SteamSignIn {
} }
} }
public ResponseEntity<Void> ConstructURLAndRedirect(boolean authentication_discord){ public ResponseEntity<Void> ConstructURLAndRedirect(boolean authentication_discord, String subdomain){
Matcher result = refinedScripts.matcher(responseURL); Matcher result = refinedScripts.matcher(responseURL);
if (!result.find() || result.group(0).isEmpty()){ if (!result.find() || result.group(0).isEmpty()){
responseURL = String.format("http://%s", responseURL); responseURL = String.format("http://%s", responseURL);
@ -72,8 +72,8 @@ public class SteamSignIn {
HashMap<String, String> authParameters = new HashMap<>(); HashMap<String, String> authParameters = new HashMap<>();
authParameters.put("openid.ns", "http://specs.openid.net/auth/2.0"); authParameters.put("openid.ns", "http://specs.openid.net/auth/2.0");
authParameters.put("openid.mode", "checkid_setup"); authParameters.put("openid.mode", "checkid_setup");
authParameters.put("openid.return_to", responseURL + "/" + (authentication_discord?"disco":"root")); authParameters.put("openid.return_to", responseURL.replace("tf2", subdomain) + "/" + (authentication_discord?"disco":"root"));
authParameters.put("openid.realm", responseURL + "/" + (authentication_discord?"disco":"root")); authParameters.put("openid.realm", responseURL.replace("tf2", subdomain) + "/" + (authentication_discord?"disco":"root"));
authParameters.put("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select"); authParameters.put("openid.identity", "http://specs.openid.net/auth/2.0/identifier_select");
authParameters.put("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select"); authParameters.put("openid.claimed_id", "http://specs.openid.net/auth/2.0/identifier_select");

Loading…
Cancel
Save