request for bunch token creation for service and container added
This commit is contained in:
parent
94d9901b11
commit
9ed284e2d1
|
@ -22,6 +22,7 @@
|
||||||
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
|
||||||
<attributes>
|
<attributes>
|
||||||
<attribute name="maven.pomderived" value="true"/>
|
<attribute name="maven.pomderived" value="true"/>
|
||||||
|
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||||
</attributes>
|
</attributes>
|
||||||
</classpathentry>
|
</classpathentry>
|
||||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8">
|
||||||
|
|
13
.project
13
.project
|
@ -5,6 +5,11 @@
|
||||||
<projects>
|
<projects>
|
||||||
</projects>
|
</projects>
|
||||||
<buildSpec>
|
<buildSpec>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
<buildCommand>
|
<buildCommand>
|
||||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||||
<arguments>
|
<arguments>
|
||||||
|
@ -15,9 +20,17 @@
|
||||||
<arguments>
|
<arguments>
|
||||||
</arguments>
|
</arguments>
|
||||||
</buildCommand>
|
</buildCommand>
|
||||||
|
<buildCommand>
|
||||||
|
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||||
|
<arguments>
|
||||||
|
</arguments>
|
||||||
|
</buildCommand>
|
||||||
</buildSpec>
|
</buildSpec>
|
||||||
<natures>
|
<natures>
|
||||||
|
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
|
||||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||||
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
<nature>org.eclipse.m2e.core.maven2Nature</nature>
|
||||||
|
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||||
</natures>
|
</natures>
|
||||||
</projectDescription>
|
</projectDescription>
|
||||||
|
|
|
@ -24,7 +24,7 @@
|
||||||
</fileSets>
|
</fileSets>
|
||||||
<files>
|
<files>
|
||||||
<file>
|
<file>
|
||||||
<source>target/${build.finalName}.war</source>
|
<source>target/${build.finalName}.jar</source>
|
||||||
<outputDirectory>/${artifactId}</outputDirectory>
|
<outputDirectory>/${artifactId}</outputDirectory>
|
||||||
</file>
|
</file>
|
||||||
</files>
|
</files>
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -77,7 +77,7 @@
|
||||||
<outputDirectory>target</outputDirectory>
|
<outputDirectory>target</outputDirectory>
|
||||||
<resources>
|
<resources>
|
||||||
<resource>
|
<resource>
|
||||||
<directory>${distroDirectory}</directory>
|
<directory>.</directory>
|
||||||
<filtering>true</filtering>
|
<filtering>true</filtering>
|
||||||
<includes>
|
<includes>
|
||||||
<include>profile.xml</include>
|
<include>profile.xml</include>
|
||||||
|
|
|
@ -12,6 +12,7 @@ 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;
|
||||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
|
import org.gcube.common.authorization.library.utils.AuthorizationEntryList;
|
||||||
import org.gcube.common.authorization.library.utils.ListMapper;
|
import org.gcube.common.authorization.library.utils.ListMapper;
|
||||||
|
|
||||||
public class Binder {
|
public class Binder {
|
||||||
|
@ -21,7 +22,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(ExternalServiceList.class, 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, ListMapper.class);
|
ServiceInfo.class, Policies.class, Policy.class, ListMapper.class, AuthorizationEntryList.class);
|
||||||
return context;
|
return context;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,6 +12,7 @@ import org.gcube.common.authorization.library.policies.Policy;
|
||||||
import org.gcube.common.authorization.library.provider.ContainerInfo;
|
import org.gcube.common.authorization.library.provider.ContainerInfo;
|
||||||
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
||||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
|
import org.gcube.common.authorization.library.utils.MultiServiceTokenRequest;
|
||||||
|
|
||||||
public interface AuthorizationProxy {
|
public interface AuthorizationProxy {
|
||||||
|
|
||||||
|
@ -20,6 +21,8 @@ public interface AuthorizationProxy {
|
||||||
void setEndpoint(EndpointsContainer endpoints);
|
void setEndpoint(EndpointsContainer endpoints);
|
||||||
|
|
||||||
AuthorizationEntry get(String token) throws ObjectNotFound, Exception;
|
AuthorizationEntry get(String token) throws ObjectNotFound, Exception;
|
||||||
|
|
||||||
|
List<AuthorizationEntry> get(List<String> tokens) throws ObjectNotFound, Exception;
|
||||||
|
|
||||||
void addPolicies(List<Policy> policies) throws Exception;
|
void addPolicies(List<Policy> policies) throws Exception;
|
||||||
|
|
||||||
|
@ -30,6 +33,9 @@ public interface AuthorizationProxy {
|
||||||
String generateApiKey(String apiQualifier) throws Exception;
|
String generateApiKey(String apiQualifier) throws Exception;
|
||||||
|
|
||||||
String generateServiceToken(ServiceInfo client) throws Exception;
|
String generateServiceToken(ServiceInfo client) throws Exception;
|
||||||
|
|
||||||
|
List<String> generateServiceToken(ServiceInfo client, List<String> containerTokens) throws Exception;
|
||||||
|
|
||||||
|
|
||||||
String generateUserToken(UserInfo client, String context)
|
String generateUserToken(UserInfo client, String context)
|
||||||
throws Exception;
|
throws Exception;
|
||||||
|
|
|
@ -36,7 +36,9 @@ import org.gcube.common.authorization.library.provider.ContainerInfo;
|
||||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||||
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
import org.gcube.common.authorization.library.provider.ServiceInfo;
|
||||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
|
import org.gcube.common.authorization.library.utils.AuthorizationEntryList;
|
||||||
import org.gcube.common.authorization.library.utils.ListMapper;
|
import org.gcube.common.authorization.library.utils.ListMapper;
|
||||||
|
import org.gcube.common.authorization.library.utils.MultiServiceTokenRequest;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
@ -55,10 +57,15 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
|
|
||||||
private String getInternalEnpoint(int infrastructureHash){
|
private String getInternalEnpoint(int infrastructureHash){
|
||||||
AuthorizationEndpoint ae = getEndpoint(infrastructureHash);
|
AuthorizationEndpoint ae = getEndpoint(infrastructureHash);
|
||||||
|
return getInternalEnpoint(ae);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getInternalEnpoint(AuthorizationEndpoint ae){
|
||||||
StringBuilder endpoint = new StringBuilder(ae.isSecureConnection()?"https://":"http://").append(ae.getHost()).append(":")
|
StringBuilder endpoint = new StringBuilder(ae.isSecureConnection()?"https://":"http://").append(ae.getHost()).append(":")
|
||||||
.append(ae.getPort()).append("/authorization-service/gcube/service");
|
.append(ae.getPort()).append("/authorization-service/gcube/service");
|
||||||
return endpoint.toString();
|
return endpoint.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateServiceToken(ServiceInfo client) throws Exception {
|
public String generateServiceToken(ServiceInfo client) throws Exception {
|
||||||
|
@ -74,7 +81,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setRequestProperty("Content-type", "application/xml");
|
connection.setRequestProperty("Content-type", "application/xml");
|
||||||
|
|
||||||
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
||||||
Binder.getContext().createMarshaller().marshal(client, os);
|
Binder.getContext().createMarshaller().marshal(client, os);
|
||||||
}
|
}
|
||||||
|
@ -94,6 +101,44 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<String> generateServiceToken(ServiceInfo client, List<String> containerTokens) throws Exception {
|
||||||
|
|
||||||
|
String methodPath = "/token/service/bunch";
|
||||||
|
|
||||||
|
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, "PUT", true);
|
||||||
|
connection.setDoOutput(true);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
connection.setRequestProperty("Content-type", "application/xml");
|
||||||
|
|
||||||
|
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
||||||
|
Binder.getContext().createMarshaller().marshal(new MultiServiceTokenRequest(containerTokens, client), os);
|
||||||
|
}
|
||||||
|
|
||||||
|
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
||||||
|
|
||||||
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||||
|
List<String> tokensToReturn = new ArrayList<String>();
|
||||||
|
|
||||||
|
try(InputStream stream = (InputStream)connection.getContent();){
|
||||||
|
ListMapper entries = (ListMapper)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
||||||
|
|
||||||
|
for (String token: entries.getList())
|
||||||
|
tokensToReturn.add(Utils.addInfrastructureHashToToken(token, infrastructureHash));
|
||||||
|
return tokensToReturn;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateExternalServiceToken(String serviceId) throws Exception {
|
public String generateExternalServiceToken(String serviceId) throws Exception {
|
||||||
|
|
||||||
|
@ -122,7 +167,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
|
|
||||||
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String resolveTokenByUserAndContext(String user, String context) throws ObjectNotFound, Exception {
|
public String resolveTokenByUserAndContext(String user, String context) throws ObjectNotFound, Exception {
|
||||||
|
|
||||||
|
@ -134,7 +179,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
|
|
||||||
URL url = new URL(callUrl.toString());
|
URL url = new URL(callUrl.toString());
|
||||||
HttpURLConnection connection = makeRequest(url, "GET", false);
|
HttpURLConnection connection = makeRequest(url, "GET", false);
|
||||||
|
|
||||||
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
||||||
|
|
||||||
if (connection.getResponseCode()==404) throw new ObjectNotFound("token not found");
|
if (connection.getResponseCode()==404) throw new ObjectNotFound("token not found");
|
||||||
|
@ -151,7 +196,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
|
|
||||||
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String generateUserToken(UserInfo client, String context) throws Exception {
|
public String generateUserToken(UserInfo client, String context) throws Exception {
|
||||||
|
|
||||||
|
@ -186,7 +231,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
|
|
||||||
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setTokenRoles(String token, List<String> roles) throws Exception {
|
public void setTokenRoles(String token, List<String> roles) throws Exception {
|
||||||
|
|
||||||
|
@ -194,7 +239,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
String methodPath = String.format("/token/user/%s/roles",realToken);
|
String methodPath = String.format("/token/user/%s/roles",realToken);
|
||||||
|
|
||||||
int infrastructureHash = Utils.getInfrastructureHashFromToken(token, endpoints.getDefaultInfrastructure());
|
int infrastructureHash = Utils.getInfrastructureHashFromToken(token, endpoints.getDefaultInfrastructure());
|
||||||
|
|
||||||
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
|
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
|
||||||
|
|
||||||
URL url = new URL(callUrl.toString());
|
URL url = new URL(callUrl.toString());
|
||||||
|
@ -202,9 +247,8 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
connection.setDoOutput(true);
|
connection.setDoOutput(true);
|
||||||
connection.setDoInput(true);
|
connection.setDoInput(true);
|
||||||
connection.setRequestProperty("Content-type", "application/xml");
|
connection.setRequestProperty("Content-type", "application/xml");
|
||||||
|
|
||||||
ListMapper listmapper = new ListMapper();
|
ListMapper listmapper = new ListMapper(roles);
|
||||||
listmapper.setList(roles);
|
|
||||||
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
||||||
Binder.getContext().createMarshaller().marshal(listmapper, os);
|
Binder.getContext().createMarshaller().marshal(listmapper, os);
|
||||||
}
|
}
|
||||||
|
@ -212,17 +256,17 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
||||||
|
|
||||||
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeAllReleatedToken(String clientId, String context) throws Exception{
|
public void removeAllReleatedToken(String clientId, String context) throws Exception{
|
||||||
String methodPath = "/token/user";
|
String methodPath = "/token/user";
|
||||||
int infrastructureHash = Utils.getInfrastructureHashfromContext(context);
|
int infrastructureHash = Utils.getInfrastructureHashfromContext(context);
|
||||||
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append("?")
|
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append("?")
|
||||||
.append(CONTEXT_PARAM).append("=").append(context).append("&").append(CLIENT_ID_PARAM).append("=").append(clientId);
|
.append(CONTEXT_PARAM).append("=").append(context).append("&").append(CLIENT_ID_PARAM).append("=").append(clientId);
|
||||||
|
|
||||||
URL url = new URL(callUrl.toString());
|
URL url = new URL(callUrl.toString());
|
||||||
HttpURLConnection connection = makeRequest(url, "DELETE", false);
|
HttpURLConnection connection = makeRequest(url, "DELETE", false);
|
||||||
//connection.setDoOutput(false);
|
//connection.setDoOutput(false);
|
||||||
|
@ -231,7 +275,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
|
||||||
|
|
||||||
if (connection.getResponseCode()!=200 && connection.getResponseCode()!=204) throw new Exception("error contacting authorization service");
|
if (connection.getResponseCode()!=200 && connection.getResponseCode()!=204) throw new Exception("error contacting authorization service");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -292,16 +336,16 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
QualifiersList entries = (QualifiersList)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
QualifiersList entries = (QualifiersList)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
||||||
tokensQulifiersMap = entries.getQualifiers();
|
tokensQulifiersMap = entries.getQualifiers();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (tokensQulifiersMap!=null && !tokensQulifiersMap.isEmpty()){
|
if (tokensQulifiersMap!=null && !tokensQulifiersMap.isEmpty()){
|
||||||
Map<String, String> toReturnMap = new HashMap<String, String>();
|
Map<String, String> toReturnMap = new HashMap<String, String>();
|
||||||
for (Entry<String, String> entry: tokensQulifiersMap.entrySet())
|
for (Entry<String, String> entry: tokensQulifiersMap.entrySet())
|
||||||
toReturnMap.put(entry.getKey(), Utils.addInfrastructureHashToToken(entry.getValue(), infrastructureHash));
|
toReturnMap.put(entry.getKey(), Utils.addInfrastructureHashToToken(entry.getValue(), infrastructureHash));
|
||||||
return toReturnMap;
|
return toReturnMap;
|
||||||
} else return Collections.emptyMap();
|
} else return Collections.emptyMap();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
/**
|
/**
|
||||||
* return a map with key external service id and value token
|
* return a map with key external service id and value token
|
||||||
|
@ -327,14 +371,14 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
ExternalServiceList entries = (ExternalServiceList)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
ExternalServiceList entries = (ExternalServiceList)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
||||||
externalServiceMap = entries.getExternalServiceMap();
|
externalServiceMap = entries.getExternalServiceMap();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (externalServiceMap!=null && !externalServiceMap.isEmpty()){
|
if (externalServiceMap!=null && !externalServiceMap.isEmpty()){
|
||||||
Map<String, String> toReturnMap = new HashMap<String, String>();
|
Map<String, String> toReturnMap = new HashMap<String, String>();
|
||||||
for (Entry<String, String> entry: externalServiceMap.entrySet())
|
for (Entry<String, String> entry: externalServiceMap.entrySet())
|
||||||
toReturnMap.put(entry.getKey(), Utils.addInfrastructureHashToToken(entry.getValue(), infrastructureHash));
|
toReturnMap.put(entry.getKey(), Utils.addInfrastructureHashToToken(entry.getValue(), infrastructureHash));
|
||||||
return toReturnMap;
|
return toReturnMap;
|
||||||
} else return Collections.emptyMap();
|
} else return Collections.emptyMap();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -424,7 +468,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
final String methodPath = "/token/";
|
final String methodPath = "/token/";
|
||||||
|
|
||||||
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHashFromToken))
|
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHashFromToken))
|
||||||
.append(methodPath).append(realToken);
|
.append(methodPath).append(realToken);
|
||||||
|
|
||||||
URL url = new URL(callUrl.toString());
|
URL url = new URL(callUrl.toString());
|
||||||
HttpURLConnection connection = makeRequest(url, "GET", false);
|
HttpURLConnection connection = makeRequest(url, "GET", false);
|
||||||
|
@ -441,6 +485,50 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<AuthorizationEntry> get(List<String> tokens) throws ObjectNotFound, Exception {
|
||||||
|
|
||||||
|
List<String> realTokens = new ArrayList<String>();
|
||||||
|
|
||||||
|
List<AuthorizationEntry> toReturn = new ArrayList<AuthorizationEntry>();
|
||||||
|
|
||||||
|
AuthorizationEndpoint endpoint = null;
|
||||||
|
|
||||||
|
for (String token : tokens) {
|
||||||
|
String realToken = Utils.getRealToken(token);
|
||||||
|
|
||||||
|
if (cache.containsKey(realToken) && cache.get(realToken).isValid(endpoint.getClientCacheValidity()))
|
||||||
|
toReturn.add(cache.get(realToken).getEntry());
|
||||||
|
else realTokens.add(realToken);
|
||||||
|
|
||||||
|
if (endpoint==null) {
|
||||||
|
int infrastructureHashFromToken = Utils.getInfrastructureHashFromToken(token, endpoints.getDefaultInfrastructure());
|
||||||
|
endpoint = getEndpoint(infrastructureHashFromToken);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
final String methodPath = "/resolve/?";
|
||||||
|
|
||||||
|
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(endpoint))
|
||||||
|
.append(methodPath);
|
||||||
|
|
||||||
|
for (String toAppend : realTokens)
|
||||||
|
callUrl= callUrl.append("token=").append(toAppend);
|
||||||
|
|
||||||
|
URL url = new URL(callUrl.toString());
|
||||||
|
HttpURLConnection connection = makeRequest(url, "GET", false);
|
||||||
|
connection.setDoInput(true);
|
||||||
|
|
||||||
|
if (connection.getResponseCode()==404) throw new ObjectNotFound("token not found");
|
||||||
|
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service (error code is "+connection.getResponseCode()+")");
|
||||||
|
if (connection.getContentLengthLong()==0) return null;
|
||||||
|
|
||||||
|
try(InputStream stream = (InputStream)connection.getContent();){
|
||||||
|
AuthorizationEntryList entries = (AuthorizationEntryList)Binder.getContext().createUnmarshaller().unmarshal(stream);
|
||||||
|
return entries.getEntries();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addPolicies(List<Policy> policies) throws Exception {
|
public void addPolicies(List<Policy> policies) throws Exception {
|
||||||
|
@ -503,7 +591,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
||||||
final String methodPath = "/symmKey/";
|
final String methodPath = "/symmKey/";
|
||||||
|
|
||||||
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure())))
|
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure())))
|
||||||
.append(methodPath);
|
.append(methodPath);
|
||||||
|
|
||||||
URL url = new URL(callUrl.toString());
|
URL url = new URL(callUrl.toString());
|
||||||
HttpURLConnection connection = makeRequest(url, "GET", true);
|
HttpURLConnection connection = makeRequest(url, "GET", true);
|
||||||
|
|
|
@ -28,7 +28,6 @@ import org.gcube.common.authorization.library.provider.UserInfo;
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@Ignore
|
|
||||||
public class CallTest {
|
public class CallTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -36,12 +35,19 @@ public class CallTest {
|
||||||
System.out.println("pred4s".hashCode() & 0xfffffff);
|
System.out.println("pred4s".hashCode() & 0xfffffff);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void requestActivation() throws Exception {
|
||||||
|
SecurityTokenProvider.instance.set("b653566c-2983-4a0e-a0a9-b913636469a8-98187548");
|
||||||
|
//ic-test.dev.int.d4science.net b653566c-2983-4a0e-a0a9-b913636469a8-98187548 80 /home/gcube/.containerxml/2-container.xml /gcube /gcube/devNext
|
||||||
|
String token = authorizationService().requestActivation(new ContainerInfo("ic-test.dev.int.d4science.net", 80), "/gcube/devNext") ;
|
||||||
|
System.out.println(token);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void requestUserTokenViaUserNameAndScope() throws Exception {
|
public void requestUserTokenViaUserNameAndScope() throws Exception {
|
||||||
String token = authorizationService().resolveTokenByUserAndContext("valentina.marioli", "/gcube");
|
AuthorizationEntry token = authorizationService().get("d9431600-9fef-41a7-946d-a5b402de30d6-98187548");
|
||||||
authorizationService().setTokenRoles(token, Arrays.asList("VOManager"));
|
System.out.println(token);
|
||||||
AuthorizationEntry authEntry = authorizationService().get(token);
|
|
||||||
System.out.println(authEntry.getClientInfo().toString());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Reference in New Issue