From 3ab13d8d6e56e0533d50197f8a1f5d3884da1180 Mon Sep 17 00:00:00 2001 From: Luca Frosini Date: Mon, 25 Jul 2016 15:27:51 +0000 Subject: [PATCH] Using new authorization lib git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@130783 82a268e6-3cf1-43bd-a215-b396298e98cf --- pom.xml | 38 ++++++++++++++++--- .../datamodel/BasicUsageRecord.java | 9 ++--- .../AccountingPersistenceConfiguration.java | 5 +-- .../AccountingPersistenceFactory.java | 4 +- .../org/gcube/testutility/ScopedTest.java | 7 ++-- 5 files changed, 44 insertions(+), 19 deletions(-) diff --git a/pom.xml b/pom.xml index ca83e1c..6300b30 100644 --- a/pom.xml +++ b/pom.xml @@ -27,41 +27,67 @@ https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId} + + + + + org.gcube.distribution + gcube-bom + 1.0.0-SNAPSHOT + pom + import + + + + + + + org.gcube.common + authorization-client + provided + + + org.gcube.common + common-authorization + [2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT) + provided + + org.gcube.data.publishing document-store-lib - [1.1.0-SNAPSHOT,2.0.0-SNAPSHOT) provided org.gcube.resources.discovery ic-client - [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) provided org.gcube.core common-scope - [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) + [2.0.0-SNAPSHOT,3.0.0-SNAPSHOT) + provided + + + org.gcube.resources.discovery + discovery-client provided org.gcube.resources common-gcore-resources - [1.0.0-SNAPSHOT,2.0.0-SNAPSHOT) provided org.gcube.core common-encryption - [1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT) provided org.slf4j slf4j-api - 1.7.5 provided diff --git a/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java b/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java index c0a8018..17c47d0 100644 --- a/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java +++ b/src/main/java/org/gcube/accounting/datamodel/BasicUsageRecord.java @@ -9,7 +9,9 @@ import java.util.Map; import org.gcube.accounting.datamodel.backwardcompatibility.MoveToRecordType; import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult; import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator; -import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.authorization.client.Constants; +import org.gcube.common.authorization.library.AuthorizationEntry; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.gcube.documentstore.exception.InvalidValueException; import org.gcube.documentstore.records.Record; import org.gcube.documentstore.records.implementation.AbstractRecord; @@ -47,7 +49,6 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe @RequiredField @ValidOperationResult public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT; - /* public static String getScopeFromToken(){ String token = SecurityTokenProvider.instance.get(); AuthorizationEntry authorizationEntry; @@ -59,7 +60,6 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe String scope = authorizationEntry.getContext(); return scope; } - */ /** * Initialize variable @@ -68,8 +68,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe super.init(); // Backward compatibility try { - //this.setScope(getScopeFromToken()); - this.setScope(ScopeProvider.instance.get()); + this.setScope(getScopeFromToken()); } catch(Exception e) { logger.warn("Unable to automaticcally set the scope using scope provider. The record will not be valid if the scope will not be explicitly set."); } diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceConfiguration.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceConfiguration.java index 87f21c2..543f134 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceConfiguration.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceConfiguration.java @@ -7,12 +7,12 @@ import java.security.Key; import java.util.List; import java.util.Map; +import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.common.encryption.StringEncrypter; import org.gcube.common.resources.gcore.ServiceEndpoint; import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint; import org.gcube.common.resources.gcore.ServiceEndpoint.Property; import org.gcube.common.resources.gcore.utils.Group; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.documentstore.persistence.PersistenceBackend; import org.gcube.documentstore.persistence.PersistenceBackendConfiguration; import org.gcube.resources.discovery.client.api.DiscoveryClient; @@ -58,8 +58,7 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig DiscoveryClient client = ICFactory.clientFor(ServiceEndpoint.class); List serviceEndpoints = client.submit(query); if(serviceEndpoints.size()>1){ - //String scope = BasicUsageRecord.getScopeFromToken(); - String scope = ScopeProvider.instance.get(); + String scope = BasicUsageRecord.getScopeFromToken(); query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE)); query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope)); serviceEndpoints = client.submit(query); diff --git a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceFactory.java b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceFactory.java index ce1cad8..a4be88c 100644 --- a/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceFactory.java +++ b/src/main/java/org/gcube/accounting/persistence/AccountingPersistenceFactory.java @@ -7,9 +7,9 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; +import org.gcube.accounting.datamodel.BasicUsageRecord; import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord; import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord; -import org.gcube.common.scope.api.ScopeProvider; import org.gcube.documentstore.persistence.PersistenceBackendFactory; /** @@ -37,7 +37,7 @@ public class AccountingPersistenceFactory { } public synchronized static AccountingPersistence getPersistence() { - String scope = ScopeProvider.instance.get(); + String scope = BasicUsageRecord.getScopeFromToken(); AccountingPersistence accountingPersistence = persistences.get(scope); if(accountingPersistence==null){ accountingPersistence = new AccountingPersistence(scope); diff --git a/src/test/java/org/gcube/testutility/ScopedTest.java b/src/test/java/org/gcube/testutility/ScopedTest.java index 7bc7612..f6c5898 100644 --- a/src/test/java/org/gcube/testutility/ScopedTest.java +++ b/src/test/java/org/gcube/testutility/ScopedTest.java @@ -4,7 +4,7 @@ package org.gcube.testutility; //import org.gcube.common.authorization.library.provider.SecurityTokenProvider; -import org.gcube.common.scope.api.ScopeProvider; +import org.gcube.common.authorization.library.provider.SecurityTokenProvider; import org.junit.Before; /** @@ -15,8 +15,9 @@ public class ScopedTest { @Before public void before() throws Exception{ - //SecurityTokenProvider.instance.reset(); - ScopeProvider.instance.reset(); + SecurityTokenProvider.instance.reset(); + + SecurityTokenProvider.instance.set(""); } }