Using new authorization lib

git-svn-id: https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/accounting-lib@130783 82a268e6-3cf1-43bd-a215-b396298e98cf
This commit is contained in:
Luca Frosini 2016-07-25 15:27:51 +00:00
parent 87e0ba1ba0
commit 3ab13d8d6e
5 changed files with 44 additions and 19 deletions

38
pom.xml
View File

@ -27,41 +27,67 @@
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId}</url>
</scm>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.distribution</groupId>
<artifactId>gcube-bom</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>authorization-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.common</groupId>
<artifactId>common-authorization</artifactId>
<version>[2.0.0-SNAPSHOT, 3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.data.publishing</groupId>
<artifactId>document-store-lib</artifactId>
<version>[1.1.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>ic-client</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-scope</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<version>[2.0.0-SNAPSHOT,3.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources.discovery</groupId>
<artifactId>discovery-client</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.resources</groupId>
<artifactId>common-gcore-resources</artifactId>
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.gcube.core</groupId>
<artifactId>common-encryption</artifactId>
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.5</version>
<scope>provided</scope>
</dependency>

View File

@ -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.");
}

View File

@ -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<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
List<ServiceEndpoint> 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);

View File

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

View File

@ -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("");
}
}