git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@131171 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
90edc18075
commit
8fd89e4942
|
@ -6,6 +6,7 @@ import javax.xml.bind.JAXBException;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.Policies;
|
import org.gcube.common.authorization.library.Policies;
|
||||||
|
import org.gcube.common.authorization.library.QualifiersList;
|
||||||
import org.gcube.common.authorization.library.policies.Policy;
|
import org.gcube.common.authorization.library.policies.Policy;
|
||||||
import org.gcube.common.authorization.library.provider.ClientInfo;
|
import org.gcube.common.authorization.library.provider.ClientInfo;
|
||||||
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
||||||
|
@ -17,7 +18,7 @@ public class Binder {
|
||||||
|
|
||||||
public static JAXBContext getContext() throws JAXBException{
|
public static JAXBContext getContext() throws JAXBException{
|
||||||
if (context==null)
|
if (context==null)
|
||||||
context = JAXBContext.newInstance(AuthorizationEntry.class, ClientInfo.class, UserInfo.class,
|
context = JAXBContext.newInstance(QualifiersList.class, AuthorizationEntry.class, ClientInfo.class, UserInfo.class,
|
||||||
ServiceInfo.class, Policies.class, Policy.class);
|
ServiceInfo.class, Policies.class, Policy.class);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,5 +33,7 @@ public interface AuthorizationProxy {
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
||||||
String requestActivation(ContainerInfo container, String context) throws Exception;
|
String requestActivation(ContainerInfo container, String context) throws Exception;
|
||||||
|
|
||||||
|
public Map<String, String> retrieveApiKeys() throws Exception;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,7 @@ import org.gcube.common.authorization.client.Constants;
|
||||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.Policies;
|
import org.gcube.common.authorization.library.Policies;
|
||||||
|
import org.gcube.common.authorization.library.QualifiersList;
|
||||||
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpoint;
|
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpoint;
|
||||||
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpointScanner;
|
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpointScanner;
|
||||||
import org.gcube.common.authorization.library.policies.Policy;
|
import org.gcube.common.authorization.library.policies.Policy;
|
||||||
|
@ -151,6 +152,34 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
return token;
|
return token;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
/**
|
||||||
|
* return a map with key qualifier and value token
|
||||||
|
*/
|
||||||
|
public Map<String, String> retrieveApiKeys() throws Exception{
|
||||||
|
String methodPath = "/apikey/";
|
||||||
|
|
||||||
|
int infrastructureHash = getInfrastructureHashFromToken(SecurityTokenProvider.instance.get());
|
||||||
|
|
||||||
|
|
||||||
|
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
|
||||||
|
|
||||||
|
System.out.println(callUrl);
|
||||||
|
|
||||||
|
URL url = new URL(callUrl.toString());
|
||||||
|
HttpURLConnection connection = makeRequest(url, "GET", true);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
|
||||||
|
if (connection.getResponseCode()!=200) throw new Exception("error retrieving keys (error code is "+connection.getResponseCode()+")");
|
||||||
|
if (connection.getContentLengthLong()<=0) return Collections.emptyMap();
|
||||||
|
|
||||||
|
try(InputStream stream = (InputStream)connection.getContent();){
|
||||||
|
QualifiersList entries = (QualifiersList)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
||||||
|
//cache.put(token, new AuthorizationEntryCache(entry));
|
||||||
|
return entries.getQualifiers();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private int getInfrastructureHashfromContext(String context) {
|
private int getInfrastructureHashfromContext(String context) {
|
||||||
try{
|
try{
|
||||||
|
|
|
@ -4,6 +4,7 @@ import static org.gcube.common.authorization.client.Constants.authorizationServi
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||||
import org.gcube.common.authorization.library.policies.Action;
|
import org.gcube.common.authorization.library.policies.Action;
|
||||||
|
@ -24,7 +25,7 @@ public class CallTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestNodeToken() throws Exception {
|
public void requestNodeToken() throws Exception {
|
||||||
String token = authorizationService().requestActivation(new ContainerInfo("dlib29.isti.cnr.it",8080), "/gcube");
|
String token = authorizationService().requestActivation(new ContainerInfo("dlib29.isti.cnr.it",8080), "/gcube/devNext");
|
||||||
System.out.println(token);
|
System.out.println(token);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -63,6 +64,15 @@ public class CallTest {
|
||||||
System.out.println(resolveToken(key));
|
System.out.println(resolveToken(key));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void retrieveApiKeys() throws Exception {
|
||||||
|
String token = requestTestToken("/gcube/devNext");
|
||||||
|
SecurityTokenProvider.instance.set(token);
|
||||||
|
Map<String, String> keys = authorizationService().retrieveApiKeys();
|
||||||
|
System.out.println("keys : "+keys);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void createTestToken() throws Exception {
|
public void createTestToken() throws Exception {
|
||||||
System.out.println(requestTestToken("/gcube/devsec"));
|
System.out.println(requestTestToken("/gcube/devsec"));
|
||||||
|
|
Loading…
Reference in New Issue