Compare commits

...

10 Commits

Author SHA1 Message Date
lucio 39f0fec6df changed dep from jaxb-runtime to jaxb-impl 2024-05-15 16:58:07 +02:00
Lucio Lelii e759732c53 Merge branch 'master' of https://code-repo.d4science.org/gCubeSystem/authorization-client 2024-05-15 11:28:59 +02:00
lucio de8215a357 moved to jakarta 2024-03-12 10:36:15 +01:00
Luca Frosini cd56803026 Update 'src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java'
Removed tokens
2023-11-06 16:36:55 +01:00
lucio 314591588e commit for release 2023-08-03 15:38:59 +02:00
lucio 6f50eab47d updated 2023-02-08 16:29:45 +01:00
Lucio Lelii ef5922163e porting to smartgears 4 2022-06-15 17:52:25 +02:00
Lucio Lelii 181d6f80d0 porting to smartgears 4 2022-06-13 12:07:08 +02:00
lucio d0fa2589a7 Merge branch 'master' of
gitea@code-repo.d4science.org:gCubeSystem/authorization-client.git

Conflicts:
	pom.xml
2020-03-18 09:22:49 +01:00
lucio 972820734f get(List<String>) modified for update of authorization service 2020-03-18 09:12:26 +01:00
18 changed files with 89 additions and 952 deletions

View File

@ -1,5 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.m2e.MAVEN2_CLASSPATH_CONTAINER">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
<attributes>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
@ -8,26 +25,15 @@
</classpathentry>
<classpathentry kind="src" output="target/test-classes" path="src/test/java">
<attributes>
<attribute name="test" value="true"/>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<classpathentry excluding="**" kind="src" output="target/test-classes" path="src/test/resources">
<attributes>
<attribute name="test" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</classpathentry>
<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">
<classpathentry excluding="**" kind="src" output="target/classes" path="src/main/resources">
<attributes>
<attribute name="maven.pomderived" value="true"/>
<attribute name="optional" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="output" path="target/classes"/>

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
/target/

View File

@ -1,14 +1,16 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.compliance=11
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.problem.forbiddenReference=warning
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=ignore
org.eclipse.jdt.core.compiler.release=disabled
org.eclipse.jdt.core.compiler.source=1.8
org.eclipse.jdt.core.compiler.source=11

12
CHANGELOG.md Normal file
View File

@ -0,0 +1,12 @@
This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
# Changelog for legacy Authorization Client
## [v3.0.1-SNAPSHOT] - 2022-06-13
- moved to jakarta
## [v3.0.0] - 2022-06-13
- First Release

View File

@ -1,6 +1,6 @@
# Authorization Client
StorageHub implements the gCube Workspace feature
client for legacy gcube authorization
## Structure of the project

View File

@ -1,14 +0,0 @@
<ReleaseNotes>
<Changeset component="authorization-client-1.0.0" date="2015-05-18">
<Change>First Release</Change>
</Changeset>
<Changeset component="authorization-client-2.0.0" date="2016-09-30">
<Change>moving to auth2 service</Change>
</Changeset>
<Changeset component="authorization-client-2.0.1" date="2016-11-25">
<Change>added calls for ExternalServiceToken generator</Change>
</Changeset>
<Changeset component="authorization-client-2.0.6" date="2016-11-25">
<Change>added setRoles for a specific token</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,32 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>.</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README.md</include>
<include>LICENSE.md</include>
<include>changelog.xml</include>
<include>profile.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

View File

@ -1 +0,0 @@
${gcube.license}

View File

@ -1,59 +0,0 @@
The gCube System - ${name}
--------------------------------------------------
${description}
${gcube.description}
${gcube.funding}
Version
--------------------------------------------------
${version} (${buildDate})
Please see the file named "changelog.xml" in this directory for the release notes.
Authors
--------------------------------------------------
* Lucio Lelii (lucio.lelii-AT-isti.cnr.it), CNR, Italy
Maintainers
--------------------------------------------------
* Lucio Lelii (lucio.lelii-AT-isti.cnr.it), CNR, Italy
Download information
--------------------------------------------------
Source code is available from SVN:
${scm.url}
Binaries can be downloaded from the gCube website:
${gcube.website}
Installation
--------------------------------------------------
Installation documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}
Documentation
--------------------------------------------------
Documentation is available on-line in the gCube Wiki:
${gcube.wikiRoot}
Support
--------------------------------------------------
Bugs and support requests can be reported in the gCube issue tracking tool:
${gcube.issueTracking}
Licensing
--------------------------------------------------
This software is licensed under the terms you may find in the file named "LICENSE" in this directory.

View File

@ -1,11 +0,0 @@
<ReleaseNotes>
<Changeset component="authorization-client-1.0.0" date="2015-05-18">
<Change>First Release</Change>
</Changeset>
<Changeset component="authorization-client-2.0.0" date="2016-09-30">
<Change>moving to auth2 service</Change>
</Changeset>
<Changeset component="authorization-client-2.0.1" date="2016-11-25">
<Change>added calls for ExternalServiceToken generator</Change>
</Changeset>
</ReleaseNotes>

View File

@ -1,35 +0,0 @@
<assembly
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
<id>servicearchive</id>
<formats>
<format>tar.gz</format>
</formats>
<baseDirectory>/</baseDirectory>
<fileSets>
<fileSet>
<directory>${distroDirectory}</directory>
<outputDirectory>/</outputDirectory>
<useDefaultExcludes>true</useDefaultExcludes>
<includes>
<include>README</include>
<include>LICENSE</include>
<include>changelog.xml</include>
</includes>
<fileMode>755</fileMode>
<filtered>true</filtered>
</fileSet>
</fileSets>
<files>
<file>
<source>${distroDirectory}/profile.xml</source>
<outputDirectory>/</outputDirectory>
<filtered>true</filtered>
</file>
<file>
<source>target/${build.finalName}.jar</source>
<outputDirectory>/${artifactId}</outputDirectory>
</file>
</files>
</assembly>

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID />
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>Common</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

95
pom.xml
View File

@ -1,53 +1,54 @@
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<version>2.0.6</version>
<version>3.0.1-SNAPSHOT</version>
<name>authorization service client library</name>
<parent>
<artifactId>maven-parent</artifactId>
<groupId>org.gcube.tools</groupId>
<version>1.1.0</version>
<version>1.2.0</version>
</parent>
<!--
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<version>3.0.1-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
-->
<scm>
<connection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
<connection>
scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</connection>
<developerConnection>
scm:git:https://code-repo.d4science.org/gCubeSystem/${project.artifactId}.git</developerConnection>
<url>https://code-repo.d4science.org/gCubeSystem/${project.artifactId}</url>
</scm>
<properties>
<distroDirectory>distro</distroDirectory>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<version>[2.0.0, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -58,63 +59,7 @@
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.13</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>copy-profile</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target</outputDirectory>
<resources>
<resource>
<directory>.</directory>
<filtering>true</filtering>
<includes>
<include>profile.xml</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptors>
<descriptor>descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

View File

@ -1,26 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<Resource xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<ID />
<Type>Service</Type>
<Profile>
<Description>${description}</Description>
<Class>Common</Class>
<Name>${artifactId}</Name>
<Version>1.0.0</Version>
<Packages>
<Software>
<Name>${artifactId}</Name>
<Version>${version}</Version>
<MavenCoordinates>
<groupId>${groupId}</groupId>
<artifactId>${artifactId}</artifactId>
<version>${version}</version>
</MavenCoordinates>
<Files>
<File>${build.finalName}.jar</File>
</Files>
</Software>
</Packages>
</Profile>
</Resource>

View File

@ -1,9 +1,6 @@
package org.gcube.common.authorization.client;
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;
@ -16,6 +13,9 @@ 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 jakarta.xml.bind.JAXBContext;
import jakarta.xml.bind.JAXBException;
public class Binder {
private static JAXBContext context;

View File

@ -1,18 +1,12 @@
package org.gcube.common.authorization.client.proxy;
import java.io.File;
import java.util.List;
import java.util.Map;
import org.gcube.common.authorization.client.exceptions.ObjectNotFound;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpoint;
import org.gcube.common.authorization.library.enpoints.EndpointsContainer;
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.endpoints.AuthorizationEndpoint;
import org.gcube.common.authorization.library.endpoints.EndpointsContainer;
import org.gcube.common.authorization.library.provider.UserInfo;
import org.gcube.common.authorization.library.utils.MultiServiceTokenRequest;
public interface AuthorizationProxy {
@ -23,39 +17,13 @@ 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;
List<Policy> getPolicies(String context) throws Exception;
String generateApiKey(String apiQualifier) throws Exception;
String generateServiceToken(ServiceInfo client) throws Exception;
List<String> generateServiceToken(ServiceInfo client, List<String> containerTokens) throws Exception;
String generateUserToken(UserInfo client, String context)
throws Exception;
String requestActivation(ContainerInfo container) throws Exception;
String requestActivation(ContainerInfo container, String context) throws Exception;
Map<String, String> retrieveApiKeys() throws Exception;
File getSymmKey(String filePath) throws Exception;
String resolveTokenByUserAndContext(String user, String context)
throws Exception;
String generateExternalServiceToken(String serviceId)
throws Exception;
Map<String, String> retrieveExternalServiceGenerated() throws Exception;
void removeAllReleatedToken(String clientId, String context) throws Exception;
void setTokenRoles(String token, List<String> roles) throws Exception;

View File

@ -1,12 +1,10 @@
package org.gcube.common.authorization.client.proxy;
import static org.gcube.common.authorization.client.Constants.CONTEXT_PARAM;
import static org.gcube.common.authorization.client.Constants.CLIENT_ID_PARAM;
import static org.gcube.common.authorization.client.Constants.CONTEXT_PARAM;
import java.io.BufferedOutputStream;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
@ -17,29 +15,18 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.stream.Collectors;
import javax.net.ssl.HttpsURLConnection;
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;
import org.gcube.common.authorization.library.enpoints.AuthorizationEndpointScanner;
import org.gcube.common.authorization.library.enpoints.EndpointsContainer;
import org.gcube.common.authorization.library.policies.Policy;
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.endpoints.AuthorizationEndpoint;
import org.gcube.common.authorization.library.endpoints.AuthorizationEndpointScanner;
import org.gcube.common.authorization.library.endpoints.EndpointsContainer;
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;
@ -68,111 +55,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
}
@Override
public String generateServiceToken(ServiceInfo client) throws Exception {
String methodPath = "/token/service";
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(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");
String token= "";
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null)
result.append(line);
token = result.toString();
}
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);
List<String> realTokens = containerTokens.stream().map(t -> Utils.getRealToken(t)).collect(Collectors.toList());
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(realTokens, 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 {
String methodPath = "/token/external/";
int infrastructureHash = Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure());
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append(serviceId);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
String token= "";
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null)
result.append(line);
token = result.toString();
}
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
}
@Override
public String resolveTokenByUserAndContext(String user, String context) throws ObjectNotFound, Exception {
@ -183,7 +66,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append(user).append("?context=").append(context);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "GET", false);
HttpURLConnection connection = makeRequest(url, "GET");
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
@ -213,7 +96,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
.append(CONTEXT_PARAM).append("=").append(context);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", false);
HttpURLConnection connection = makeRequest(url, "PUT");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
@ -248,7 +131,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", false);
HttpURLConnection connection = makeRequest(url, "PUT");
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
@ -274,7 +157,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
.append(CONTEXT_PARAM).append("=").append(context).append("&").append(CLIENT_ID_PARAM).append("=").append(clientId);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "DELETE", false);
HttpURLConnection connection = makeRequest(url, "DELETE");
//connection.setDoOutput(false);
connection.setDoInput(true);
@ -283,181 +166,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
if (connection.getResponseCode()!=200 && connection.getResponseCode()!=204) throw new Exception("error contacting authorization service");
}
@Override
public String generateApiKey(String apiQualifier) throws Exception {
String methodPath = String.format("/apikey?qualifier=%s",apiQualifier);
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.setDoInput(true);
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(0);
connection.setRequestProperty("Content-type", "application/xml");
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
String token= "";
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null)
result.append(line);
token = result.toString();
}
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
}
@Override
/**
* return a map with key qualifier and value token
*/
public Map<String, String> retrieveApiKeys() throws Exception{
String methodPath = "/apikey/";
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 keys (error code is "+connection.getResponseCode()+")");
if (connection.getContentLengthLong()==0) return Collections.emptyMap();
Map<String, String> tokensQulifiersMap;
try(InputStream stream = (InputStream)connection.getContent();){
QualifiersList entries = (QualifiersList)Binder.getContext().createUnmarshaller().unmarshal(stream);
tokensQulifiersMap = entries.getQualifiers();
}
if (tokensQulifiersMap!=null && !tokensQulifiersMap.isEmpty()){
Map<String, String> toReturnMap = new HashMap<String, String>();
for (Entry<String, String> entry: tokensQulifiersMap.entrySet())
toReturnMap.put(entry.getKey(), Utils.addInfrastructureHashToToken(entry.getValue(), infrastructureHash));
return toReturnMap;
} else return Collections.emptyMap();
}
@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 {
String methodPath = "/token/node";
int infrastructureHash = Utils.getInfrastructureHashfromContext(context);
StringBuilder callUrl;
callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append("?context=").append(context);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", false);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
Binder.getContext().createMarshaller().marshal(container, os);
}
log.debug("response code is "+connection.getResponseCode());
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
String token= "";
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null)
result.append(line);
token = result.toString();
}
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
}
@Override
public String requestActivation(ContainerInfo container) throws Exception {
String methodPath = "/token/node";
int infrastructureHash = Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure());
StringBuilder callUrl;
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(container, os);
}
log.debug("response code is "+connection.getResponseCode());
if (connection.getResponseCode()!=200) throw new Exception("error contacting authorization service");
String token= "";
try(BufferedReader reader = new BufferedReader(new InputStreamReader((InputStream)connection.getContent()))){
StringBuilder result = new StringBuilder();
String line;
while((line = reader.readLine()) != null)
result.append(line);
token = result.toString();
}
return Utils.addInfrastructureHashToToken(token, infrastructureHash);
}
@Override
public AuthorizationEntry get(String token) throws ObjectNotFound, Exception{
@ -478,7 +187,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
.append(methodPath).append(realToken);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "GET", false);
HttpURLConnection connection = makeRequest(url, "GET");
connection.setDoInput(true);
if (connection.getResponseCode()==404) throw new ObjectNotFound("token "+maskedToken+" not found");
@ -513,8 +222,8 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
endpoint = getEndpoint(infrastructureHashFromToken);
}
}
final String methodPath = "/token/resolve/?";
final String methodPath = "/token/bunch/?";
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(endpoint))
.append(methodPath);
@ -529,7 +238,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
}
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "GET", false);
HttpURLConnection connection = makeRequest(url, "GET");
connection.setDoInput(true);
if (connection.getResponseCode()==404) throw new ObjectNotFound("token not found");
@ -543,103 +252,12 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
}
@Override
public void addPolicies(List<Policy> policies) throws Exception {
final String methodPath = "/policyManager";
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure()))).append(methodPath);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "POST", true);
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "application/xml");
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
Binder.getContext().createMarshaller().marshal(new Policies(policies), os);
}
if (connection.getResponseCode()!=200) throw new Exception("error adding policies");
}
@Override
public void removePolicies(long... ids) throws Exception {
final String methodPath = "/policyManager/";
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure()))).append(methodPath);
List<Long> errorIds = new ArrayList<Long>();
for (long id: ids){
URL url = new URL(callUrl.toString()+id);
HttpURLConnection connection = makeRequest(url, "DELETE", true);
if (connection.getResponseCode()!=200) errorIds.add(id);
}
if (!errorIds.isEmpty())
throw new Exception("error removing policies with ids: "+errorIds);
}
@Override
public List<Policy> getPolicies(String context) throws Exception{
final String methodPath = "/policyManager/";
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashfromContext(context))).append(methodPath).append("?").append(CONTEXT_PARAM).append("=").append(context);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "GET", true);
connection.setDoInput(true);
if (connection.getResponseCode()!=200){
log.info("response code is not 200");
throw new Exception("error retrieving policies");
}
if (connection.getContentLengthLong()==0)
return Collections.emptyList();
try(InputStreamReader stream = new InputStreamReader((InputStream)connection.getContent())){
Policies policies = (Policies)Binder.getContext().createUnmarshaller().unmarshal(stream);
return policies.getPolicies();
}
}
@Override
public File getSymmKey(String filePath) throws Exception{
final String methodPath = "/symmKey/";
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure())))
.append(methodPath);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "GET", true);
connection.setDoInput(true);
if (connection.getResponseCode()!=200) throw new Exception("error retrieving key");
if (connection.getContentLengthLong()<=0) return null;
String resourceName = (String)connection.getHeaderField("resource-name");
File toReturnFile = new File(filePath+"/"+resourceName);
toReturnFile.createNewFile();
try(InputStream stream = (InputStream)connection.getContent();
OutputStream os = new FileOutputStream(toReturnFile)){
int read = 0;
byte[] bytes = new byte[1024];
while ((read = stream.read(bytes)) != -1) {
os.write(bytes, 0, read);
}
}
return toReturnFile;
}
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");
connection.setRequestProperty(Constants.TOKEN_HEADER_ENTRY,Utils.getRealToken(SecurityTokenProvider.instance.get()));
}
connection.setRequestMethod(method);
return connection;
}
@ -647,7 +265,7 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
@Override
public AuthorizationEndpoint getEndpoint(int infrastructureHash) {
for (String infra: endpoints.getEndpoints().keySet()) {
if (Utils.getInfrastructureHashfromContext(infra)==infrastructureHash)
if (Utils.getInfrastructureHashfromContext(infra)==infrastructureHash)
return endpoints.getEndpoints().get(infra);
}
throw new RuntimeException("Authorization Endpoint not found for the required infrastructure");

View File

@ -2,32 +2,10 @@ package org.gcube.common.authorizationservice.cl;
import static org.gcube.common.authorization.client.Constants.authorizationService;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.FileInputStream;
import java.io.FileWriter;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.gcube.common.authorization.client.proxy.AuthorizationProxy;
import org.gcube.common.authorization.library.AuthorizationEntry;
import org.gcube.common.authorization.library.policies.Action;
import org.gcube.common.authorization.library.policies.Policy;
import org.gcube.common.authorization.library.policies.ServiceAccess;
import org.gcube.common.authorization.library.policies.User2ServicePolicy;
import org.gcube.common.authorization.library.policies.Users;
import org.gcube.common.authorization.library.provider.ContainerInfo;
import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
import org.gcube.common.authorization.library.provider.ServiceIdentifier;
import org.gcube.common.authorization.library.provider.ServiceInfo;
import org.gcube.common.authorization.library.provider.UserInfo;
import org.junit.Ignore;
import org.junit.Test;
public class CallTest {
@ -37,96 +15,33 @@ public class CallTest {
System.out.println("pred4s".hashCode() & 0xfffffff);
}
@Test
public void getToken() throws Exception {
System.out.println(authorizationService().get("XXXXXXXX"));
//System.out.println(authorizationService().get("XXXXXXXX").getContext());
//System.out.println(authorizationService().get("XXXXXXXX").getMap());
}
@Test
public void removeUserinContext() throws Exception {
authorizationService().removeAllReleatedToken("lucio.lelii", "/gcube/devsec");
}
@Test
public void requestExternalServiceToken() throws Exception {
SecurityTokenProvider.instance.set(requestTestToken("/gcube"));
System.out.println(authorizationService().generateExternalServiceToken("URIResolver"));
}
@Test
public void getExternalServiceToken() throws Exception {
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devsec"));
System.out.println(authorizationService().retrieveExternalServiceGenerated());
}
@Test
public void requestNodeToken() throws Exception {
System.out.println(_requestNodeToken());
}
@Test
public void addPolicy() throws Exception {
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext/NextNext"));
List<Policy> policies = new ArrayList<Policy>();
policies.add(new User2ServicePolicy("/gcube/devNext/NextNext", new ServiceAccess(), Users.one("lucio.lelii"), Action.ACCESS ));
authorizationService().addPolicies(policies);
}
@Test
public void getPolicies() throws Exception{
SecurityTokenProvider.instance.set(requestTestToken("/gcube/devNext"));
List<Policy> policies = authorizationService().getPolicies("/gcube/devsec");
for (Policy policy: policies)
System.out.println(policy);
}
@Test
public void removePolicy() throws Exception {
authorizationService().removePolicies(2, 3, 4);
}
@Test
public void generateToken() throws Exception{
System.out.println(authorizationService().generateUserToken(new UserInfo("guest", new ArrayList<String>()), "/pred4s"));
}
@Test(expected=RuntimeException.class)
public void createKeyWithError() throws Exception {
authorizationService().generateApiKey("TEST");
}
@Test
public void getSymmKey() throws Exception{
SecurityTokenProvider.instance.set(_requestNodeToken());
authorizationService().getSymmKey("/tmp");
}
@Test
public void createKey() throws Exception {
String token = requestTestToken("/gcube");
SecurityTokenProvider.instance.set(token);
String key = authorizationService().generateApiKey("PIPPO");
System.out.println("key : "+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);
}
public String _requestNodeToken() throws Exception {
SecurityTokenProvider.instance.set(requestTestToken("/gcube"));
String token = authorizationService().requestActivation(new ContainerInfo("workspace-repository1-d.d4science.org",80), "/gcube/devsec");
return token;
}
@Test
public void createTestToken() throws Exception {
System.out.println(requestTestToken("/pred4s"));
}
@Test
public void resoveTokenAndPrint() throws Exception{
System.out.println(resolveToken("fa7ed90a-d9d6-4bfb-95c9-5e3d7b6cd23e-843339462"));
}
private String requestTestToken(String context) throws Exception{
return authorizationService().generateUserToken(new UserInfo("lucio.lelii", new ArrayList<String>()), context);
@ -137,131 +52,5 @@ public class CallTest {
return entry;
}
/* List<String> scopes = Arrays.asList("/d4science.research-infrastructures.eu/gCubeApps/TabularDataLab",
"/d4science.research-infrastructures.eu/FARM/AquaMaps",
"/d4science.research-infrastructures.eu/FARM/WECAFC-FIRMS",
"/d4science.research-infrastructures.eu/gCubeApps/PGFA-UFMT",
"/d4science.research-infrastructures.eu/FARM",
"/d4science.research-infrastructures.eu/gCubeApps/EcologicalModelling",
"/d4science.research-infrastructures.eu/gCubeApps/EuBrazilOpenBio",
"/d4science.research-infrastructures.eu/gCubeApps/AlieiaVRE",
/d4science.research-infrastructures.eu/gCubeApps/ENVRIPlus",
/d4science.research-infrastructures.eu/gCubeApps/ENVRI",
/d4science.research-infrastructures.eu/gCubeApps/ICES_DASC",
/d4science.research-infrastructures.eu/gCubeApps/FAO_TunaAtlas",
/d4science.research-infrastructures.eu/SoBigData/ResourceCatalogue",
/d4science.research-infrastructures.eu/gCubeApps/StocksAndFisheriesKB",
/d4science.research-infrastructures.eu/SoBigData/TagMe",
/d4science.research-infrastructures.eu/gCubeApps/BlueCommons",
/d4science.research-infrastructures.eu/gCubeApps/ICES_TCSSM",
/d4science.research-infrastructures.eu/gCubeApps/OpenIt",
/d4science.research-infrastructures.eu/SmartArea/SmartApps",
/d4science.research-infrastructures.eu",
/d4science.research-infrastructures.eu/gCubeApps/Parthenos",
/d4science.research-infrastructures.eu/gCubeApps/AquacultureAtlasGeneration",
/d4science.research-infrastructures.eu/gCubeApps/IGDI",
/d4science.research-infrastructures.eu/gCubeApps/RStudioLab",
/d4science.research-infrastructures.eu/SoBigData",
/d4science.research-infrastructures.eu/gCubeApps/BlueBridgeProject",
/d4science.research-infrastructures.eu/gCubeApps/rScience",
/d4science.research-infrastructures.eu/FARM/VME-DB",
/d4science.research-infrastructures.eu/gCubeApps/EllinikaPsariaVRE",
/d4science.research-infrastructures.eu/gCubeApps/gCube",
/d4science.research-infrastructures.eu/FARM/TBTI_VRE",
/d4science.research-infrastructures.eu/FARM/GRSF",
/d4science.research-infrastructures.eu/gCubeApps/DocumentsWorkflow",
/d4science.research-infrastructures.eu/gCubeApps/ICOS_ETC",
/d4science.research-infrastructures.eu/SoBigData/CityOfCitizens",
/d4science.research-infrastructures.eu/gCubeApps/SoBigData.eu",
/d4science.research-infrastructures.eu/gCubeApps/BiOnym",
/d4science.research-infrastructures.eu/gCubeApps/PerformanceEvaluationInAquaculture",
/d4science.research-infrastructures.eu/gCubeApps/SmartArea",
/d4science.research-infrastructures.eu/gCubeApps/ICES_TCRE",
/d4science.research-infrastructures.eu/gCubeApps/CNR_OpenScienceTF",
/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-PSC",
/d4science.research-infrastructures.eu/gCubeApps/BOBLME_HilsaAWG",
/d4science.research-infrastructures.eu/gCubeApps/ScalableDataMining",
/d4science.research-infrastructures.eu/gCubeApps/BiodiversityLab",
/d4science.research-infrastructures.eu/gCubeApps/DESCRAMBLE",
/d4science.research-infrastructures.eu/gCubeApps/ICES_FIACO",
/d4science.research-infrastructures.eu/gCubeApps/BlueBRIDGE-EAB",
/d4science.research-infrastructures.eu/gCubeApps/ARIADNE",
/d4science.research-infrastructures.eu/SmartArea/SmartBuilding",
/d4science.research-infrastructures.eu/gCubeApps/ProtectedAreaImpactMaps",
/d4science.research-infrastructures.eu/gCubeApps/ForkysVRE",
/d4science.research-infrastructures.eu/gCubeApps/EGIEngage",
/d4science.research-infrastructures.eu/gCubeApps/ICES_StockAssessmentAdvanced",
/d4science.research-infrastructures.eu/FARM/GRSF",
/d4science.research-infrastructures.eu/SmartArea",
/d4science.research-infrastructures.eu/gCubeApps/RPrototypingLab",
/d4science.research-infrastructures.eu/gCubeApps/TCom",
/d4science.research-infrastructures.eu/gCubeApps/ICCAT_BFT-E",
/d4science.research-infrastructures.eu/gCubeApps/ICES_DALSA",
/d4science.research-infrastructures.eu/gCubeApps/SoBigData.it",
/d4science.research-infrastructures.eu/gCubeApps/EGIP",
/d4science.research-infrastructures.eu/gCubeApps/BlueUptake",
/d4science.research-infrastructures.eu/FARM/iMarineBoardVRE",
/d4science.research-infrastructures.eu/gCubeApps/KnowledgeBridging",
/d4science.research-infrastructures.eu/gCubeApps/EFG",
/d4science.research-infrastructures.eu/gCubeApps/StockAssessment",
/d4science.research-infrastructures.eu/gCubeApps/iSearch",
"/d4science.research-infrastructures.eu/gCubeApps",
"/d4science.research-infrastructures.eu/gCubeApps/StrategicInvestmentAnalysis")*/
@Test
public void requestListOfTokenForVREs() throws Exception{
SecurityTokenProvider.instance.set(requestTestToken("/d4science.research-infrastructures.eu"));
String jrNode ="tabulardata.d4science.org";
int jrPort =8080;
AuthorizationProxy proxy = authorizationService();
try(BufferedReader isr = new BufferedReader(new InputStreamReader(new FileInputStream("./src/test/resources/Scopes.txt")));
BufferedWriter bw = new BufferedWriter(new FileWriter("./src/test/resources/tokens-"+jrNode+".txt"))){
String line = null;
while ( (line=isr.readLine())!=null){
System.out.println(" retrieving token for scope "+line);
String token = proxy.requestActivation(new ContainerInfo(jrNode,jrPort), line.trim());
bw.write(String.format("<token>%s</token>", token));
bw.newLine();
}
}
}
@Ignore @Test
public void checkDiff() throws Exception{
Set<String> scopes = new HashSet<String>();
try(BufferedReader isr = new BufferedReader(new InputStreamReader(new FileInputStream("./src/test/resources/Scopes.txt")))){
String line = null;
while ( (line=isr.readLine())!=null){
System.out.println(scopes.size()+" "+line);
if (scopes.contains(line.trim()))
System.out.println("already contians "+line);
else scopes.add(line.trim());
}
}
System.out.println("initial scope count is "+scopes.size());
try(BufferedReader isr = new BufferedReader(new InputStreamReader(new FileInputStream("./src/test/resources/createdScope.txt")))){
String line = null;
while ( (line=isr.readLine())!=null){
if (!scopes.remove(line.trim()))
System.out.println("cannot remove scope "+line.trim());
}
}
System.out.println("final scope count is "+scopes.size());
}
}