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:
parent
87e0ba1ba0
commit
3ab13d8d6e
38
pom.xml
38
pom.xml
|
@ -27,41 +27,67 @@
|
||||||
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId}</url>
|
<url>https://svn.d4science.research-infrastructures.eu/gcube/trunk/accounting/${project.artifactId}</url>
|
||||||
</scm>
|
</scm>
|
||||||
|
|
||||||
|
<dependencyManagement>
|
||||||
<dependencies>
|
<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>
|
<dependency>
|
||||||
<groupId>org.gcube.data.publishing</groupId>
|
<groupId>org.gcube.data.publishing</groupId>
|
||||||
<artifactId>document-store-lib</artifactId>
|
<artifactId>document-store-lib</artifactId>
|
||||||
<version>[1.1.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.resources.discovery</groupId>
|
<groupId>org.gcube.resources.discovery</groupId>
|
||||||
<artifactId>ic-client</artifactId>
|
<artifactId>ic-client</artifactId>
|
||||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-scope</artifactId>
|
<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>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.resources</groupId>
|
<groupId>org.gcube.resources</groupId>
|
||||||
<artifactId>common-gcore-resources</artifactId>
|
<artifactId>common-gcore-resources</artifactId>
|
||||||
<version>[1.0.0-SNAPSHOT,2.0.0-SNAPSHOT)</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.gcube.core</groupId>
|
<groupId>org.gcube.core</groupId>
|
||||||
<artifactId>common-encryption</artifactId>
|
<artifactId>common-encryption</artifactId>
|
||||||
<version>[1.0.0-SNAPSHOT, 2.0.0-SNAPSHOT)</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.slf4j</groupId>
|
<groupId>org.slf4j</groupId>
|
||||||
<artifactId>slf4j-api</artifactId>
|
<artifactId>slf4j-api</artifactId>
|
||||||
<version>1.7.5</version>
|
|
||||||
<scope>provided</scope>
|
<scope>provided</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
|
|
@ -9,7 +9,9 @@ import java.util.Map;
|
||||||
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToRecordType;
|
import org.gcube.accounting.datamodel.backwardcompatibility.MoveToRecordType;
|
||||||
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
|
import org.gcube.accounting.datamodel.validations.annotations.ValidOperationResult;
|
||||||
import org.gcube.accounting.datamodel.validations.validators.ValidOperationResultValidator;
|
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.exception.InvalidValueException;
|
||||||
import org.gcube.documentstore.records.Record;
|
import org.gcube.documentstore.records.Record;
|
||||||
import org.gcube.documentstore.records.implementation.AbstractRecord;
|
import org.gcube.documentstore.records.implementation.AbstractRecord;
|
||||||
|
@ -47,7 +49,6 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
||||||
@RequiredField @ValidOperationResult
|
@RequiredField @ValidOperationResult
|
||||||
public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
|
public static final String OPERATION_RESULT = UsageRecord.OPERATION_RESULT;
|
||||||
|
|
||||||
/*
|
|
||||||
public static String getScopeFromToken(){
|
public static String getScopeFromToken(){
|
||||||
String token = SecurityTokenProvider.instance.get();
|
String token = SecurityTokenProvider.instance.get();
|
||||||
AuthorizationEntry authorizationEntry;
|
AuthorizationEntry authorizationEntry;
|
||||||
|
@ -59,7 +60,6 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
||||||
String scope = authorizationEntry.getContext();
|
String scope = authorizationEntry.getContext();
|
||||||
return scope;
|
return scope;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Initialize variable
|
* Initialize variable
|
||||||
|
@ -68,8 +68,7 @@ public abstract class BasicUsageRecord extends AbstractRecord implements UsageRe
|
||||||
super.init();
|
super.init();
|
||||||
// Backward compatibility
|
// Backward compatibility
|
||||||
try {
|
try {
|
||||||
//this.setScope(getScopeFromToken());
|
this.setScope(getScopeFromToken());
|
||||||
this.setScope(ScopeProvider.instance.get());
|
|
||||||
} catch(Exception e) {
|
} 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.");
|
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.");
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,12 +7,12 @@ import java.security.Key;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||||
import org.gcube.common.encryption.StringEncrypter;
|
import org.gcube.common.encryption.StringEncrypter;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.AccessPoint;
|
||||||
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
import org.gcube.common.resources.gcore.ServiceEndpoint.Property;
|
||||||
import org.gcube.common.resources.gcore.utils.Group;
|
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.PersistenceBackend;
|
||||||
import org.gcube.documentstore.persistence.PersistenceBackendConfiguration;
|
import org.gcube.documentstore.persistence.PersistenceBackendConfiguration;
|
||||||
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
import org.gcube.resources.discovery.client.api.DiscoveryClient;
|
||||||
|
@ -58,8 +58,7 @@ public class AccountingPersistenceConfiguration extends PersistenceBackendConfig
|
||||||
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
DiscoveryClient<ServiceEndpoint> client = ICFactory.clientFor(ServiceEndpoint.class);
|
||||||
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
List<ServiceEndpoint> serviceEndpoints = client.submit(query);
|
||||||
if(serviceEndpoints.size()>1){
|
if(serviceEndpoints.size()>1){
|
||||||
//String scope = BasicUsageRecord.getScopeFromToken();
|
String scope = BasicUsageRecord.getScopeFromToken();
|
||||||
String scope = ScopeProvider.instance.get();
|
|
||||||
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Name/text() eq '%s'", TARGET_SCOPE));
|
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));
|
query.addCondition(String.format("$resource/Profile/AccessPoint/Properties/Property/Value/text() eq '%s'", scope));
|
||||||
serviceEndpoints = client.submit(query);
|
serviceEndpoints = client.submit(query);
|
||||||
|
|
|
@ -7,9 +7,9 @@ import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.concurrent.TimeUnit;
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.gcube.accounting.datamodel.BasicUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
import org.gcube.accounting.datamodel.aggregation.AggregatedServiceUsageRecord;
|
||||||
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
import org.gcube.accounting.datamodel.usagerecords.ServiceUsageRecord;
|
||||||
import org.gcube.common.scope.api.ScopeProvider;
|
|
||||||
import org.gcube.documentstore.persistence.PersistenceBackendFactory;
|
import org.gcube.documentstore.persistence.PersistenceBackendFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -37,7 +37,7 @@ public class AccountingPersistenceFactory {
|
||||||
}
|
}
|
||||||
|
|
||||||
public synchronized static AccountingPersistence getPersistence() {
|
public synchronized static AccountingPersistence getPersistence() {
|
||||||
String scope = ScopeProvider.instance.get();
|
String scope = BasicUsageRecord.getScopeFromToken();
|
||||||
AccountingPersistence accountingPersistence = persistences.get(scope);
|
AccountingPersistence accountingPersistence = persistences.get(scope);
|
||||||
if(accountingPersistence==null){
|
if(accountingPersistence==null){
|
||||||
accountingPersistence = new AccountingPersistence(scope);
|
accountingPersistence = new AccountingPersistence(scope);
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
package org.gcube.testutility;
|
package org.gcube.testutility;
|
||||||
|
|
||||||
//import org.gcube.common.authorization.library.provider.SecurityTokenProvider;
|
//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;
|
import org.junit.Before;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -15,8 +15,9 @@ public class ScopedTest {
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void before() throws Exception{
|
public void before() throws Exception{
|
||||||
//SecurityTokenProvider.instance.reset();
|
SecurityTokenProvider.instance.reset();
|
||||||
ScopeProvider.instance.reset();
|
|
||||||
|
SecurityTokenProvider.instance.set("");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue