user format in IdmUser, implementd missing search methods
This commit is contained in:
parent
11c8c87022
commit
3b8da33ff3
1
pom.xml
1
pom.xml
|
@ -87,7 +87,6 @@
|
|||
<artifactId>gxJRS</artifactId>
|
||||
</dependency>
|
||||
|
||||
|
||||
<dependency>
|
||||
<groupId>org.glassfish.jersey.core</groupId>
|
||||
<artifactId>jersey-client</artifactId>
|
||||
|
|
|
@ -7,11 +7,12 @@ import java.net.URLEncoder;
|
|||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.com.fasterxml.jackson.databind.JavaType;
|
||||
import org.gcube.common.keycloak.model.UserInfo;
|
||||
import org.gcube.idm.client.beans.ResponseBean;
|
||||
import org.gcube.idm.client.clients.IdmRestClient;
|
||||
import org.gcube.idm.client.model.UserInfo;
|
||||
import org.gcube.idm.client.model.UserProfile;
|
||||
import org.gcube.idm.client.model.util.JsonUtilsCustom;
|
||||
import org.gcube.idm.common.models.IdmFullUser;
|
||||
|
@ -20,6 +21,7 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import jakarta.ws.rs.BadRequestException;
|
||||
import jakarta.ws.rs.NotAuthorizedException;
|
||||
|
||||
public class DefaultUsersClient extends AbstractIdmClient implements IdmUsersClient {
|
||||
protected String auth_token;
|
||||
|
@ -104,10 +106,19 @@ public class DefaultUsersClient extends AbstractIdmClient implements IdmUsersCli
|
|||
return resp.getResult();
|
||||
}
|
||||
|
||||
private HashMap<String, String> getSearchParameters(String format, Integer first, Integer max,
|
||||
@Override
|
||||
public UserInfo getUser(String user_id) {
|
||||
ResponseBean<UserInfo> resp = this.client.performGetRequest(pathForUserID(user_id, null),
|
||||
this.auth_token,
|
||||
UserInfo.class);
|
||||
|
||||
return resp.getResult();
|
||||
}
|
||||
|
||||
private HashMap<String, String> getSearchParameters(IdmUser.USERS_REPR format, Integer first, Integer max,
|
||||
SearchUsersParams params) {
|
||||
HashMap<String, String> parameters = new HashMap<String, String>();
|
||||
parameters.put("format", format);
|
||||
parameters.put("format", format.toString());
|
||||
if (first != null) {
|
||||
parameters.put("first", first.toString());
|
||||
}
|
||||
|
@ -134,7 +145,7 @@ public class DefaultUsersClient extends AbstractIdmClient implements IdmUsersCli
|
|||
@Override
|
||||
public List<String> searchUsernames(Integer first, Integer max, SearchUsersParams params) {
|
||||
HashMap<String, String> headers = IdmRestClient.getHeadersWithAuth(this.auth_token, null);
|
||||
HashMap<String, String> parameters = getSearchParameters("username", first, max, params);
|
||||
HashMap<String, String> parameters = getSearchParameters(IdmUser.USERS_REPR.username, first, max, params);
|
||||
JavaType listType = JsonUtilsCustom.geListOfObjectsType(String.class);
|
||||
ResponseBean<List<String>> resp = this.client.performGetRequest("/users/search", headers, parameters, listType);
|
||||
return resp.getResult();
|
||||
|
@ -143,7 +154,7 @@ public class DefaultUsersClient extends AbstractIdmClient implements IdmUsersCli
|
|||
@Override
|
||||
public List<IdmUser> searchUsers(Integer first, Integer max, SearchUsersParams params) {
|
||||
HashMap<String, String> headers = IdmRestClient.getHeadersWithAuth(this.auth_token, null);
|
||||
HashMap<String, String> parameters = getSearchParameters("compact", first, max, params);
|
||||
HashMap<String, String> parameters = getSearchParameters(IdmUser.USERS_REPR.compact, first, max, params);
|
||||
JavaType listType = JsonUtilsCustom.geListOfObjectsType(UserInfo.class);
|
||||
ResponseBean<List<IdmUser>> resp = this.client.performGetRequest("/users/search", headers, parameters,
|
||||
listType);
|
||||
|
@ -154,7 +165,7 @@ public class DefaultUsersClient extends AbstractIdmClient implements IdmUsersCli
|
|||
public List<IdmFullUser> searchFullUsers(Integer first, Integer max, SearchUsersParams params) {
|
||||
// TODO Auto-generated method stub
|
||||
HashMap<String, String> headers = IdmRestClient.getHeadersWithAuth(this.auth_token, null);
|
||||
HashMap<String, String> parameters = getSearchParameters("full", first, max, params);
|
||||
HashMap<String, String> parameters = getSearchParameters(IdmUser.USERS_REPR.full, first, max, params);
|
||||
JavaType listType = JsonUtilsCustom.geListOfObjectsType(IdmFullUser.class);
|
||||
ResponseBean<List<IdmFullUser>> resp = this.client.performGetRequest("/users/search", headers, parameters,
|
||||
listType);
|
||||
|
@ -162,8 +173,46 @@ public class DefaultUsersClient extends AbstractIdmClient implements IdmUsersCli
|
|||
}
|
||||
|
||||
@Override
|
||||
public org.gcube.idm.client.model.UserInfo getUser(String user_id) {
|
||||
// TODO Auto-generated method stub
|
||||
throw new UnsupportedOperationException("Unimplemented method 'getUser'");
|
||||
public List<String> searchEmails(Integer first, Integer max, SearchUsersParams params) {
|
||||
HashMap<String, String> headers = IdmRestClient.getHeadersWithAuth(this.auth_token, null);
|
||||
HashMap<String, String> parameters = getSearchParameters(IdmUser.USERS_REPR.email, first, max, params);
|
||||
JavaType listType = JsonUtilsCustom.geListOfObjectsType(String.class);
|
||||
ResponseBean<List<String>> resp = this.client.performGetRequest("/users/search", headers, parameters, listType);
|
||||
return resp.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> searchUsernamesEmails(Integer first, Integer max, SearchUsersParams params)
|
||||
throws NotAuthorizedException, BadRequestException {
|
||||
HashMap<String, String> headers = IdmRestClient.getHeadersWithAuth(this.auth_token, null);
|
||||
HashMap<String, String> parameters = getSearchParameters(IdmUser.USERS_REPR.username_email, first, max, params);
|
||||
|
||||
JavaType mapStringType = JsonUtilsCustom.geMapOfObjectsType(String.class, String.class);
|
||||
ResponseBean<Map<String, String>> resp = this.client.performGetRequest("/users/search", headers,
|
||||
parameters, mapStringType);
|
||||
return resp.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, IdmUser> searchUsernamesUsers(Integer first, Integer max, SearchUsersParams params)
|
||||
throws NotAuthorizedException, BadRequestException {
|
||||
HashMap<String, String> headers = IdmRestClient.getHeadersWithAuth(this.auth_token, null);
|
||||
|
||||
HashMap<String, String> parameters = getSearchParameters(IdmUser.USERS_REPR.username_user, first, max, params);
|
||||
|
||||
JavaType mapStringType = JsonUtilsCustom.geMapOfObjectsType(String.class, IdmUser.class);
|
||||
ResponseBean<Map<String, IdmUser>> resp = this.client.performGetRequest("/users/search", headers,
|
||||
parameters, mapStringType);
|
||||
return resp.getResult();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> searchFullnames(Integer first, Integer max, SearchUsersParams params)
|
||||
throws NotAuthorizedException, BadRequestException {
|
||||
HashMap<String, String> headers = IdmRestClient.getHeadersWithAuth(this.auth_token, null);
|
||||
HashMap<String, String> parameters = getSearchParameters(IdmUser.USERS_REPR.fullname, first, max, params);
|
||||
JavaType listType = JsonUtilsCustom.geListOfObjectsType(String.class);
|
||||
ResponseBean<List<String>> resp = this.client.performGetRequest("/users/search", headers, parameters, listType);
|
||||
return resp.getResult();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,8 @@ public class IdmClientFactory {
|
|||
// set a custom secret, instead of fetch it from IS
|
||||
public void setSecret(Secret secret) {
|
||||
this.secret = secret;
|
||||
this.setConfig(fetchIsConfig(secret));
|
||||
this.setConfig(null);
|
||||
// this.setConfig(fetchIsConfig(secret));
|
||||
}
|
||||
|
||||
// set a custom config for the factory, skipping or overriding the fetch from IS
|
||||
|
@ -57,6 +58,11 @@ public class IdmClientFactory {
|
|||
String error_message = "secret is null. invoke setSecret(secret) before fetching the configuration. ";
|
||||
throw new InternalServerErrorException(error_message);
|
||||
}
|
||||
|
||||
if (this.config == null) {
|
||||
this.config = fetchIsConfig(this.secret);
|
||||
}
|
||||
|
||||
return fetchIsConfig(this.secret);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package org.gcube.idm.client;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.idm.client.model.UserInfo;
|
||||
import org.gcube.idm.client.model.UserProfile;
|
||||
|
@ -30,6 +31,10 @@ public interface IdmUsersClient {
|
|||
public List<IdmFullUser> searchFullUsers(Integer first, Integer max, SearchUsersParams params) throws NotAuthorizedException, BadRequestException;
|
||||
|
||||
public List<String> searchUsernames(Integer first, Integer max, SearchUsersParams params) throws NotAuthorizedException, BadRequestException;
|
||||
public List<String> searchEmails(Integer first, Integer max, SearchUsersParams params) throws NotAuthorizedException, BadRequestException;
|
||||
public Map<String, String> searchUsernamesEmails(Integer first, Integer max, SearchUsersParams params) throws NotAuthorizedException, BadRequestException;
|
||||
public Map<String, IdmUser> searchUsernamesUsers(Integer first, Integer max, SearchUsersParams params) throws NotAuthorizedException, BadRequestException;
|
||||
public List<String> searchFullnames(Integer first, Integer max, SearchUsersParams params) throws NotAuthorizedException, BadRequestException;
|
||||
|
||||
public UserInfo getUser(String user_id);
|
||||
|
||||
|
|
|
@ -7,9 +7,12 @@ import static org.junit.Assert.assertNull;
|
|||
import java.io.IOException;
|
||||
import java.rmi.ServerException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.gcube.idm.client.IdmUsersClient;
|
||||
import org.gcube.idm.client.SearchUsersParams;
|
||||
import org.gcube.idm.client.model.UserInfo;
|
||||
import org.gcube.idm.client.model.UserProfile;
|
||||
import org.gcube.idm.common.models.IdmFullUser;
|
||||
import org.gcube.idm.common.models.IdmUser;
|
||||
import org.junit.Test;
|
||||
|
@ -17,20 +20,26 @@ import org.junit.Test;
|
|||
import jakarta.ws.rs.NotAuthorizedException;
|
||||
|
||||
public class IdmUsersClientTest extends ClientContextTest {
|
||||
// @Test
|
||||
// public void getUser() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
@Test
|
||||
public void getUser() throws IOException {
|
||||
IdmUsersClient client = getUserClient();
|
||||
UserInfo user = client.getUser("alfredo.oliviero");
|
||||
String expected = "alfredo.oliviero@isti.cnr.it";
|
||||
assertEquals(expected, user.user.getEmail());
|
||||
}
|
||||
|
||||
// @Test
|
||||
// public void getUserInspect() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void getUserProfile() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
@Test
|
||||
public void getUserProfile() throws IOException {
|
||||
IdmUsersClient client = getUserClient();
|
||||
UserProfile profile = client.getUserProfile("alfredo.oliviero");
|
||||
String expected = "alfredo.oliviero";
|
||||
assertEquals(expected, profile.getUsername());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getUserEmail() throws IOException {
|
||||
|
@ -42,46 +51,44 @@ public class IdmUsersClientTest extends ClientContextTest {
|
|||
|
||||
// @Test
|
||||
// public void getUserRolesRealm() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void getUserRolesClient() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void getUserGroups() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void getUserId() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void getUserUsername() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void getUserName() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
// @Test
|
||||
// public void getUserAttributes() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
|
||||
// @Test
|
||||
// public void getUserUser() throws IOException {
|
||||
// fail("Unimplemented");
|
||||
// fail("Unimplemented");
|
||||
// }
|
||||
|
||||
|
||||
// public String getUserEmail(String user_id);
|
||||
// public String getUserUsername(String user_id);
|
||||
// public TokenInfo getUserOwner(String user_id);
|
||||
|
@ -110,6 +117,36 @@ public class IdmUsersClientTest extends ClientContextTest {
|
|||
assertNotNull("expected to receive users", users);
|
||||
assertEquals("size expected 3", 3, users.size());
|
||||
}
|
||||
@Test
|
||||
public void searchEmail() throws IOException {
|
||||
IdmUsersClient client = getUserClient();
|
||||
List<String> emails = client.searchEmails(null, 3, null);
|
||||
assertNotNull("expected to receive emails", emails);
|
||||
assertEquals("size expected 3", 3, emails.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void searchUsernamesEmail() throws IOException {
|
||||
IdmUsersClient client = getUserClient();
|
||||
Map<String, String> users_emails = client.searchUsernamesEmails(null, 3, null);
|
||||
assertNotNull("expected to receive users", users_emails);
|
||||
assertEquals("size expected 3", 3, users_emails.size());
|
||||
}
|
||||
@Test
|
||||
public void searchUsernamesUsers() throws IOException {
|
||||
IdmUsersClient client = getUserClient();
|
||||
Map<String, IdmUser> users = client.searchUsernamesUsers(null, 3, null);
|
||||
assertNotNull("expected to receive users", users);
|
||||
assertEquals("size expected 3", 3, users.size());
|
||||
} @Test
|
||||
|
||||
public void searchFullnames() throws IOException {
|
||||
IdmUsersClient client = getUserClient();
|
||||
List<String> users = client.searchFullnames(null, 3, null);
|
||||
assertNotNull("expected to receive users", users);
|
||||
assertEquals("size expected 3", 3, users.size());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void searchFilteredFullUsers() throws IOException {
|
||||
|
|
Loading…
Reference in New Issue