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

wired up for namserver to work correctly

parent 884887e0
No related branches found
No related tags found
No related merge requests found
package net.jami.jams.authmodule;
import lombok.extern.slf4j.Slf4j;
import net.jami.jams.common.jami.NameServer;
import net.jami.jams.common.objects.roots.X509Fields;
import net.jami.jams.common.objects.user.User;
import net.jami.jams.dht.DeviceReceiptGenerator;
......@@ -13,7 +14,7 @@ import static net.jami.jams.authmodule.UserAuthenticationModule.datastore;
public class RegisterUserFlow {
//Get the CA, sign, return the Jami ID.
public static void createUser(User user){
public static boolean createUser(User user, NameServer nameServer){
//This generates the X509 Fields we need.
user.setX509Fields(new X509Fields());
user.getX509Fields().setCommonName(user.getUsername());
......@@ -25,7 +26,14 @@ public class RegisterUserFlow {
user.setEthAddress(ethKeyPair[0]);
user.setEthKey(ethKeyPair[1]);
user.setJamiId(DeviceReceiptGenerator.generateJamiId(user));
//Didn't exactly plan on this happening here, but this is the only place we actually need it.
//Given an interface of NameServer, we need to enroll the user or decline the enrollement before
//storing him
if(nameServer != null && nameServer.registerName(user.getUsername() ) != 200){
return false;
}
datastore.getUserDao().storeObject(user);
log.info("Create the user " + user.getUsername() + " because he did not exist before!");
return true;
}
}
......@@ -10,6 +10,7 @@ import net.jami.jams.common.authmodule.AuthenticationResult;
import net.jami.jams.common.cryptoengineapi.CertificateAuthority;
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.AccessLevel;
import net.jami.jams.common.objects.user.User;
import net.jami.jams.common.utils.LibraryLoader;
......@@ -37,6 +38,11 @@ public class UserAuthenticationModule implements AuthenticationModule {
log.info("Started authentication module - default local source is already enabled!");
}
public UserAuthenticationModule(DataStore dataStore, CertificateAuthority certificateAuthority, NameServer nameServer){
this(dataStore,certificateAuthority);
log.info("Attached NameServer to Process...");
}
@Override
public void attachAuthSource(AuthenticationSourceType type, String settings) {
switch (type){
......@@ -82,7 +88,7 @@ public class UserAuthenticationModule implements AuthenticationModule {
user.setAccessLevel(AccessLevel.USER);
user.setRealm(key.getRealm());
user.setUserType(key.getType());
RegisterUserFlow.createUser(user);
RegisterUserFlow.createUser(user,null);
res.setToken(tokenController.generateToken(user.getUsername(),res.getExpires()));
res.setAuthenticated(true);
return res;
......
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