Added getSecret for a specific context
This commit is contained in:
parent
3fbcaf37ad
commit
356da003c7
|
@ -29,6 +29,17 @@ public class ClienIDManager implements RenewalProvider {
|
||||||
return jwtSecret;
|
return jwtSecret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Secret getSecret(String context) throws Exception {
|
||||||
|
TokenResponse tokenResponse = KeycloakClientFactory.newInstance().queryUMAToken(clientID, clientSecret, context, null);
|
||||||
|
|
||||||
|
JWTSecret jwtSecret = new JWTSecret(tokenResponse.getAccessToken());
|
||||||
|
jwtSecret.setRenewalProvider(this);
|
||||||
|
|
||||||
|
jwtSecret.setTokenResponse(tokenResponse);
|
||||||
|
|
||||||
|
return jwtSecret;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Secret renew() throws Exception {
|
public Secret renew() throws Exception {
|
||||||
return getSecret();
|
return getSecret();
|
||||||
|
|
|
@ -38,7 +38,7 @@ public class SocialService {
|
||||||
|
|
||||||
private static final String RESOURCE = "jersey-servlet";
|
private static final String RESOURCE = "jersey-servlet";
|
||||||
private static final String SERVICE_NAME = "SocialNetworking";
|
private static final String SERVICE_NAME = "SocialNetworking";
|
||||||
private static final String SERVICE_CLASSE = "Portal";
|
private static final String SERVICE_CLASS = "Portal";
|
||||||
|
|
||||||
private static Logger logger = LoggerFactory.getLogger(SocialService.class);
|
private static Logger logger = LoggerFactory.getLogger(SocialService.class);
|
||||||
private String serviceBasePath;
|
private String serviceBasePath;
|
||||||
|
@ -73,7 +73,7 @@ public class SocialService {
|
||||||
SecretManager secretManager = SecretManagerProvider.instance.get();
|
SecretManager secretManager = SecretManagerProvider.instance.get();
|
||||||
try {
|
try {
|
||||||
SimpleQuery query = queryFor(GCoreEndpoint.class);
|
SimpleQuery query = queryFor(GCoreEndpoint.class);
|
||||||
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'", SERVICE_CLASSE));
|
query.addCondition(String.format("$resource/Profile/ServiceClass/text() eq '%s'", SERVICE_CLASS));
|
||||||
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
|
query.addCondition("$resource/Profile/DeploymentData/Status/text() eq 'ready'");
|
||||||
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'", SERVICE_NAME));
|
query.addCondition(String.format("$resource/Profile/ServiceName/text() eq '%s'", SERVICE_NAME));
|
||||||
query.setResult(
|
query.setResult(
|
||||||
|
@ -84,20 +84,20 @@ public class SocialService {
|
||||||
List<String> endpoints = client.submit(query);
|
List<String> endpoints = client.submit(query);
|
||||||
if(endpoints == null || endpoints.isEmpty()) {
|
if(endpoints == null || endpoints.isEmpty()) {
|
||||||
throw new Exception("Cannot retrieve the GCoreEndpoint SERVICE_NAME: " + SERVICE_NAME
|
throw new Exception("Cannot retrieve the GCoreEndpoint SERVICE_NAME: " + SERVICE_NAME
|
||||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + secretManager.getContext());
|
+ ", SERVICE_CLASSE: " + SERVICE_CLASS + ", in scope: " + secretManager.getContext());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.serviceBasePath = endpoints.get(0);
|
this.serviceBasePath = endpoints.get(0);
|
||||||
|
|
||||||
if(serviceBasePath == null)
|
if(serviceBasePath == null)
|
||||||
throw new Exception("Endpoint:" + RESOURCE + ", is null for SERVICE_NAME: " + SERVICE_NAME
|
throw new Exception("Endpoint:" + RESOURCE + ", is null for SERVICE_NAME: " + SERVICE_NAME
|
||||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + secretManager.getContext());
|
+ ", SERVICE_CLASSE: " + SERVICE_CLASS + ", in scope: " + secretManager.getContext());
|
||||||
|
|
||||||
serviceBasePath = serviceBasePath.endsWith("/") ? serviceBasePath : serviceBasePath + "/";
|
serviceBasePath = serviceBasePath.endsWith("/") ? serviceBasePath : serviceBasePath + "/";
|
||||||
|
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
String error = "An error occurred during GCoreEndpoint discovery, SERVICE_NAME: " + SERVICE_NAME
|
String error = "An error occurred during GCoreEndpoint discovery, SERVICE_NAME: " + SERVICE_NAME
|
||||||
+ ", SERVICE_CLASSE: " + SERVICE_CLASSE + ", in scope: " + secretManager.getContext() + ".";
|
+ ", SERVICE_CLASSE: " + SERVICE_CLASS + ", in scope: " + secretManager.getContext() + ".";
|
||||||
logger.error(error, e);
|
logger.error(error, e);
|
||||||
throw new Exception(error);
|
throw new Exception(error);
|
||||||
}
|
}
|
||||||
|
|
|
@ -37,12 +37,12 @@ public class ContextTest {
|
||||||
throw new RuntimeException(e);
|
throw new RuntimeException(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
//DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
|
// DEFAULT_TEST_SCOPE_NAME = "/pred4s/preprod/preVRE";
|
||||||
// DEFAULT_TEST_SCOPE_NAME = "/gcube/devsec/devVRE";
|
// DEFAULT_TEST_SCOPE_NAME = "/gcube/devsec/devVRE";
|
||||||
|
|
||||||
ROOT = "/gcube";
|
ROOT = "/gcube";
|
||||||
// VO = ROOT + "/devsec";
|
// VO = ROOT + "/devsec";
|
||||||
// VRE = VO + "/devVRE";
|
// VRE = VO + "/devVRE";
|
||||||
VO = ROOT + "/devNext";
|
VO = ROOT + "/devNext";
|
||||||
VRE = VO + "/NextNext";
|
VRE = VO + "/NextNext";
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue