Skip to content

Commit

Permalink
Add CoturnServers to API (#618)
Browse files Browse the repository at this point in the history
  • Loading branch information
Sheikah45 committed Jun 26, 2022
1 parent a66a7f1 commit a8c3e4d
Show file tree
Hide file tree
Showing 6 changed files with 89 additions and 4 deletions.
2 changes: 1 addition & 1 deletion configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
| DATABASE_ADDRESS | | | `127.0.0.1` |
| DATABASE_NAME | | | `faf` |
| DATABASE_PASSWORD | | | `banana` |
| DATABASE_SCHEMA_VERSION | `123` | | |
| DATABASE_SCHEMA_VERSION | `124` | | |
| DATABASE_USERNAME | | | `faf-java-api` |
| EMAIL_FROM_ADDRESS | | | `faf@example.com` |
| EMAIL_FROM_NAME | | | `FAForever` |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Configuration
public class MainDbTestContainers {
private static final MariaDBContainer<?> fafDBContainer = new MariaDBContainer<>("mariadb:10.6");
private static final GenericContainer<?> flywayMigrationsContainer = new GenericContainer<>("faforever/faf-db-migrations:v123");
private static final GenericContainer<?> flywayMigrationsContainer = new GenericContainer<>("faforever/faf-db-migrations:v124");
private static final Network sharedNetwork = Network.newNetwork();

@Bean
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/faforever/api/data/domain/CoturnServer.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.faforever.api.data.domain;

import com.faforever.api.data.checks.Prefab;
import com.faforever.api.security.elide.permission.LobbyCheck;
import com.yahoo.elide.annotation.Include;
import com.yahoo.elide.annotation.ReadPermission;
import com.yahoo.elide.annotation.UpdatePermission;
import lombok.Setter;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;

@Entity
@Table(name = "coturn_servers")
@Include(name = CoturnServer.TYPE_NAME)
@ReadPermission(expression = LobbyCheck.EXPRESSION)
@UpdatePermission(expression = Prefab.NONE)
@Setter
public class CoturnServer {
public static final String TYPE_NAME = "coturnServer";

private Integer id;
private String region;
private String host;
private Integer port;
private String key;
private boolean active;

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public Integer getId() {
return id;
}

@Column(name = "region")
public String getRegion() {
return region;
}

@Column(name = "host")
public String getHost() {
return host;
}

@Column(name = "port")
public Integer getPort() {
return port;
}

@Column(name = "preshared_key")
public String getKey() {
return key;
}

@Column(name = "active")
public boolean isActive() {
return active;
}
}
4 changes: 3 additions & 1 deletion src/main/java/com/faforever/api/security/OAuthScope.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public enum OAuthScope {
VOTE(OAuthScope._VOTE, "Vote"),
READ_SENSIBLE_USERDATA(OAuthScope._READ_SENSIBLE_USERDATA, "View sensible user data (email addresses, ip addresses, etc.)"),
ADMINISTRATIVE_ACTION(OAuthScope._ADMINISTRATIVE_ACTION, "Administrative actions"),
MANAGE_VAULT(OAuthScope._MANAGE_VAULT, "Manage vault");
MANAGE_VAULT(OAuthScope._MANAGE_VAULT, "Manage vault"),
LOBBY(OAuthScope._LOBBY, "Connect to Lobby");

public static final String _PUBLIC_PROFILE = "public_profile";
public static final String _WRITE_ACHIEVEMENTS = "write_achievements";
Expand All @@ -29,6 +30,7 @@ public enum OAuthScope {
public static final String _READ_SENSIBLE_USERDATA = "read_sensible_userdata";
public static final String _ADMINISTRATIVE_ACTION = "administrative_actions";
public static final String _MANAGE_VAULT = "manage_vault";
public static final String _LOBBY = "lobby";

private static final Map<String, OAuthScope> fromString;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.faforever.api.security.elide.permission;

import com.faforever.api.security.OAuthScope;
import com.yahoo.elide.annotation.SecurityCheck;
import com.yahoo.elide.core.security.User;
import lombok.extern.slf4j.Slf4j;

import static com.faforever.api.security.elide.permission.LobbyCheck.EXPRESSION;

@Slf4j
@SecurityCheck(EXPRESSION)
public class LobbyCheck extends FafUserCheck {
public static final String EXPRESSION = "Lobby";

@Override
public boolean ok(User user) {
return checkOAuthScopes(OAuthScope.LOBBY);
}
}
2 changes: 1 addition & 1 deletion src/main/resources/config/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ faf-api:
invite-link-expire-duration-minutes: ${CLAN_INVITE_LINK_EXPIRE_DURATION_MINUTES:604800}
website-url-format: ${CLAN_WEBSITE_URL_FORMAT:https://clans.${FAF_DOMAIN}/clan/%s}
database:
schema-version: ${DATABASE_SCHEMA_VERSION:123}
schema-version: ${DATABASE_SCHEMA_VERSION:124}
deployment:
forged-alliance-exe-path: ${FORGED_ALLIANCE_EXE_PATH:/content/legacy-featured-mod-files/updates_faf_files/ForgedAlliance.exe}
repositories-directory: ${REPOSITORIES_DIRECTORY:/repositories}
Expand Down

0 comments on commit a8c3e4d

Please sign in to comment.