forked from gCubeSystem/registry-publisher
token ora scope made mandatory
This commit is contained in:
parent
858c935b6c
commit
eb40fd0eeb
2
pom.xml
2
pom.xml
|
@ -21,7 +21,7 @@
|
|||
|
||||
<groupId>org.gcube.resources</groupId>
|
||||
<artifactId>registry-publisher</artifactId>
|
||||
<version>1.3.0-SNAPSHOT</version>
|
||||
<version>1.3.1-SNAPSHOT</version>
|
||||
|
||||
<dependencies>
|
||||
|
||||
|
|
|
@ -40,7 +40,7 @@ public class CollectorStubs implements RegistryStub {
|
|||
StringBuilder callUrl = new StringBuilder(endopoint).append("/").append(type);
|
||||
try {
|
||||
URL url = new URL(callUrl.toString());
|
||||
HttpURLConnection connection = makeRequest(url, "POST", false);
|
||||
HttpURLConnection connection = makeRequest(url, "POST");
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("Content-type", "text/xml");
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class CollectorStubs implements RegistryStub {
|
|||
StringBuilder callUrl = new StringBuilder(endopoint).append("/").append(type).append("/").append(id);
|
||||
try {
|
||||
URL url = new URL(callUrl.toString());
|
||||
HttpURLConnection connection = makeRequest(url, "PUT", false);
|
||||
HttpURLConnection connection = makeRequest(url, "PUT");
|
||||
connection.setDoOutput(true);
|
||||
connection.setRequestProperty("Content-type", "text/xml");
|
||||
|
||||
|
@ -85,7 +85,7 @@ public class CollectorStubs implements RegistryStub {
|
|||
StringBuilder callUrl = new StringBuilder(endopoint).append("/").append(type).append("/").append(id);
|
||||
try {
|
||||
URL url = new URL(callUrl.toString());
|
||||
HttpURLConnection connection = makeRequest(url, "DELETE", false);
|
||||
HttpURLConnection connection = makeRequest(url, "DELETE");
|
||||
connection.setDoInput(true);
|
||||
if (connection.getResponseCode()!=200){
|
||||
log.info("response code is not 200");
|
||||
|
@ -99,19 +99,18 @@ public class CollectorStubs implements RegistryStub {
|
|||
|
||||
|
||||
|
||||
private HttpURLConnection makeRequest(URL url, String method, boolean includeTokenInHeader) throws Exception{
|
||||
private HttpURLConnection makeRequest(URL url, String method) throws Exception{
|
||||
HttpURLConnection connection;
|
||||
if (url.toString().startsWith("https://"))
|
||||
connection = (HttpsURLConnection)url.openConnection();
|
||||
else connection = (HttpURLConnection)url.openConnection();
|
||||
|
||||
if (includeTokenInHeader){
|
||||
if (SecurityTokenProvider.instance.get()==null) throw new RuntimeException("null token passed");
|
||||
if (SecurityTokenProvider.instance.get()!=null)
|
||||
connection.setRequestProperty(TOKEN_HEADER_ENTRY,SecurityTokenProvider.instance.get());
|
||||
} else {
|
||||
if (ScopeProvider.instance.get()==null) throw new RuntimeException("null scope passed");
|
||||
else if (ScopeProvider.instance.get()!=null)
|
||||
connection.setRequestProperty(SCOPE_HEADER_ENTRY,ScopeProvider.instance.get());
|
||||
}
|
||||
else throw new RuntimeException("Collector requires authorization (via token or scope)");
|
||||
|
||||
connection.setRequestMethod(method);
|
||||
return connection;
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package org.gcube.informationsystem.publisher;
|
|||
|
||||
import static org.gcube.common.resources.gcore.Resources.print;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
||||
import org.gcube.common.resources.gcore.GCoreEndpoint;
|
||||
import org.gcube.common.resources.gcore.Resource;
|
||||
import org.gcube.common.resources.gcore.Resource.Type;
|
||||
|
@ -14,38 +16,39 @@ import org.slf4j.Logger;
|
|||
import org.slf4j.LoggerFactory;
|
||||
|
||||
public class GCoreEndpointPublisherTests {
|
||||
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(RegistryPublisherTests.class);
|
||||
static GCoreEndpoint running;
|
||||
static RegistryPublisher rp;
|
||||
static Resource r;
|
||||
|
||||
|
||||
@BeforeClass
|
||||
public static void init(){
|
||||
// ScopeProvider.instance.set("/d4science.research-infrastructures.eu/EUBrazilOpenBio");
|
||||
// ScopeProvider.instance.set("/d4science.research-infrastructures.eu/EUBrazilOpenBio");
|
||||
ScopeProvider.instance.set("/gcube/devNext");
|
||||
running = Resources.unmarshal(GCoreEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("gCoreEndpoint.xml"));
|
||||
SecurityTokenProvider.instance.set("52b59669-ccde-46d2-a4da-108b9e941f7c-98187548");
|
||||
rp=RegistryPublisherFactory.create();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void printTest(){
|
||||
print(running);
|
||||
//resource-specific tests
|
||||
//print(running);
|
||||
//resource-specific tests
|
||||
assertEquals(Type.GCOREENDPOINT,running.type());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void registerCreate(){
|
||||
r=rp.create(running);
|
||||
System.out.println("new resource created: ");
|
||||
if(r!=null)
|
||||
print(r);
|
||||
assertEquals(running,r);
|
||||
|
||||
for (int i = 0; i<10; i++) {
|
||||
running = Resources.unmarshal(GCoreEndpoint.class, PublisherTest.class.getClassLoader().getResourceAsStream("gCoreEndpoint.xml"));
|
||||
r=rp.create(running);
|
||||
System.out.println("new resource created: "+r.id());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@AfterClass
|
||||
|
||||
|
||||
/*@AfterClass
|
||||
public static void forceDeleteResource(){
|
||||
try {
|
||||
Thread.sleep(3000);
|
||||
|
@ -59,8 +62,8 @@ public class GCoreEndpointPublisherTests {
|
|||
advancedPublisher.forceRemove(r);
|
||||
ScopeProvider.instance.set(currentScope);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}*/
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
|
||||
<Resource version="0.4.x">
|
||||
<ID>5d244ab0-9d79-11e3-af18-dd5904b11dd6</ID>
|
||||
<ID></ID>
|
||||
<Type>RunningInstance</Type>
|
||||
<Scopes>
|
||||
</Scopes>
|
||||
|
|
Loading…
Reference in New Issue