added functionality to hide repos/roles from beta to production and vice versa
This commit is contained in:
parent
940fd326ad
commit
6d492ae919
|
@ -14,6 +14,7 @@ import org.springframework.beans.factory.annotation.Value;
|
|||
import org.springframework.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
@ -29,7 +30,7 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
public final RegistryUtils jsonUtils;
|
||||
|
||||
@Autowired
|
||||
RegistryCalls(@Value("${registry.coid:2}") String coid,
|
||||
RegistryCalls(@Value("${aai.registry.coid:2}") String coid,
|
||||
HttpUtils httpUtils, RegistryUtils registryUtils) {
|
||||
this.coid = coid;
|
||||
this.httpUtils = httpUtils;
|
||||
|
@ -121,7 +122,7 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
Map<String, String> params = new HashMap<>();
|
||||
params.put("coid", coid);
|
||||
if (name != null) {
|
||||
params.put("name", name.toLowerCase());
|
||||
params.put("name", URLEncoder.encode(name).toLowerCase());
|
||||
}
|
||||
JsonElement response = httpUtils.get("cous.json", params);
|
||||
return (response != null) ? response.getAsJsonObject().get("Cous").getAsJsonArray() : new JsonArray();
|
||||
|
@ -245,6 +246,9 @@ public class RegistryCalls implements AaiRegistryService {
|
|||
@Override
|
||||
public JsonArray getUserEmailByCouId(Integer couId, boolean admin) {
|
||||
Map<String, String> params = new HashMap<>();
|
||||
if (couId == null) {
|
||||
throw new IllegalArgumentException("Provided 'couId' is null");
|
||||
}
|
||||
params.put("couid", couId.toString());
|
||||
if (admin) {
|
||||
params.put("admin", "true");
|
||||
|
|
|
@ -8,6 +8,7 @@ import org.springframework.stereotype.Service;
|
|||
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Collection;
|
||||
import java.util.Objects;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@Service("roleMappingService")
|
||||
|
@ -15,7 +16,7 @@ public class AaiRoleMappingService implements RoleMappingService {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(AaiRoleMappingService.class);
|
||||
|
||||
@Value("${registry.production:true}")
|
||||
@Value("${aai.registry.production:true}")
|
||||
private boolean production;
|
||||
|
||||
|
||||
|
@ -33,6 +34,9 @@ public class AaiRoleMappingService implements RoleMappingService {
|
|||
|
||||
@Override
|
||||
public String getRepoIdByRoleId(String roleId) {
|
||||
if (!roleActive(roleId)) {
|
||||
return null;
|
||||
}
|
||||
return roleId.replaceFirst(".*datasource\\.", "").replace("$", ":");
|
||||
}
|
||||
|
||||
|
@ -40,7 +44,9 @@ public class AaiRoleMappingService implements RoleMappingService {
|
|||
public Collection<String> getRepoIdsByRoleIds(Collection<String> roleIds) {
|
||||
return roleIds
|
||||
.stream()
|
||||
//.filter(this::roleActive) // implicitly executed in the next statement
|
||||
.map(this::getRepoIdByRoleId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
|
@ -62,13 +68,14 @@ public class AaiRoleMappingService implements RoleMappingService {
|
|||
return repoIds
|
||||
.stream()
|
||||
.map(this::getRoleIdByRepoId)
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.toList());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String convertAuthorityIdToRepoId(String authorityId) {
|
||||
String repo = "";
|
||||
if (authorityId != null) {
|
||||
if (authorityId != null && roleActive(authorityId)) {
|
||||
repo = authorityId
|
||||
.replaceFirst(".*datasource\\.", "")
|
||||
.replace("$", ":")
|
||||
|
@ -105,4 +112,9 @@ public class AaiRoleMappingService implements RoleMappingService {
|
|||
String role = convertRepoIdToEncodedAuthorityId(repoId);
|
||||
return new SimpleGrantedAuthority(role);
|
||||
}
|
||||
|
||||
private boolean roleActive(String roleId) {
|
||||
return (production && !roleId.toLowerCase().startsWith("beta."))
|
||||
|| (!production && roleId.toLowerCase().startsWith("beta."));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,16 +18,13 @@ public class HttpUtils {
|
|||
|
||||
private static final Logger logger = Logger.getLogger(HttpUtils.class);
|
||||
|
||||
//TODO: refactor
|
||||
// TODO: To be changed the values
|
||||
// @Value("https://aai.openaire.eu/registry/")
|
||||
@Value("https://openaire-dev.aai-dev.grnet.gr/registry/")
|
||||
private String issuer;
|
||||
@Value("${aai.registry.url}")
|
||||
private String registryUrl;
|
||||
|
||||
@Value("kostis30fylloy")
|
||||
@Value("${aai.registry.authentication.username}")
|
||||
private String user;
|
||||
|
||||
@Value("fynhWc7F*2y4me4U")
|
||||
@Value("${aai.registry.authentication.password}")
|
||||
private String password;
|
||||
|
||||
public JsonElement post(String path, JsonObject body) {
|
||||
|
@ -35,7 +32,7 @@ public class HttpUtils {
|
|||
HttpHeaders headers = createHeaders(user, password);
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<String> request = new HttpEntity<>(body.toString(), headers);
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(issuer + path, HttpMethod.POST, request, String.class);
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(registryUrl + path, HttpMethod.POST, request, String.class);
|
||||
return getResponseEntityAsJsonElement(responseEntity);
|
||||
}
|
||||
|
||||
|
@ -44,13 +41,13 @@ public class HttpUtils {
|
|||
HttpHeaders headers = createHeaders(user, password);
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
HttpEntity<String> request = new HttpEntity<>(body.toString(), headers);
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(issuer + path, HttpMethod.PUT, request, String.class);
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange(registryUrl + path, HttpMethod.PUT, request, String.class);
|
||||
return getResponseEntityAsJsonElement(responseEntity);
|
||||
}
|
||||
|
||||
public JsonElement get(String path, Map<String, String> params) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = issuer + path + ((params != null) ? createParams(params) : null);
|
||||
String url = registryUrl + path + ((params != null) ? createParams(params) : null);
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange
|
||||
(url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class);
|
||||
return getResponseEntityAsJsonElement(responseEntity);
|
||||
|
@ -58,7 +55,7 @@ public class HttpUtils {
|
|||
|
||||
public JsonElement delete(String path) {
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
String url = issuer + path;
|
||||
String url = registryUrl + path;
|
||||
ResponseEntity<String> responseEntity = restTemplate.exchange
|
||||
(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class);
|
||||
return getResponseEntityAsJsonElement(responseEntity);
|
||||
|
|
Loading…
Reference in New Issue