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

fully functional AD and LDAP modules

parent cba2d5fd
No related branches found
No related tags found
No related merge requests found
......@@ -67,7 +67,7 @@ public class ADConnector implements AuthenticationSource {
}
@Override
public UserProfile getUserProfile(String queryString, String field) {
public UserProfile[] getUserProfile(String queryString, String field) {
return userProfileService.getUserProfile(queryString,field);
}
......
......@@ -32,8 +32,9 @@ public class UserProfileService {
fieldMap.put("o","Organization");
}
public UserProfile getUserProfile(String queryString, String field){
public UserProfile[] getUserProfile(String queryString, String field){
Endpoint endpoint = ADConnector.getConnection();
UserProfile[] profiles = null;
try{
QueryRequest queryRequest = buildRequest(endpoint);
Sentence sentence = null;
......@@ -51,8 +52,12 @@ public class UserProfileService {
try(Connector connector = new Connector(queryRequest)) {
queryResponse = connector.execute();
}
List<Field> fields = queryResponse.getAll().stream().map(EntityResponse::getValue).collect(Collectors.toList()).get(0);
return profileFromResponse(fields);
List<List<Field>> results = queryResponse.getAll().stream().map(EntityResponse::getValue).collect(Collectors.toList());
if(results.size() > 0) profiles = new UserProfile[results.size()];
for(int i=0;i< profiles.length; i++){
profiles[i] = profileFromResponse(results.get(i));
}
return profiles;
}
catch (Exception e){
log.error("Could not find entity with specified parameters.");
......
......@@ -47,7 +47,7 @@ public class DataStore implements AuthenticationSource {
}
@Override
public UserProfile getUserProfile(String queryString, String field) {
public UserProfile[] getUserProfile(String queryString, String field) {
return null;
}
......
......@@ -6,7 +6,7 @@ import net.jami.jams.common.objects.user.UserProfile;
public interface AuthenticationSource {
boolean createUser(User user);
UserProfile getUserProfile(String queryString, String field);
UserProfile[] getUserProfile(String queryString, String field);
boolean authenticate(String username, String password);
AuthenticationSourceInfo getInfo();
boolean testConfiguration(String configuration);
......
......@@ -57,12 +57,12 @@ public class Server {
try {
InputStream path;
ClassLoader classLoader = Thread.currentThread().getContextClassLoader();
path = classLoader.getResourceAsStream("ldapconfig.json");
userAuthenticationModule.attachLDAPAuthSource(new String(path.readAllBytes()));
UserProfile userProfile = userAuthenticationModule.getAuthenticationSources()
.get(new AuthModuleKey("savoirfairelinux", AuthenticationSourceType.LDAP))
path = classLoader.getResourceAsStream("adsampleconfig.json");
userAuthenticationModule.attachADAuthSource(new String(path.readAllBytes()));
UserProfile[] userProfile = userAuthenticationModule.getAuthenticationSources()
.get(new AuthModuleKey("SAVOIRFAIRELINU", AuthenticationSourceType.AD))
.getUserProfile("Sidokhine","FULL_TEXT_NAME");
System.out.println(userProfile);
System.out.println(userProfile[0]);
} catch (Exception e) {
log.error("Could not load and inject active directory connector with error: " + e.toString());
}
......
......@@ -45,7 +45,7 @@ public class LDAPConnector implements AuthenticationSource {
}
@Override
public UserProfile getUserProfile(String queryString, String field) {
public UserProfile[] getUserProfile(String queryString, String field) {
return userProfileService.getUserProfile(queryString,field);
}
......
......@@ -29,7 +29,8 @@ public class UserProfileService {
this.connectionFactory = connectionFactory;
}
public UserProfile getUserProfile(String queryString, String field){
public UserProfile[] getUserProfile(String queryString, String field){
UserProfile[] profiles = null;
Connection connection = null;
try {
connection = connectionFactory.getConnection();
......@@ -37,8 +38,11 @@ public class UserProfileService {
connection.open();
SearchOperation search = new SearchOperation(connectionFactory);
SearchResponse res = search.execute(buildRequest(queryString,field));
if (res.getEntries().size() > 0) return profileFromResponse(res.getEntry());
return null;
if (res.getEntries().size() > 0) profiles = new UserProfile[res.getEntries().size()];
for(int i=0; i< profiles.length; i++){
profiles[i] = profileFromResponse(res.getEntry());
}
return profiles;
} catch (Exception e) {
log.error("Could not search LDAP directory with error " + e.toString());
return null;
......
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