git-svn-id: http://svn.research-infrastructures.eu/public/d4science/gcube/trunk/Common/authorization-common-client@134513 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
parent
3e0fcc2485
commit
e0972c8291
|
@ -5,6 +5,7 @@ import javax.xml.bind.JAXBContext;
|
|||
import javax.xml.bind.JAXBException;
|
||||
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.ExternalServiceList;
|
||||
import org.gcube.common.authorization.library.Policies;
|
||||
import org.gcube.common.authorization.library.QualifiersList;
|
||||
import org.gcube.common.authorization.library.policies.Policy;
|
||||
|
@ -18,7 +19,7 @@ public class Binder {
|
|||
|
||||
public static JAXBContext getContext() throws JAXBException{
|
||||
if (context==null)
|
||||
context = JAXBContext.newInstance(QualifiersList.class, AuthorizationEntry.class, ClientInfo.class, UserInfo.class,
|
||||
context = JAXBContext.newInstance(ExternalServiceList.class, QualifiersList.class, AuthorizationEntry.class, ClientInfo.class, UserInfo.class,
|
||||
ServiceInfo.class, Policies.class, Policy.class);
|
||||
return context;
|
||||
}
|
||||
|
|
|
@ -48,4 +48,6 @@ public interface AuthorizationProxy {
|
|||
String generateExternalServiceToken(String serviceId)
|
||||
throws Exception;
|
||||
|
||||
Map<String, String> retrieveExternalServiceGenerated() throws Exception;
|
||||
|
||||
}
|
||||
|
|
|
@ -24,6 +24,7 @@ import org.gcube.common.authorization.client.Binder;
|
|||
import org.gcube.common.authorization.client.Constants;
|
||||
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
|
||||
import org.gcube.common.authorization.library.AuthorizationEntry;
|
||||
import org.gcube.common.authorization.library.ExternalServiceList;
|
||||
import org.gcube.common.authorization.library.Policies;
|
||||
import org.gcube.common.authorization.library.QualifiersList;
|
||||
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpoint;
|
||||
|
@ -236,7 +237,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
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();
|
||||
if (connection.getContentLengthLong()==0) return Collections.emptyMap();
|
||||
|
||||
Map<String, String> tokensQulifiersMap;
|
||||
try(InputStream stream = (InputStream)connection.getContent();){
|
||||
|
@ -253,6 +254,40 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
/**
|
||||
* return a map with key external service id and value token
|
||||
*/
|
||||
public Map<String, String> retrieveExternalServiceGenerated() throws Exception{
|
||||
String methodPath = "/token/external";
|
||||
|
||||
int infrastructureHash = Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure());
|
||||
|
||||
|
||||
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
|
||||
|
||||
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 externalServices (error code is "+connection.getResponseCode()+")");
|
||||
if (connection.getContentLengthLong()==0) return Collections.emptyMap();
|
||||
|
||||
Map<String, String> externalServiceMap;
|
||||
try(InputStream stream = (InputStream)connection.getContent();){
|
||||
ExternalServiceList entries = (ExternalServiceList)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
||||
externalServiceMap = entries.getExternalServiceMap();
|
||||
}
|
||||
|
||||
if (externalServiceMap!=null && !externalServiceMap.isEmpty()){
|
||||
Map<String, String> toReturnMap = new HashMap<String, String>();
|
||||
for (Entry<String, String> entry: externalServiceMap.entrySet())
|
||||
toReturnMap.put(entry.getKey(), Utils.addInfrastructureHashToToken(entry.getValue(), infrastructureHash));
|
||||
return toReturnMap;
|
||||
} else return Collections.emptyMap();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String requestActivation(ContainerInfo container, String context) throws Exception {
|
||||
|
|
Loading…
Reference in New Issue