Compare commits

...

16 Commits

Author SHA1 Message Date
Luca Frosini cd56803026 Update 'src/test/java/org/gcube/common/authorizationservice/cl/CallTest.java'
Removed tokens
5 months ago
lucio 314591588e commit for release 8 months ago
lucio 6f50eab47d updated 1 year ago
Lucio Lelii ef5922163e porting to smartgears 4 2 years ago
Lucio Lelii 181d6f80d0 porting to smartgears 4 2 years ago
lucio d0fa2589a7 Merge branch 'master' of
gitea@code-repo.d4science.org:gCubeSystem/authorization-client.git

Conflicts:
	pom.xml
4 years ago
lucio 972820734f get(List<String>) modified for update of authorization service 4 years ago
Lucio Lelii 401316e5fa Update pom.xml 4 years ago
lucio 9d0b85d50a Merge branch 'master' of
gitea@code-repo.d4science.org:gCubeSystem/authorization-client.git

Conflicts:
	pom.xml
4 years ago
lucio fa7ac84ba0 JaxbContext updated 4 years ago
lucio 9ed284e2d1 request for bunch token creation for service and container added 4 years ago
lucio 94d9901b11 readme updated 5 years ago
lucio 6685f21fae added changelong 5 years ago
lucio 10f0c49651 distro file structure changed 5 years ago
lucio f1e9f4b029 setRoles added 5 years ago
lucio 6d6bd2daa0 setRoles on a token added 5 years ago

@ -1,18 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" output="target/classes" path="src/main/java">
<attributes>
<attribute name="optional" value="true"/>
<attribute name="maven.pomderived" value="true"/>
</attributes>
</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"/>

1
.gitignore vendored

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

@ -5,11 +5,21 @@
<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>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.m2e.core.maven2Builder</name>
<arguments>
@ -17,7 +27,10 @@
</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>

@ -8,7 +8,9 @@ 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

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

@ -0,0 +1,311 @@
#European Union Public Licence V.1.1
##*EUPL © the European Community 2007*
This **European Union Public Licence** (the **“EUPL”**) applies to the Work or Software
(as defined below) which is provided under the terms of this Licence. Any use of
the Work, other than as authorised under this Licence is prohibited (to the
extent such use is covered by a right of the copyright holder of the Work).
The Original Work is provided under the terms of this Licence when the Licensor
(as defined below) has placed the following notice immediately following the
copyright notice for the Original Work:
**Licensed under the EUPL V.1.1**
or has expressed by any other mean his willingness to license under the EUPL.
##1. Definitions
In this Licence, the following terms have the following meaning:
- The Licence: this Licence.
- The Original Work or the Software: the software distributed and/or
communicated by the Licensor under this Licence, available as Source Code and
also as Executable Code as the case may be.
- Derivative Works: the works or software that could be created by the Licensee,
based upon the Original Work or modifications thereof. This Licence does not
define the extent of modification or dependence on the Original Work required
in order to classify a work as a Derivative Work; this extent is determined by
copyright law applicable in the country mentioned in Article 15.
- The Work: the Original Work and/or its Derivative Works.
- The Source Code: the human-readable form of the Work which is the most
convenient for people to study and modify.
- The Executable Code: any code which has generally been compiled and which is
meant to be interpreted by a computer as a program.
- The Licensor: the natural or legal person that distributes and/or communicates
the Work under the Licence.
- Contributor(s): any natural or legal person who modifies the Work under the
Licence, or otherwise contributes to the creation of a Derivative Work.
- The Licensee or “You”: any natural or legal person who makes any usage of the
Software under the terms of the Licence.
- Distribution and/or Communication: any act of selling, giving, lending,
renting, distributing, communicating, transmitting, or otherwise making
available, on-line or off-line, copies of the Work or providing access to its
essential functionalities at the disposal of any other natural or legal
person.
##2. Scope of the rights granted by the Licence
The Licensor hereby grants You a world-wide, royalty-free, non-exclusive,
sub-licensable licence to do the following, for the duration of copyright vested
in the Original Work:
- use the Work in any circumstance and for all usage, reproduce the Work, modify
- the Original Work, and make Derivative Works based upon the Work, communicate
- to the public, including the right to make available or display the Work or
- copies thereof to the public and perform publicly, as the case may be, the
- Work, distribute the Work or copies thereof, lend and rent the Work or copies
- thereof, sub-license rights in the Work or copies thereof.
Those rights can be exercised on any media, supports and formats, whether now
known or later invented, as far as the applicable law permits so.
In the countries where moral rights apply, the Licensor waives his right to
exercise his moral right to the extent allowed by law in order to make effective
the licence of the economic rights here above listed.
The Licensor grants to the Licensee royalty-free, non exclusive usage rights to
any patents held by the Licensor, to the extent necessary to make use of the
rights granted on the Work under this Licence.
##3. Communication of the Source Code
The Licensor may provide the Work either in its Source Code form, or as
Executable Code. If the Work is provided as Executable Code, the Licensor
provides in addition a machine-readable copy of the Source Code of the Work
along with each copy of the Work that the Licensor distributes or indicates, in
a notice following the copyright notice attached to the Work, a repository where
the Source Code is easily and freely accessible for as long as the Licensor
continues to distribute and/or communicate the Work.
##4. Limitations on copyright
Nothing in this Licence is intended to deprive the Licensee of the benefits from
any exception or limitation to the exclusive rights of the rights owners in the
Original Work or Software, of the exhaustion of those rights or of other
applicable limitations thereto.
##5. Obligations of the Licensee
The grant of the rights mentioned above is subject to some restrictions and
obligations imposed on the Licensee. Those obligations are the following:
Attribution right: the Licensee shall keep intact all copyright, patent or
trademarks notices and all notices that refer to the Licence and to the
disclaimer of warranties. The Licensee must include a copy of such notices and a
copy of the Licence with every copy of the Work he/she distributes and/or
communicates. The Licensee must cause any Derivative Work to carry prominent
notices stating that the Work has been modified and the date of modification.
Copyleft clause: If the Licensee distributes and/or communicates copies of the
Original Works or Derivative Works based upon the Original Work, this
Distribution and/or Communication will be done under the terms of this Licence
or of a later version of this Licence unless the Original Work is expressly
distributed only under this version of the Licence. The Licensee (becoming
Licensor) cannot offer or impose any additional terms or conditions on the Work
or Derivative Work that alter or restrict the terms of the Licence.
Compatibility clause: If the Licensee Distributes and/or Communicates Derivative
Works or copies thereof based upon both the Original Work and another work
licensed under a Compatible Licence, this Distribution and/or Communication can
be done under the terms of this Compatible Licence. For the sake of this clause,
“Compatible Licence” refers to the licences listed in the appendix attached to
this Licence. Should the Licensees obligations under the Compatible Licence
conflict with his/her obligations under this Licence, the obligations of the
Compatible Licence shall prevail.
Provision of Source Code: When distributing and/or communicating copies of the
Work, the Licensee will provide a machine-readable copy of the Source Code or
indicate a repository where this Source will be easily and freely available for
as long as the Licensee continues to distribute and/or communicate the Work.
Legal Protection: This Licence does not grant permission to use the trade names,
trademarks, service marks, or names of the Licensor, except as required for
reasonable and customary use in describing the origin of the Work and
reproducing the content of the copyright notice.
##6. Chain of Authorship
The original Licensor warrants that the copyright in the Original Work granted
hereunder is owned by him/her or licensed to him/her and that he/she has the
power and authority to grant the Licence.
Each Contributor warrants that the copyright in the modifications he/she brings
to the Work are owned by him/her or licensed to him/her and that he/she has the
power and authority to grant the Licence.
Each time You accept the Licence, the original Licensor and subsequent
Contributors grant You a licence to their contributions to the Work, under the
terms of this Licence.
##7. Disclaimer of Warranty
The Work is a work in progress, which is continuously improved by numerous
contributors. It is not a finished work and may therefore contain defects or
“bugs” inherent to this type of software development.
For the above reason, the Work is provided under the Licence on an “as is” basis
and without warranties of any kind concerning the Work, including without
limitation merchantability, fitness for a particular purpose, absence of defects
or errors, accuracy, non-infringement of intellectual property rights other than
copyright as stated in Article 6 of this Licence.
This disclaimer of warranty is an essential part of the Licence and a condition
for the grant of any rights to the Work.
##8. Disclaimer of Liability
Except in the cases of wilful misconduct or damages directly caused to natural
persons, the Licensor will in no event be liable for any direct or indirect,
material or moral, damages of any kind, arising out of the Licence or of the use
of the Work, including without limitation, damages for loss of goodwill, work
stoppage, computer failure or malfunction, loss of data or any commercial
damage, even if the Licensor has been advised of the possibility of such
damage. However, the Licensor will be liable under statutory product liability
laws as far such laws apply to the Work.
##9. Additional agreements
While distributing the Original Work or Derivative Works, You may choose to
conclude an additional agreement to offer, and charge a fee for, acceptance of
support, warranty, indemnity, or other liability obligations and/or services
consistent with this Licence. However, in accepting such obligations, You may
act only on your own behalf and on your sole responsibility, not on behalf of
the original Licensor or any other Contributor, and only if You agree to
indemnify, defend, and hold each Contributor harmless for any liability incurred
by, or claims asserted against such Contributor by the fact You have accepted
any such warranty or additional liability.
##10. Acceptance of the Licence
The provisions of this Licence can be accepted by clicking on an icon “I agree”
placed under the bottom of a window displaying the text of this Licence or by
affirming consent in any other similar way, in accordance with the rules of
applicable law. Clicking on that icon indicates your clear and irrevocable
acceptance of this Licence and all of its terms and conditions.
Similarly, you irrevocably accept this Licence and all of its terms and
conditions by exercising any rights granted to You by Article 2 of this Licence,
such as the use of the Work, the creation by You of a Derivative Work or the
Distribution and/or Communication by You of the Work or copies thereof.
##11. Information to the public
In case of any Distribution and/or Communication of the Work by means of
electronic communication by You (for example, by offering to download the Work
from a remote location) the distribution channel or media (for example, a
website) must at least provide to the public the information requested by the
applicable law regarding the Licensor, the Licence and the way it may be
accessible, concluded, stored and reproduced by the Licensee.
##12. Termination of the Licence
The Licence and the rights granted hereunder will terminate automatically upon
any breach by the Licensee of the terms of the Licence.
Such a termination will not terminate the licences of any person who has
received the Work from the Licensee under the Licence, provided such persons
remain in full compliance with the Licence.
##13. Miscellaneous
Without prejudice of Article 9 above, the Licence represents the complete
agreement between the Parties as to the Work licensed hereunder.
If any provision of the Licence is invalid or unenforceable under applicable
law, this will not affect the validity or enforceability of the Licence as a
whole. Such provision will be construed and/or reformed so as necessary to make
it valid and enforceable.
The European Commission may publish other linguistic versions and/or new
versions of this Licence, so far this is required and reasonable, without
reducing the scope of the rights granted by the Licence. New versions of the
Licence will be published with a unique version number.
All linguistic versions of this Licence, approved by the European Commission,
have identical value. Parties can take advantage of the linguistic version of
their choice.
##14. Jurisdiction
Any litigation resulting from the interpretation of this License, arising
between the European Commission, as a Licensor, and any Licensee, will be
subject to the jurisdiction of the Court of Justice of the European Communities,
as laid down in article 238 of the Treaty establishing the European Community.
Any litigation arising between Parties, other than the European Commission, and
resulting from the interpretation of this License, will be subject to the
exclusive jurisdiction of the competent court where the Licensor resides or
conducts its primary business.
##15. Applicable Law
This Licence shall be governed by the law of the European Union country where
the Licensor resides or has his registered office.
This licence shall be governed by the Belgian law if:
- a litigation arises between the European Commission, as a Licensor, and any
- Licensee; the Licensor, other than the European Commission, has no residence
- or registered office inside a European Union country.
---
##Appendix
**“Compatible Licences”** according to article 5 EUPL are:
- GNU General Public License (GNU GPL) v. 2
- Open Software License (OSL) v. 2.1, v. 3.0
- Common Public License v. 1.0
- Eclipse Public License v. 1.0
- Cecill v. 2.0

@ -0,0 +1,46 @@
# Authorization Client
client for legacy gcube authorization
## Structure of the project
* The source code is present in the src folder.
## Built With
* [OpenJDK](https://openjdk.java.net/) - The JDK used
* [Maven](https://maven.apache.org/) - Dependency Management
## Documentation
* Use of this theme is described in the [Wiki](https://wiki.gcube-system.org/gcube/Authorization_Client_Library).
## Change log
See [Releases](https://code-repo.d4science.org/gCubeSystem/authorization-client/releases).
## Authors
* **Lucio Lelii** ([ISTI-CNR Infrascience Group](http://nemis.isti.cnr.it/groups/infrascience)
## License
This project is licensed under the EUPL V.1.1 License - see the [LICENSE.md](LICENSE.md) file for details.
## About the gCube Framework
This software is part of the [gCubeFramework](https://www.gcube-system.org/ "gCubeFramework"): an
open-source software toolkit used for building and operating Hybrid Data
Infrastructures enabling the dynamic deployment of Virtual Research Environments
by favouring the realisation of reuse oriented policies.
The projects leading to this software have received funding from a series of European Union programmes including:
- the Sixth Framework Programme for Research and Technological Development
- DILIGENT (grant no. 004260);
- the Seventh Framework Programme for research, technological development and demonstration
- D4Science (grant no. 212488), D4Science-II (grant no.239019), ENVRI (grant no. 283465), EUBrazilOpenBio (grant no. 288754), iMarine(grant no. 283644);
- the H2020 research and innovation programme
- BlueBRIDGE (grant no. 675680), EGIEngage (grant no. 654142), ENVRIplus (grant no. 654182), Parthenos (grant no. 654119), SoBigData (grant no. 654024),DESIRA (grant no. 818194), ARIADNEplus (grant no. 823914), RISIS2 (grant no. 824091), PerformFish (grant no. 727610), AGINFRAplus (grant no. 731001);

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

@ -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.

@ -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>

@ -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>

@ -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>

@ -3,51 +3,40 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<version>2.0.4</version>
<version>3.0.0</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.0</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>
</scm>
<properties>
<distroDirectory>distro</distroDirectory>
</properties>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.2</version>
</dependency>
<dependency>
<groupId>junit</groupId>
@ -58,63 +47,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>${distroDirectory}</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>${distroDirectory}/descriptor.xml</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<id>servicearchive</id>
<phase>install</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

@ -12,6 +12,9 @@ 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;
import org.gcube.common.authorization.library.utils.MultiServiceTokenRequest;
public class Binder {
@ -20,7 +23,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);
ServiceInfo.class, Policies.class, Policy.class, ListMapper.class, AuthorizationEntryList.class, MultiServiceTokenRequest.class);
return context;
}

@ -1,16 +1,11 @@
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;
public interface AuthorizationProxy {
@ -21,35 +16,16 @@ public interface AuthorizationProxy {
AuthorizationEntry get(String token) 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<AuthorizationEntry> get(List<String> tokens) throws ObjectNotFound, 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;
}

@ -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,25 +15,18 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
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.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -54,73 +45,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 {
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 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 {
@ -132,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());
@ -162,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");
@ -187,196 +121,52 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
}
@Override
public void removeAllReleatedToken(String clientId, String context) throws Exception{
String methodPath = "/token/user";
int infrastructureHash = Utils.getInfrastructureHashfromContext(context);
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append("?")
.append(CONTEXT_PARAM).append("=").append(context).append("&").append(CLIENT_ID_PARAM).append("=").append(clientId);
public void setTokenRoles(String token, List<String> roles) throws Exception {
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "DELETE", false);
//connection.setDoOutput(false);
connection.setDoInput(true);
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");
}
@Override
public String generateApiKey(String apiQualifier) throws Exception {
String methodPath = String.format("/apikey?qualifier=%s",apiQualifier);
String realToken = Utils.getRealToken(token);
String methodPath = String.format("/token/user/%s/roles",realToken);
int infrastructureHash = Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure());
int infrastructureHash = Utils.getInfrastructureHashFromToken(token, 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);
HttpURLConnection connection = makeRequest(url, "PUT");
connection.setDoOutput(true);
connection.setFixedLengthStreamingMode(0);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
ListMapper listmapper = new ListMapper(roles);
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
Binder.getContext().createMarshaller().marshal(listmapper, 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
/**
* 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";
public void removeAllReleatedToken(String clientId, String context) throws Exception{
String methodPath = "/token/user";
int infrastructureHash = Utils.getInfrastructureHashfromContext(context);
StringBuilder callUrl;
callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append("?context=").append(context);
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(infrastructureHash)).append(methodPath).append("?")
.append(CONTEXT_PARAM).append("=").append(context).append("&").append(CLIENT_ID_PARAM).append("=").append(clientId);
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", false);
connection.setDoOutput(true);
HttpURLConnection connection = makeRequest(url, "DELETE");
//connection.setDoOutput(false);
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);
log.debug("response code for "+callUrl.toString()+" is "+connection.getResponseCode()+" "+connection.getResponseMessage());
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "PUT", true);
connection.setDoOutput(true);
connection.setDoInput(true);
connection.setRequestProperty("Content-type", "application/xml");
if (connection.getResponseCode()!=200 && connection.getResponseCode()!=204) throw new Exception("error contacting authorization service");
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{
@ -397,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");
@ -411,104 +201,63 @@ public class DefaultAuthorizationProxy implements AuthorizationProxy {
}
}
@Override
public void addPolicies(List<Policy> policies) throws Exception {
final String methodPath = "/policyManager";
public List<AuthorizationEntry> get(List<String> tokens) throws ObjectNotFound, Exception {
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashFromToken(SecurityTokenProvider.instance.get(), endpoints.getDefaultInfrastructure()))).append(methodPath);
List<String> realTokens = new ArrayList<String>();
URL url = new URL(callUrl.toString());
HttpURLConnection connection = makeRequest(url, "POST", true);
connection.setDoOutput(true);
connection.setRequestProperty("Content-type", "application/xml");
List<AuthorizationEntry> toReturn = new ArrayList<AuthorizationEntry>();
try(OutputStream os = new BufferedOutputStream(connection.getOutputStream())){
Binder.getContext().createMarshaller().marshal(new Policies(policies), os);
}
AuthorizationEndpoint endpoint = null;
if (connection.getResponseCode()!=200) throw new Exception("error adding policies");
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);
@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 (endpoint==null) {
int infrastructureHashFromToken = Utils.getInfrastructureHashFromToken(token, endpoints.getDefaultInfrastructure());
endpoint = getEndpoint(infrastructureHashFromToken);
}
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/";
final String methodPath = "/token/bunch/?";
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(Utils.getInfrastructureHashfromContext(context))).append(methodPath).append("?").append(CONTEXT_PARAM).append("=").append(context);
StringBuilder callUrl = new StringBuilder(getInternalEnpoint(endpoint))
.append(methodPath);
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();
boolean first = true;
for (String toAppend : realTokens) {
if (first) {
callUrl= callUrl.append("token=").append(toAppend);
first = false;
} else callUrl= callUrl.append("&token=").append(toAppend);
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);
HttpURLConnection connection = makeRequest(url, "GET");
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];
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;
while ((read = stream.read(bytes)) != -1) {
os.write(bytes, 0, read);
try(InputStream stream = (InputStream)connection.getContent();){
AuthorizationEntryList entries = (AuthorizationEntryList)Binder.getContext().createUnmarshaller().unmarshal(stream);
return entries.getEntries();
}
}
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;
}

@ -2,30 +2,12 @@ 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.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.UserInfo;
import org.junit.Ignore;
import org.junit.Test;
@Ignore
public class CallTest {
@Test
@ -34,8 +16,10 @@ public class CallTest {
}
@Test
public void requestUserTokenViaUserNameAndScope() throws Exception {
System.out.println(authorizationService().resolveTokenByUserAndContext("valentina.marioli", "/gcube/devNext/NextNext"));
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
@ -43,83 +27,11 @@ public class CallTest {
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 {
@ -135,131 +47,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());
}
}

Loading…
Cancel
Save