forked from External/mage
lol cef auth + forejo
This commit is contained in:
parent
0fdb21f17d
commit
35d7d3756a
15 changed files with 114 additions and 118 deletions
|
|
@ -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.";
|
||||
|
|
@ -267,6 +279,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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue