Revision 61422
Added by Konstantinos Spyrou almost 3 years ago
modules/uoa-repository-manager-service/branches/aai_roles_new/src/main/java/eu/dnetlib/repo/manager/service/aai/registry/RegistryCalls.java | ||
---|---|---|
14 | 14 |
import org.springframework.security.core.context.SecurityContextHolder; |
15 | 15 |
import org.springframework.stereotype.Service; |
16 | 16 |
|
17 |
import java.net.URLEncoder; |
|
17 | 18 |
import java.util.ArrayList; |
18 | 19 |
import java.util.HashMap; |
19 | 20 |
import java.util.List; |
... | ... | |
29 | 30 |
public final RegistryUtils jsonUtils; |
30 | 31 |
|
31 | 32 |
@Autowired |
32 |
RegistryCalls(@Value("${registry.coid:2}") String coid, |
|
33 |
RegistryCalls(@Value("${aai.registry.coid:2}") String coid,
|
|
33 | 34 |
HttpUtils httpUtils, RegistryUtils registryUtils) { |
34 | 35 |
this.coid = coid; |
35 | 36 |
this.httpUtils = httpUtils; |
... | ... | |
121 | 122 |
Map<String, String> params = new HashMap<>(); |
122 | 123 |
params.put("coid", coid); |
123 | 124 |
if (name != null) { |
124 |
params.put("name", name.toLowerCase());
|
|
125 |
params.put("name", URLEncoder.encode(name).toLowerCase());
|
|
125 | 126 |
} |
126 | 127 |
JsonElement response = httpUtils.get("cous.json", params); |
127 | 128 |
return (response != null) ? response.getAsJsonObject().get("Cous").getAsJsonArray() : new JsonArray(); |
... | ... | |
245 | 246 |
@Override |
246 | 247 |
public JsonArray getUserEmailByCouId(Integer couId, boolean admin) { |
247 | 248 |
Map<String, String> params = new HashMap<>(); |
249 |
if (couId == null) { |
|
250 |
throw new IllegalArgumentException("Provided 'couId' is null"); |
|
251 |
} |
|
248 | 252 |
params.put("couid", couId.toString()); |
249 | 253 |
if (admin) { |
250 | 254 |
params.put("admin", "true"); |
modules/uoa-repository-manager-service/branches/aai_roles_new/src/main/java/eu/dnetlib/repo/manager/service/security/AaiRoleMappingService.java | ||
---|---|---|
8 | 8 |
|
9 | 9 |
import java.net.URLEncoder; |
10 | 10 |
import java.util.Collection; |
11 |
import java.util.Objects; |
|
11 | 12 |
import java.util.stream.Collectors; |
12 | 13 |
|
13 | 14 |
@Service("roleMappingService") |
... | ... | |
15 | 16 |
|
16 | 17 |
private static final Logger logger = Logger.getLogger(AaiRoleMappingService.class); |
17 | 18 |
|
18 |
@Value("${registry.production:true}") |
|
19 |
@Value("${aai.registry.production:true}")
|
|
19 | 20 |
private boolean production; |
20 | 21 |
|
21 | 22 |
|
... | ... | |
33 | 34 |
|
34 | 35 |
@Override |
35 | 36 |
public String getRepoIdByRoleId(String roleId) { |
37 |
if (!roleActive(roleId)) { |
|
38 |
return null; |
|
39 |
} |
|
36 | 40 |
return roleId.replaceFirst(".*datasource\\.", "").replace("$", ":"); |
37 | 41 |
} |
38 | 42 |
|
... | ... | |
40 | 44 |
public Collection<String> getRepoIdsByRoleIds(Collection<String> roleIds) { |
41 | 45 |
return roleIds |
42 | 46 |
.stream() |
47 |
//.filter(this::roleActive) // implicitly executed in the next statement |
|
43 | 48 |
.map(this::getRepoIdByRoleId) |
49 |
.filter(Objects::nonNull) |
|
44 | 50 |
.collect(Collectors.toList()); |
45 | 51 |
} |
46 | 52 |
|
... | ... | |
62 | 68 |
return repoIds |
63 | 69 |
.stream() |
64 | 70 |
.map(this::getRoleIdByRepoId) |
71 |
.filter(Objects::nonNull) |
|
65 | 72 |
.collect(Collectors.toList()); |
66 | 73 |
} |
67 | 74 |
|
68 | 75 |
@Override |
69 | 76 |
public String convertAuthorityIdToRepoId(String authorityId) { |
70 | 77 |
String repo = ""; |
71 |
if (authorityId != null) { |
|
78 |
if (authorityId != null && roleActive(authorityId)) {
|
|
72 | 79 |
repo = authorityId |
73 | 80 |
.replaceFirst(".*datasource\\.", "") |
74 | 81 |
.replace("$", ":") |
... | ... | |
105 | 112 |
String role = convertRepoIdToEncodedAuthorityId(repoId); |
106 | 113 |
return new SimpleGrantedAuthority(role); |
107 | 114 |
} |
115 |
|
|
116 |
private boolean roleActive(String roleId) { |
|
117 |
return (production && !roleId.toLowerCase().startsWith("beta.")) |
|
118 |
|| (!production && roleId.toLowerCase().startsWith("beta.")); |
|
119 |
} |
|
108 | 120 |
} |
modules/uoa-repository-manager-service/branches/aai_roles_new/src/main/java/eu/dnetlib/repo/manager/utils/HttpUtils.java | ||
---|---|---|
18 | 18 |
|
19 | 19 |
private static final Logger logger = Logger.getLogger(HttpUtils.class); |
20 | 20 |
|
21 |
//TODO: refactor |
|
22 |
// TODO: To be changed the values |
|
23 |
// @Value("https://aai.openaire.eu/registry/") |
|
24 |
@Value("https://openaire-dev.aai-dev.grnet.gr/registry/") |
|
25 |
private String issuer; |
|
21 |
@Value("${aai.registry.url}") |
|
22 |
private String registryUrl; |
|
26 | 23 |
|
27 |
@Value("kostis30fylloy")
|
|
24 |
@Value("${aai.registry.authentication.username}")
|
|
28 | 25 |
private String user; |
29 | 26 |
|
30 |
@Value("fynhWc7F*2y4me4U")
|
|
27 |
@Value("${aai.registry.authentication.password}")
|
|
31 | 28 |
private String password; |
32 | 29 |
|
33 | 30 |
public JsonElement post(String path, JsonObject body) { |
... | ... | |
35 | 32 |
HttpHeaders headers = createHeaders(user, password); |
36 | 33 |
headers.setContentType(MediaType.APPLICATION_JSON); |
37 | 34 |
HttpEntity<String> request = new HttpEntity<>(body.toString(), headers); |
38 |
ResponseEntity<String> responseEntity = restTemplate.exchange(issuer + path, HttpMethod.POST, request, String.class);
|
|
35 |
ResponseEntity<String> responseEntity = restTemplate.exchange(registryUrl + path, HttpMethod.POST, request, String.class);
|
|
39 | 36 |
return getResponseEntityAsJsonElement(responseEntity); |
40 | 37 |
} |
41 | 38 |
|
... | ... | |
44 | 41 |
HttpHeaders headers = createHeaders(user, password); |
45 | 42 |
headers.setContentType(MediaType.APPLICATION_JSON); |
46 | 43 |
HttpEntity<String> request = new HttpEntity<>(body.toString(), headers); |
47 |
ResponseEntity<String> responseEntity = restTemplate.exchange(issuer + path, HttpMethod.PUT, request, String.class);
|
|
44 |
ResponseEntity<String> responseEntity = restTemplate.exchange(registryUrl + path, HttpMethod.PUT, request, String.class);
|
|
48 | 45 |
return getResponseEntityAsJsonElement(responseEntity); |
49 | 46 |
} |
50 | 47 |
|
51 | 48 |
public JsonElement get(String path, Map<String, String> params) { |
52 | 49 |
RestTemplate restTemplate = new RestTemplate(); |
53 |
String url = issuer + path + ((params != null) ? createParams(params) : null);
|
|
50 |
String url = registryUrl + path + ((params != null) ? createParams(params) : null);
|
|
54 | 51 |
ResponseEntity<String> responseEntity = restTemplate.exchange |
55 | 52 |
(url, HttpMethod.GET, new HttpEntity<>(createHeaders(user, password)), String.class); |
56 | 53 |
return getResponseEntityAsJsonElement(responseEntity); |
... | ... | |
58 | 55 |
|
59 | 56 |
public JsonElement delete(String path) { |
60 | 57 |
RestTemplate restTemplate = new RestTemplate(); |
61 |
String url = issuer + path;
|
|
58 |
String url = registryUrl + path;
|
|
62 | 59 |
ResponseEntity<String> responseEntity = restTemplate.exchange |
63 | 60 |
(url, HttpMethod.DELETE, new HttpEntity<>(createHeaders(user, password)), String.class); |
64 | 61 |
return getResponseEntityAsJsonElement(responseEntity); |
Also available in: Unified diff
added functionality to hide repos/roles from beta to production and vice versa