lol cef auth + forejo

This commit is contained in:
Failure 2024-11-14 22:23:52 -08:00
parent 0fdb21f17d
commit 35d7d3756a
15 changed files with 114 additions and 118 deletions

View file

@ -0,0 +1,23 @@
on:
push:
branches:
- 'master'
jobs:
example-docker-compose:
runs-on: self-hosted
steps:
- uses: actions/checkout@v4
- name: Build Mage
run: |
apk update
apk add openjdk8-jdk maven
mvn clean install -DskipTests
- uses: actions/upload-artifact@v4
with:
name: files
path: |
./Mage.Client/target/mage-client.zip
./Mage.Server/target/mage-server.zip

View file

@ -1,10 +0,0 @@
version: 2
updates:
- package-ecosystem: 'github-actions'
directory: '/'
schedule:
interval: 'weekly'
- package-ecosystem: 'maven'
directory: '/'
schedule:
interval: 'weekly'

23
.github/labeler.yml vendored
View file

@ -1,23 +0,0 @@
dev:
- changed-files:
- any-glob-to-any-file: [ '*', 'Utils/**', '/.github/**' ]
engine:
- changed-files:
- any-glob-to-any-file: [ 'Mage/**' ]
client:
- changed-files:
- any-glob-to-any-file: [ 'Mage.Client/**', 'Mage.Common/**', 'Mage.Plugins/**' ]
server:
- changed-files:
- any-glob-to-any-file: [ 'Mage.Server*/**' ]
tests:
- changed-files:
- any-glob-to-any-file: [ 'Mage.Verify/**', 'Mage.Tests/**', 'Mage.Reports/**' ]
cards:
- changed-files:
- any-glob-to-any-file: [ 'Mage.Sets/**' ]

View file

@ -1,15 +0,0 @@
name: "Pull Request Labeler (auto)"
on:
- pull_request_target
jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- id: label-the-PR
uses: actions/labeler@v5
with:
configuration-path: '.github/labeler.yml'

View file

@ -1,24 +0,0 @@
name: "Pull Request Labeler (manual)"
on:
workflow_dispatch:
inputs:
oldPRs:
# no multi lines support, so call by single PR only
description: 'PR number to process'
required: true
type: string
default: '123'
jobs:
labeler:
permissions:
contents: read
pull-requests: write
runs-on: ubuntu-latest
steps:
- id: label-the-PR
uses: actions/labeler@v5
with:
configuration-path: '.github/labeler.yml'
pr-number: |
${{ github.event.inputs.oldPRs }}

View file

@ -1,21 +0,0 @@
name: Mtg Card Fetch Bot
on:
issue_comment:
types: [created]
issues:
types: [opened]
pull_request_review:
types: [submitted]
pull_request_review_comment:
types: [created]
jobs:
fetch-card-references:
name: Fetch MTG Card
runs-on: ubuntu-latest
permissions:
issues: write
pull-requests: write
steps:
- uses: ldeluigi/mtg-fetch-action@v1

View file

@ -308,14 +308,6 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
errorDialog.setLocation(100, 100);
desktopPane.add(errorDialog, errorDialog.isModal() ? JLayeredPane.MODAL_LAYER : JLayeredPane.PALETTE_LAYER);
try {
this.whatsNewDialog = new WhatsNewDialog();
} catch (Throwable e) {
// example: JavaFX is not supported on old MacOS with OpenJDK
// https://bugs.openjdk.java.net/browse/JDK-8202132
LOGGER.error("JavaFX is not supported by your system. What's new page will be disabled.", e);
this.whatsNewDialog = null;
}
PING_SENDER_EXECUTOR.scheduleAtFixedRate(SessionHandler::ping, TablesPanel.PING_SERVER_SECS, TablesPanel.PING_SERVER_SECS, TimeUnit.SECONDS);
@ -396,11 +388,6 @@ public class MageFrame extends javax.swing.JFrame implements MageClient {
setWindowTitle(); // make sure title is actual on startup
});
// run what's new checks (loading in background)
SwingUtilities.invokeLater(() -> {
showWhatsNewDialog(false);
});
}
private void bootstrapSetsAndFormats() {

View file

@ -329,6 +329,7 @@ public class ConnectDialog extends MageDialog {
});
btnFindBeta.setText("BETA");
btnFindBeta.setEnabled(false);
btnFindBeta.setToolTipText("Connect to BETA server, AI disabled (use any username without registration)");
btnFindBeta.setAlignmentY(0.0F);
btnFindBeta.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);

View file

@ -59,6 +59,8 @@
mailUser=""
mailPassword=""
mailFromAddress=""
httpAuth="false"
authUrl=""
/>
<playerTypes>
<playerType name="Human" jar="mage-player-human-${project.version}.jar" className="mage.player.human.HumanPlayer"/>

View file

@ -64,6 +64,7 @@ public class AuthorizedUser {
public boolean doCredentialsMatch(String name, String password) {
HashedCredentialsMatcher matcher = new HashedCredentialsMatcher(this.hashAlgorithm);
matcher.setHashIterations(this.hashIterations);
AuthenticationToken token = new UsernamePasswordToken(name, password);
AuthenticationInfo info = new SimpleAuthenticationInfo(this.name,
ByteSource.Util.bytes(Base64.decode(this.password)),

View file

@ -18,6 +18,17 @@ import org.jboss.remoting.callback.Callback;
import org.jboss.remoting.callback.HandleCallbackException;
import org.jboss.remoting.callback.InvokerCallbackHandler;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@ -152,8 +163,8 @@ public class Session {
if (userName.length() > config.getMaxUserNameLength()) {
return "User name may not be longer than " + config.getMaxUserNameLength() + " characters";
}
if (userName.length() <= 3) {
return "User name is too short (3 characters or fewer)";
if (userName.length() <= 1) {
return "User name is too short (1 characters or fewer)";
}
if (userName.length() >= 500) {
return "User name is too long (500 characters or more)";
@ -242,6 +253,7 @@ public class Session {
// find auth user
AuthorizedUser authorizedUser = null;
if (managerFactory.configSettings().isAuthenticationActivated()) {
authorizedUser = AuthorizedUserRepository.getInstance().getByName(userName);
String errorMsg = "Wrong username or password. You must register your account first.";
@ -268,6 +280,52 @@ public class Session {
}
}
if (managerFactory.configSettings().isHttpAuth()) {
try {
JsonObject body = new JsonObject();
body.addProperty("passphrase", password);
body.addProperty("accountName", userName);
String json = body.toString();
System.out.println(json);
URL url = new URL(managerFactory.configSettings().getAuthUrl());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("POST");
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Content-Length", Integer.toString(json.length()));
conn.setRequestProperty("User-Agent", "Tainted-Mage/1.0");
conn.setDoOutput(true);
OutputStream os = conn.getOutputStream();
os.write(json.getBytes());
os.flush();
os.close();
int responseCode = conn.getResponseCode();
if (responseCode == HttpURLConnection.HTTP_OK) {
BufferedReader in = new BufferedReader(new InputStreamReader(conn.getInputStream()));
String resp = in.readLine();
in.close();
JsonElement response = JsonParser.parseString(resp);
if (response.isJsonObject() && response.getAsJsonObject().has("success") && response.getAsJsonObject().get("success").getAsBoolean()) {
// s'all good, man
} else {
return "Failed to authenticate";
}
} else {
return "Failed to authenticate: " + Integer.toString(responseCode);
}
} catch (Exception e) {
return "Error with external authentication. Please try again later.";
}
}
// create new user instance (auth or anon)
boolean isReconnection = false;
User newUser = managerFactory.userManager().createUser(userName, host, authorizedUser).orElse(null);

View file

@ -69,4 +69,8 @@ public interface ConfigSettings {
List<Plugin> getDraftCubes();
List<Plugin> getDeckTypes();
boolean isHttpAuth();
String getAuthUrl();
}

View file

@ -31,6 +31,9 @@
<xs:attribute name="userNamePattern" type="xs:string" use="required"/>
<xs:attribute name="maxAiOpponents" type="xs:string" use="optional"/>
<xs:attribute name="saveGameActivated" type="xs:boolean" use="optional"/>
<xs:attribute name="httpAuth" type="xs:boolean" use="optional" />
<xs:attribute name="authUrl" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>

View file

@ -143,4 +143,12 @@ public class ConfigWrapper implements ConfigSettings {
return config.getDeckTypes().getDeckType();
}
public boolean isHttpAuth() {
return config.getServer().isHttpAuth();
}
public String getAuthUrl() {
return config.getServer().getAuthUrl();
}
}

View file

@ -44,6 +44,8 @@
<xs:attribute name="mailUser" type="xs:string" use="optional"/>
<xs:attribute name="mailPassword" type="xs:string" use="optional"/>
<xs:attribute name="mailFromAddress" type="xs:string" use="optional"/>
<xs:attribute name="httpAuth" type="xs:boolean" use="optional" />
<xs:attribute name="authUrl" type="xs:string" use="optional"/>
</xs:complexType>
</xs:element>