diff --git a/src/main/java/org/gcube/common/authorization/utils/clientid/ClientIDManager.java b/src/main/java/org/gcube/common/authorization/utils/clientid/ClientIDManager.java index 9098081..e617402 100644 --- a/src/main/java/org/gcube/common/authorization/utils/clientid/ClientIDManager.java +++ b/src/main/java/org/gcube/common/authorization/utils/clientid/ClientIDManager.java @@ -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); diff --git a/src/main/java/org/gcube/common/authorization/utils/socialservice/SocialService.java b/src/main/java/org/gcube/common/authorization/utils/socialservice/SocialService.java index 8f492c8..f93166d 100644 --- a/src/main/java/org/gcube/common/authorization/utils/socialservice/SocialService.java +++ b/src/main/java/org/gcube/common/authorization/utils/socialservice/SocialService.java @@ -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) { diff --git a/src/test/java/org/gcube/common/authorization/utils/manager/SecretManagerTest.java b/src/test/java/org/gcube/common/authorization/utils/manager/SecretManagerTest.java index 414aa3b..23c22f7 100644 --- a/src/test/java/org/gcube/common/authorization/utils/manager/SecretManagerTest.java +++ b/src/test/java/org/gcube/common/authorization/utils/manager/SecretManagerTest.java @@ -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 map = secret.getHTTPAuthorizationHeaders(); - logger.debug("{}", map); + logger.debug("Generated HTTP Header {}", map); - map = clientIDManager.renew(context).getHTTPAuthorizationHeaders(); - logger.debug("{}", map); + Map 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); + } + }