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">
|
||||
<attributes>
|
||||
<attribute name="maven.pomderived" value="true"/>
|
||||
<attribute name="org.eclipse.jst.component.nondependency" value=""/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<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>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.common.project.facet.core.builder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
|
@ -15,9 +20,17 @@
|
|||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.wst.validation.validationbuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<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.m2e.core.maven2Nature</nature>
|
||||
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
</fileSets>
|
||||
<files>
|
||||
<file>
|
||||
<source>target/${build.finalName}.war</source>
|
||||
<source>target/${build.finalName}.jar</source>
|
||||
<outputDirectory>/${artifactId}</outputDirectory>
|
||||
</file>
|
||||
</files>
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -77,7 +77,7 @@
|
|||
<outputDirectory>target</outputDirectory>
|
||||
<resources>
|
||||
<resource>
|
||||
<directory>${distroDirectory}</directory>
|
||||
<directory>.</directory>
|
||||
<filtering>true</filtering>
|
||||
<includes>
|
||||
<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.ServiceInfo;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.authorization.library.utils.AuthorizationEntryList;
|
||||
import org.gcube.common.authorization.library.utils.ListMapper;
|
||||
|
||||
public class Binder {
|
||||
|
@ -21,7 +22,7 @@ public class Binder {
|
|||
public static JAXBContext getContext() throws JAXBException{
|
||||
if (context==null)
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.ServiceInfo;
|
||||
import org.gcube.common.authorization.library.provider.UserInfo;
|
||||
import org.gcube.common.authorization.library.utils.MultiServiceTokenRequest;
|
||||
|
||||
public interface AuthorizationProxy {
|
||||
|
||||
|
@ -21,6 +22,8 @@ public interface AuthorizationProxy {
|
|||
|
||||
AuthorizationEntry get(String token) throws ObjectNotFound, Exception;
|
||||
|
||||
List<AuthorizationEntry> get(List<String> tokens) throws ObjectNotFound, Exception;
|
||||
|
||||
void addPolicies(List<Policy> policies) throws Exception;
|
||||
|
||||
void removePolicies(long ... ids) throws Exception;
|
||||
|
@ -31,6 +34,9 @@ public interface AuthorizationProxy {
|
|||
|
||||
String generateServiceToken(ServiceInfo client) throws Exception;
|
||||
|
||||
List<String> generateServiceToken(ServiceInfo client, List<String> containerTokens) throws Exception;
|
||||
|
||||
|
||||
String generateUserToken(UserInfo client, String context)
|
||||
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.ServiceInfo;
|
||||
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.MultiServiceTokenRequest;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
|
@ -55,11 +57,16 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
|
||||
private String getInternalEnpoint(int 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(":")
|
||||
.append(ae.getPort()).append("/authorization-service/gcube/service");
|
||||
return endpoint.toString();
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String generateServiceToken(ServiceInfo client) throws Exception {
|
||||
|
||||
|
@ -94,6 +101,44 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
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
|
||||
public String generateExternalServiceToken(String serviceId) throws Exception {
|
||||
|
||||
|
@ -203,8 +248,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
|
|||
connection.setDoInput(true);
|
||||
connection.setRequestProperty("Content-type", "application/xml");
|
||||
|
||||
ListMapper listmapper = new ListMapper();
|
||||
listmapper.setList(roles);
|
||||
ListMapper listmapper = new ListMapper(roles);
|
||||
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
|
||||
Binder.getContext().createMarshaller().marshal(listmapper, os);
|
||||
}
|
||||
|
@ -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
|
||||
public void addPolicies(List<Policy> policies) throws Exception {
|
||||
|
|
|
@ -28,7 +28,6 @@ import org.gcube.common.authorization.library.provider.UserInfo;
|
|||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
|
||||
@Ignore
|
||||
public class CallTest {
|
||||
|
||||
@Test
|
||||
|
@ -36,12 +35,19 @@ public class CallTest {
|
|||
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
|
||||
public void requestUserTokenViaUserNameAndScope() throws Exception {
|
||||
String token = authorizationService().resolveTokenByUserAndContext("valentina.marioli", "/gcube");
|
||||
authorizationService().setTokenRoles(token, Arrays.asList("VOManager"));
|
||||
AuthorizationEntry authEntry = authorizationService().get(token);
|
||||
System.out.println(authEntry.getClientInfo().toString());
|
||||
AuthorizationEntry token = authorizationService().get("d9431600-9fef-41a7-946d-a5b402de30d6-98187548");
|
||||
System.out.println(token);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Reference in New Issue