Skip to content
Snippets Groups Projects
Commit 4c82024b authored by Felix Sidokhine's avatar Felix Sidokhine
Browse files

working on implementing the nameservers and their proxies

parent 896c48e4
No related branches found
No related tags found
No related merge requests found
import requests
import json
import requests
data = {}
data['username'] = "admin"
......
package net.jami.jams.common.jami;
public interface NameServer {
Integer registerName();
String getAddressFromName();
String getNameFromAddress();
Integer registerName(String username);
String getAddressFromName(String username);
String getNameFromAddress(String address);
}
package net.jami.jams.common.utils;
import net.jami.jams.common.authentication.AuthenticationSource;
import net.jami.jams.common.authentication.AuthenticationSourceType;
import net.jami.jams.common.objects.requests.CreateCARequest;
import java.math.BigInteger;
......
package net.jami.jams.server.core.jaminamserver;
import lombok.extern.slf4j.Slf4j;
import net.jami.jams.common.dao.StatementElement;
import net.jami.jams.common.dao.StatementList;
import net.jami.jams.common.jami.NameServer;
import net.jami.jams.common.objects.user.User;
import java.util.List;
import static net.jami.jams.server.Server.dataStore;
@Slf4j
public class LocalNameServer implements NameServer {
//This always returns 200, for obvious reasons.
@Override
public Integer registerName() {
return null;
public Integer registerName(String username) {
return 200;
}
@Override
public String getAddressFromName() {
return null;
public String getAddressFromName(String username) {
StatementList statementList = new StatementList();
StatementElement statementElement = new StatementElement("username","=",username,"");
statementList.addStatement(statementElement);
List<User> results = dataStore.getUserDao().getObjects(statementList);
if(results.size() == 0){
return null;
}
return results.get(0).getAddress();
}
@Override
public String getNameFromAddress() {
return null;
public String getNameFromAddress(String address) {
StatementList statementList = new StatementList();
//TODO: Check this.
StatementElement statementElement = new StatementElement("address","=",address,"");
statementList.addStatement(statementElement);
List<User> results = dataStore.getUserDao().getObjects(statementList);
if(results.size() == 0){
return null;
}
return results.get(0).getUsername();
}
}
package net.jami.jams.server.core.jaminamserver;
import lombok.extern.slf4j.Slf4j;
import net.jami.jams.common.jami.NameServer;
import java.io.BufferedReader;
import java.net.HttpURLConnection;
import java.net.URL;
@Slf4j
public class PublicNameServer implements NameServer {
private final String nameserverURI;
public PublicNameServer(String nameserverURI) {
this.nameserverURI = nameserverURI;
}
@Override
public Integer registerName() {
return null;
public Integer registerName(String username) {
try {
URL url = new URL(nameserverURI+"/");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
con.connect();
return con.getResponseCode();
}
catch (Exception e) {
return 500;
}
}
@Override
public String getAddressFromName() {
public String getAddressFromName(String usernmae) {
try {
URL url = new URL(nameserverURI+"/");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
}
catch (Exception e){
return null;
}
return null;
}
@Override
public String getNameFromAddress() {
public String getNameFromAddress(String address) {
try {
URL url = new URL(nameserverURI+"/");
HttpURLConnection con = (HttpURLConnection) url.openConnection();
con.setRequestMethod("GET");
}
catch (Exception e){
return null;
}
return null;
}
}
......@@ -9,8 +9,6 @@ import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import net.jami.jams.common.authentication.AuthenticationSourceType;
import net.jami.jams.common.objects.requests.CreateAuthSourceRequest;
import net.jami.jams.common.objects.requests.CreateCARequest;
import net.jami.jams.common.utils.Validator;
import java.io.IOException;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment