Library migrated to d4science-iam-client

This commit is contained in:
Luca Frosini 2024-11-08 15:34:52 +01:00
parent 6602011176
commit 5cc91b7fbb
3 changed files with 32 additions and 5 deletions

View File

@ -35,7 +35,7 @@ public class ClientIDManager implements RenewalProvider {
@Override
public Secret renew(String context) throws Exception {
if(d4ScienceIAMClientAuthn!=null && d4ScienceIAMClientAuthn.canBeRefreshed()) {
d4ScienceIAMClientAuthn.refresh();
d4ScienceIAMClientAuthn.refresh(clientId, clientSecret);
return getJWTSecret(d4ScienceIAMClientAuthn);
}
return getSecret(context);

View File

@ -160,6 +160,7 @@ public class SocialService {
HttpURLConnection httpURLConnection = gxhttpStringRequest.get();
String ret = getResultAsString(httpURLConnection);
logger.trace("Got response from social service is {}", ret);
ObjectMapper mapper = new ObjectMapper();
return mapper.readValue(ret, GCubeUser.class);
} catch(Exception e) {

View File

@ -6,13 +6,17 @@ import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.gcube.common.authorization.library.utils.Caller;
import org.gcube.common.authorization.utils.ContextTest;
import org.gcube.common.authorization.utils.clientid.ClientIDManager;
import org.gcube.common.authorization.utils.secret.GCubeSecret;
import org.gcube.common.authorization.utils.secret.JWTSecret;
import org.gcube.common.authorization.utils.secret.Secret;
import org.gcube.common.authorization.utils.user.User;
import org.gcube.common.iam.D4ScienceIAMClient;
import org.gcube.common.iam.D4ScienceIAMClientAuthn;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -73,11 +77,15 @@ public class SecretManagerTest extends ContextTest {
ClientIDManager clientIDManager = new ClientIDManager(clientId, clientSecret);
Secret secret = clientIDManager.getSecret(context);
Map<String, String> map = secret.getHTTPAuthorizationHeaders();
logger.debug("{}", map);
logger.debug("Generated HTTP Header {}", map);
map = clientIDManager.renew(context).getHTTPAuthorizationHeaders();
logger.debug("{}", map);
Map<String, String> newMap = clientIDManager.renew(context).getHTTPAuthorizationHeaders();
logger.debug("Refreshed HTTP Header {}", newMap);
Assert.assertTrue(map.size()==newMap.size());
for(String key : map.keySet()) {
Assert.assertTrue(map.get(key).compareTo(newMap.get(key))!=0);
}
}
@Test
@ -103,9 +111,27 @@ public class SecretManagerTest extends ContextTest {
D4ScienceIAMClient iamClient = D4ScienceIAMClient.newInstance(context);
D4ScienceIAMClientAuthn d4ScienceIAMClientAuthn = iamClient.authenticate(clientId, clientSecret, context);
String accessToken = d4ScienceIAMClientAuthn.getAccessTokenString();
logger.info("Generated Access Token is {}", accessToken);
if(d4ScienceIAMClientAuthn!=null && d4ScienceIAMClientAuthn.canBeRefreshed()) {
d4ScienceIAMClientAuthn.refresh();
d4ScienceIAMClientAuthn.refresh(clientId, clientSecret);
String refreshedAccessToken = d4ScienceIAMClientAuthn.getAccessTokenString();
logger.info("Refreshed Access Token is {}", refreshedAccessToken);
Assert.assertTrue(accessToken.compareTo(refreshedAccessToken)!=0);
}
}
@Ignore
@Test
public void testGcubeToken() throws Exception {
GCubeSecret gCubeSecret = new GCubeSecret("");
Caller caller = gCubeSecret.getCaller();
logger.debug("caller {}", caller);
User user = gCubeSecret.getUser();
logger.debug("user {}", user);
}
}