2 |
2 |
|
3 |
3 |
import eu.dnetlib.parthenos.publisher.ParthenosPublisherException;
|
4 |
4 |
import eu.dnetlib.parthenos.publisher.SaxonHelper;
|
|
5 |
import org.apache.commons.lang3.StringUtils;
|
5 |
6 |
import org.apache.commons.logging.Log;
|
6 |
7 |
import org.apache.commons.logging.LogFactory;
|
|
8 |
import org.gcube.common.authorization.client.Constants;
|
|
9 |
import org.gcube.common.authorization.library.AuthorizationEntry;
|
|
10 |
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
|
11 |
import org.gcube.common.scope.api.ScopeProvider;
|
7 |
12 |
import org.gcube.informationsystem.resourceregistry.client.ParthenosRegistryClientSetter;
|
8 |
13 |
import org.gcube.informationsystem.resourceregistry.publisher.ParthenosRegistryPublisherSetter;
|
9 |
14 |
import org.springframework.beans.factory.annotation.Autowired;
|
... | ... | |
24 |
29 |
private String registryBaseURL;
|
25 |
30 |
@Value("${gcube.registry.uri.base.default}")
|
26 |
31 |
private String defaultBaseURI;
|
|
32 |
@Value("${gcube.registry.application.token}")
|
|
33 |
private String applicationToken;
|
27 |
34 |
|
28 |
35 |
@Autowired
|
29 |
36 |
private SaxonHelper saxonHelper;
|
... | ... | |
32 |
39 |
|
33 |
40 |
public RegistryClient getRegistryClient() throws ParthenosPublisherException {
|
34 |
41 |
log.debug("Creating RegistryClient for "+registryBaseURL);
|
|
42 |
return new RegistryClient(registryBaseURL, getSaxonHelper(), defaultBaseURI, getResourceGenerator());
|
|
43 |
}
|
|
44 |
|
|
45 |
public RegistryClientFactory() throws Exception {
|
|
46 |
log.info("Creating RegistryClientFactory");
|
35 |
47 |
ParthenosRegistryClientSetter.forceToURL(registryBaseURL);
|
36 |
48 |
ParthenosRegistryPublisherSetter.forceToURL(registryBaseURL);
|
37 |
|
return new RegistryClient(registryBaseURL, getSaxonHelper(), defaultBaseURI, getResourceGenerator());
|
|
49 |
log.info("Registry URL forced to "+registryBaseURL);
|
|
50 |
if(StringUtils.isNotBlank(getApplicationToken())) {
|
|
51 |
RegistryClientFactory.setContext(getApplicationToken());
|
|
52 |
log.info("GCube Context set");
|
|
53 |
}
|
|
54 |
else{
|
|
55 |
log.fatal("GCube context cannot be configured without a value in gcube.registry.application.token");
|
|
56 |
}
|
38 |
57 |
}
|
39 |
58 |
|
|
59 |
public static String getCurrentScope(String token) throws Exception {
|
|
60 |
AuthorizationEntry authorizationEntry = Constants.authorizationService().get(token);
|
|
61 |
String context = authorizationEntry.getContext();
|
|
62 |
log.info("Context of token "+token+" is: "+context);
|
|
63 |
return context;
|
|
64 |
}
|
|
65 |
|
|
66 |
public static void setContext(String token) throws Exception {
|
|
67 |
SecurityTokenProvider.instance.set(token);
|
|
68 |
ScopeProvider.instance.set(getCurrentScope(token));
|
|
69 |
}
|
|
70 |
|
|
71 |
public String getApplicationToken() {
|
|
72 |
return applicationToken;
|
|
73 |
}
|
|
74 |
|
|
75 |
public void setApplicationToken(final String applicationToken) {
|
|
76 |
this.applicationToken = applicationToken;
|
|
77 |
}
|
|
78 |
|
|
79 |
|
40 |
80 |
public String getRegistryBaseURL() {
|
41 |
81 |
return registryBaseURL;
|
42 |
82 |
}
|
Configuring connection to gcube registry