Library migrated to d4science-iam-client
This commit is contained in:
parent
6602011176
commit
5cc91b7fbb
|
@ -35,7 +35,7 @@ public class ClientIDManager implements RenewalProvider {
|
||||||
@Override
|
@Override
|
||||||
public Secret renew(String context) throws Exception {
|
public Secret renew(String context) throws Exception {
|
||||||
if(d4ScienceIAMClientAuthn!=null && d4ScienceIAMClientAuthn.canBeRefreshed()) {
|
if(d4ScienceIAMClientAuthn!=null && d4ScienceIAMClientAuthn.canBeRefreshed()) {
|
||||||
d4ScienceIAMClientAuthn.refresh();
|
d4ScienceIAMClientAuthn.refresh(clientId, clientSecret);
|
||||||
return getJWTSecret(d4ScienceIAMClientAuthn);
|
return getJWTSecret(d4ScienceIAMClientAuthn);
|
||||||
}
|
}
|
||||||
return getSecret(context);
|
return getSecret(context);
|
||||||
|
|
|
@ -160,6 +160,7 @@ public class SocialService {
|
||||||
HttpURLConnection httpURLConnection = gxhttpStringRequest.get();
|
HttpURLConnection httpURLConnection = gxhttpStringRequest.get();
|
||||||
|
|
||||||
String ret = getResultAsString(httpURLConnection);
|
String ret = getResultAsString(httpURLConnection);
|
||||||
|
logger.trace("Got response from social service is {}", ret);
|
||||||
ObjectMapper mapper = new ObjectMapper();
|
ObjectMapper mapper = new ObjectMapper();
|
||||||
return mapper.readValue(ret, GCubeUser.class);
|
return mapper.readValue(ret, GCubeUser.class);
|
||||||
} catch(Exception e) {
|
} catch(Exception e) {
|
||||||
|
|
|
@ -6,13 +6,17 @@ import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
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.ContextTest;
|
||||||
import org.gcube.common.authorization.utils.clientid.ClientIDManager;
|
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.JWTSecret;
|
||||||
import org.gcube.common.authorization.utils.secret.Secret;
|
import org.gcube.common.authorization.utils.secret.Secret;
|
||||||
import org.gcube.common.authorization.utils.user.User;
|
import org.gcube.common.authorization.utils.user.User;
|
||||||
import org.gcube.common.iam.D4ScienceIAMClient;
|
import org.gcube.common.iam.D4ScienceIAMClient;
|
||||||
import org.gcube.common.iam.D4ScienceIAMClientAuthn;
|
import org.gcube.common.iam.D4ScienceIAMClientAuthn;
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
@ -73,11 +77,15 @@ public class SecretManagerTest extends ContextTest {
|
||||||
ClientIDManager clientIDManager = new ClientIDManager(clientId, clientSecret);
|
ClientIDManager clientIDManager = new ClientIDManager(clientId, clientSecret);
|
||||||
Secret secret = clientIDManager.getSecret(context);
|
Secret secret = clientIDManager.getSecret(context);
|
||||||
Map<String, String> map = secret.getHTTPAuthorizationHeaders();
|
Map<String, String> map = secret.getHTTPAuthorizationHeaders();
|
||||||
logger.debug("{}", map);
|
logger.debug("Generated HTTP Header {}", map);
|
||||||
|
|
||||||
map = clientIDManager.renew(context).getHTTPAuthorizationHeaders();
|
Map<String, String> newMap = clientIDManager.renew(context).getHTTPAuthorizationHeaders();
|
||||||
logger.debug("{}", map);
|
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
|
@Test
|
||||||
|
@ -103,9 +111,27 @@ public class SecretManagerTest extends ContextTest {
|
||||||
|
|
||||||
D4ScienceIAMClient iamClient = D4ScienceIAMClient.newInstance(context);
|
D4ScienceIAMClient iamClient = D4ScienceIAMClient.newInstance(context);
|
||||||
D4ScienceIAMClientAuthn d4ScienceIAMClientAuthn = iamClient.authenticate(clientId, clientSecret, context);
|
D4ScienceIAMClientAuthn d4ScienceIAMClientAuthn = iamClient.authenticate(clientId, clientSecret, context);
|
||||||
|
|
||||||
|
String accessToken = d4ScienceIAMClientAuthn.getAccessTokenString();
|
||||||
|
logger.info("Generated Access Token is {}", accessToken);
|
||||||
|
|
||||||
if(d4ScienceIAMClientAuthn!=null && d4ScienceIAMClientAuthn.canBeRefreshed()) {
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue