This is an automated email from the ASF dual-hosted git repository.
isjarana pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/airavata-custos.git
The following commit(s) were added to refs/heads/develop by this push:
new 2fa7595 Add institutional whitelisting and backlisting for tenants
new 3142e49 Merge pull request #90 from
isururanawaka/institutional_caching
2fa7595 is described below
commit 2fa75953ef2c7a02bc4545caca1825d60e9b2739
Author: Isuru Ranawaka <[email protected]>
AuthorDate: Tue Jul 7 14:48:47 2020 -0400
Add institutional whitelisting and backlisting for tenants
---
.../client/FederatedAuthenticationClient.java | 33 ++++++--
.../service/FederatedAuthenticationService.java | 83 +++++++++++++--------
.../authentication/validator/InputValidator.java | 18 ++---
.../proto/FederatedAuthenticationService.proto | 16 ++--
.../main/resources/tenant-management-service.pb | Bin 132895 -> 148047 bytes
.../interceptors/AuthInterceptorImpl.java | 43 ++++++++++-
.../management/interceptors/InputValidator.java | 6 ++
.../service/TenantManagementService.java | 74 ++++++++++++++++++
.../custos/tenant/management/utils/Constants.java | 2 +
.../src/main/proto/TenantManagementService.proto | 27 ++++++-
10 files changed, 248 insertions(+), 54 deletions(-)
diff --git
a/custos-core-services-client-stubs/federated-authentication-core-service-client-stub/src/main/java/org/apache/custos/federated/authentication/client/FederatedAuthenticationClient.java
b/custos-core-services-client-stubs/federated-authentication-core-service-client-stub/src/main/java/org/apache/custos/federated/authentication/client/FederatedAuthenticationClient.java
index 899e9f6..3876828 100644
---
a/custos-core-services-client-stubs/federated-authentication-core-service-client-stub/src/main/java/org/apache/custos/federated/authentication/client/FederatedAuthenticationClient.java
+++
b/custos-core-services-client-stubs/federated-authentication-core-service-client-stub/src/main/java/org/apache/custos/federated/authentication/client/FederatedAuthenticationClient.java
@@ -44,8 +44,8 @@ public class FederatedAuthenticationClient {
public FederatedAuthenticationClient(List<ClientInterceptor>
clientInterceptorList,
-
@Value("${federated.authentication.service.dns.name}") String serviceHost,
-
@Value("${federated.authentication.service.port}") int servicePort) {
+
@Value("${federated.authentication.service.dns.name}") String serviceHost,
+
@Value("${federated.authentication.service.port}") int servicePort) {
this.clientInterceptorList = clientInterceptorList;
managedChannel = ManagedChannelBuilder.forAddress(
serviceHost,
servicePort).usePlaintext(true).intercept(clientInterceptorList).build();
@@ -63,6 +63,7 @@ public class FederatedAuthenticationClient {
StreamObserver observer = this.getObserver(callback, "updateClient
task failed");
federatedAuthenticationServiceStub.updateClient(request, observer);
}
+
public void deleteClientAsync(DeleteClientRequest request, final
ServiceCallback callback) {
StreamObserver observer = this.getObserver(callback, "deleteClient
task failed");
federatedAuthenticationServiceStub.deleteClient(request, observer);
@@ -70,7 +71,7 @@ public class FederatedAuthenticationClient {
public void getOperationsMetadataAsync(GetOperationsMetadataRequest
request, final ServiceCallback callback) {
StreamObserver observer = getObserver(callback, "get operations
metadata");
-
federatedAuthenticationServiceStub.getOperationMetadata(request,observer);
+ federatedAuthenticationServiceStub.getOperationMetadata(request,
observer);
}
public void getClientAsync(GetClientRequest request) {
@@ -78,15 +79,17 @@ public class FederatedAuthenticationClient {
}
public RegisterClientResponse addClient(ClientMetadata request) {
- return federatedAuthenticationServiceBlockingStub.addClient(request);
+ return federatedAuthenticationServiceBlockingStub.addClient(request);
}
- public Empty updateClient(ClientMetadata request) {
+ public Empty updateClient(ClientMetadata request) {
return
federatedAuthenticationServiceBlockingStub.updateClient(request);
}
+
public Empty deleteClient(DeleteClientRequest request) {
- return
federatedAuthenticationServiceBlockingStub.deleteClient(request);
+ return
federatedAuthenticationServiceBlockingStub.deleteClient(request);
}
+
public GetClientResponse getClient(GetClientRequest request) {
return federatedAuthenticationServiceBlockingStub.getClient(request);
}
@@ -95,6 +98,24 @@ public class FederatedAuthenticationClient {
return
federatedAuthenticationServiceBlockingStub.getOperationMetadata(request);
}
+ public Status addToCache(CacheManipulationRequest request) {
+ return federatedAuthenticationServiceBlockingStub.addToCache(request);
+ }
+
+
+ public Status removeFromCache(CacheManipulationRequest request) {
+ return
federatedAuthenticationServiceBlockingStub.removeFromCache(request);
+ }
+
+ public GetInstitutionsIdsAsResponse getFromCache(CacheManipulationRequest
request) {
+ return
federatedAuthenticationServiceBlockingStub.getFromCache(request);
+ }
+
+ public GetInstitutionsResponse getInstitutions(CacheManipulationRequest
request) {
+ return
federatedAuthenticationServiceBlockingStub.getInstitutions(request);
+ }
+
+
private StreamObserver getObserver(ServiceCallback callback, String
failureMsg) {
final Object[] response = new Object[1];
StreamObserver observer = new StreamObserver() {
diff --git
a/custos-core-services/federated-authentication-core-service/src/main/java/org/apache/custos/federated/authentication/service/FederatedAuthenticationService.java
b/custos-core-services/federated-authentication-core-service/src/main/java/org/apache/custos/federated/authentication/service/FederatedAuthenticationService.java
index c6c0bcf..2e2a8a4 100644
---
a/custos-core-services/federated-authentication-core-service/src/main/java/org/apache/custos/federated/authentication/service/FederatedAuthenticationService.java
+++
b/custos-core-services/federated-authentication-core-service/src/main/java/org/apache/custos/federated/authentication/service/FederatedAuthenticationService.java
@@ -239,14 +239,14 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
@Override
- public void addToCache(InstitutionOperationRequest request,
StreamObserver<Status> responseObserver) {
+ public void addToCache(CacheManipulationRequest request,
StreamObserver<Status> responseObserver) {
try {
LOGGER.debug("Calling addToCache API for tenantId " +
request.getTenantId());
long tenantId = request.getTenantId();
- List<String> ids = request.getInstitutionIdList();
+ List<String> ids = request.getInstitutionIdsList();
InstitutionCacheType type = request.getType();
@@ -257,6 +257,22 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
});
+
+ for (CILogonInstitution ciLogonInstitution : ciLogonInstitutions) {
+
+ Optional<CILogonInstitution> optionalCILogonInstitution =
+
institutionRespository.findById(ciLogonInstitution.getId());
+
+ if (optionalCILogonInstitution.isPresent()) {
+ String msg = " Duplicate entry with Id " +
ciLogonInstitution.getInstitutionId();
+ LOGGER.error(msg);
+
responseObserver.onError(io.grpc.Status.ALREADY_EXISTS.withDescription(msg).asRuntimeException());
+ return;
+ }
+
+ }
+
+
institutionRespository.saveAll(ciLogonInstitutions);
Status status = Status.newBuilder().setStatus(true).build();
@@ -264,20 +280,19 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
responseObserver.onCompleted();
} catch (Exception ex) {
- FederatedAuthenticationServiceException failedException =
- new FederatedAuthenticationServiceException(" operation
failed for "
- + request.getTenantId(), ex);
- responseObserver.onError(failedException);
+ String msg = " Error at federated authentication core service " +
ex;
+ LOGGER.error(msg);
+
responseObserver.onError(io.grpc.Status.INTERNAL.withDescription(msg).asRuntimeException());
}
}
@Override
- public void removeFromCache(InstitutionOperationRequest request,
StreamObserver<Status> responseObserver) {
+ public void removeFromCache(CacheManipulationRequest request,
StreamObserver<Status> responseObserver) {
try {
LOGGER.debug("Calling removeFromCache API for tenantId" +
request.getTenantId());
long tenantId = request.getTenantId();
- List<String> ids = request.getInstitutionIdList();
+ List<String> ids = request.getInstitutionIdsList();
List<CILogonInstitution> ciLogonInstitutions = new ArrayList<>();
@@ -301,15 +316,14 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
responseObserver.onCompleted();
} catch (Exception ex) {
- FederatedAuthenticationServiceException failedException =
- new FederatedAuthenticationServiceException(" operation
failed for "
- + request.getTenantId(), ex);
- responseObserver.onError(failedException);
+ String msg = " Error at federated authentication core service " +
ex;
+ LOGGER.error(msg);
+
responseObserver.onError(io.grpc.Status.INTERNAL.withDescription(msg).asRuntimeException());
}
}
@Override
- public void getFromCache(InstitutionOperationRequest request,
StreamObserver<GetInstitutionsResponse> responseObserver) {
+ public void getFromCache(CacheManipulationRequest request,
StreamObserver<GetInstitutionsIdsAsResponse> responseObserver) {
try {
LOGGER.debug("Calling getFromCache API for tenantId " +
request.getTenantId());
@@ -320,41 +334,41 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
List<CILogonInstitution> institutions =
institutionRespository.findAllByTenantIdAndType(tenant, type);
- List<Institution> institutionList = new ArrayList<>();
+ List<String> institutionList = new ArrayList<>();
if (institutions != null && !institutions.isEmpty()) {
for (CILogonInstitution institution : institutions) {
- institutionList.add(ModelMapper.convert(institution));
+ institutionList.add(institution.getInstitutionId());
}
}
- GetInstitutionsResponse response = GetInstitutionsResponse.
- newBuilder().addAllInstitutions(institutionList).build();
+ GetInstitutionsIdsAsResponse response =
GetInstitutionsIdsAsResponse.
+ newBuilder().addAllEntityIds(institutionList).build();
responseObserver.onNext(response);
responseObserver.onCompleted();
} catch (Exception ex) {
- FederatedAuthenticationServiceException failedException =
- new FederatedAuthenticationServiceException(" operation
failed for "
- + request.getTenantId(), ex);
- responseObserver.onError(failedException);
+ String msg = " Error at federated authentication core service " +
ex;
+ LOGGER.error(msg);
+
responseObserver.onError(io.grpc.Status.INTERNAL.withDescription(msg).asRuntimeException());
}
}
@Override
- public void getInstitutions(InstitutionOperationRequest request,
StreamObserver<GetInstitutionsResponse> responseObserver) {
+ public void getInstitutions(CacheManipulationRequest request,
StreamObserver<GetInstitutionsResponse> responseObserver) {
try {
LOGGER.debug("Calling getInstitutions API for tenantId " +
request.getTenantId());
long tenant = request.getTenantId();
- String type = request.getType().name();
- List<CILogonInstitution> institutions =
institutionRespository.findAllByTenantIdAndType(tenant, type);
+ List<CILogonInstitution> institutions =
institutionRespository.findAllByTenantIdAndType(tenant,
InstitutionCacheType.WHITELIST.name());
+
+ List<CILogonInstitution> backListedInstituions =
institutionRespository.findAllByTenantIdAndType(tenant,
InstitutionCacheType.BACKLIST.name());
org.apache.custos.federated.services.clients.cilogon.CILogonInstitution[]
ciLogonInstitutions =
@@ -362,7 +376,12 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
List<org.apache.custos.federated.services.clients.cilogon.CILogonInstitution>
selectedLists = new ArrayList<>();
- if (type.equals(InstitutionCacheType.WHITELIST.name())) {
+ if (institutions.isEmpty() && backListedInstituions.isEmpty()) {
+
+ selectedLists.addAll(Arrays.asList(ciLogonInstitutions));
+
+ } else if (!institutions.isEmpty()) {
+
for
(org.apache.custos.federated.services.clients.cilogon.CILogonInstitution
ciLogonInstitution : ciLogonInstitutions) {
@@ -381,12 +400,14 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
for
(org.apache.custos.federated.services.clients.cilogon.CILogonInstitution
ciLogonInstitution : ciLogonInstitutions) {
AtomicBoolean doNotAdd = new AtomicBoolean(false);
- institutions.forEach(it -> {
+ for (CILogonInstitution it : backListedInstituions) {
if
(it.getInstitutionId().equals(ciLogonInstitution.getEntityId())) {
doNotAdd.set(true);
+ break;
+
}
- });
+ }
if (!doNotAdd.get()) {
selectedLists.add(ciLogonInstitution);
@@ -395,6 +416,7 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
}
}
+
List<Institution> institutionList = new ArrayList<>();
selectedLists.forEach(sl -> {
@@ -410,10 +432,9 @@ public class FederatedAuthenticationService extends
FederatedAuthenticationServi
responseObserver.onCompleted();
} catch (Exception ex) {
- FederatedAuthenticationServiceException failedException =
- new FederatedAuthenticationServiceException(" operation
failed for "
- + request.getTenantId(), ex);
- responseObserver.onError(failedException);
+ String msg = " Error at federated authentication core service " +
ex;
+ LOGGER.error(msg);
+
responseObserver.onError(io.grpc.Status.INTERNAL.withDescription(msg).asRuntimeException());
}
}
diff --git
a/custos-core-services/federated-authentication-core-service/src/main/java/org/apache/custos/federated/authentication/validator/InputValidator.java
b/custos-core-services/federated-authentication-core-service/src/main/java/org/apache/custos/federated/authentication/validator/InputValidator.java
index b8912b1..e39fa27 100644
---
a/custos-core-services/federated-authentication-core-service/src/main/java/org/apache/custos/federated/authentication/validator/InputValidator.java
+++
b/custos-core-services/federated-authentication-core-service/src/main/java/org/apache/custos/federated/authentication/validator/InputValidator.java
@@ -22,10 +22,10 @@ package
org.apache.custos.federated.authentication.validator;
import org.apache.custos.core.services.commons.Validator;
import
org.apache.custos.federated.authentication.exceptions.MissingParameterException;
+import
org.apache.custos.federated.authentication.service.CacheManipulationRequest;
import org.apache.custos.federated.authentication.service.ClientMetadata;
import org.apache.custos.federated.authentication.service.DeleteClientRequest;
import org.apache.custos.federated.authentication.service.GetClientRequest;
-import
org.apache.custos.federated.authentication.service.InstitutionOperationRequest;
/**
* This class validates the requests
@@ -138,14 +138,14 @@ public class InputValidator implements Validator {
private boolean validateAddToCache(Object object, String methodName) {
- if (object instanceof InstitutionOperationRequest) {
- InstitutionOperationRequest request =
(InstitutionOperationRequest) object;
+ if (object instanceof CacheManipulationRequest) {
+ CacheManipulationRequest request = (CacheManipulationRequest)
object;
if (request.getTenantId() == 0) {
throw new MissingParameterException("Tenant Id should not be
null", null);
}
- if (request.getInstitutionIdList() == null ||
request.getInstitutionIdList().isEmpty()) {
+ if (request.getInstitutionIdsList() == null ||
request.getInstitutionIdsList().isEmpty()) {
throw new MissingParameterException("Institutional id list is
empty", null);
}
@@ -162,14 +162,14 @@ public class InputValidator implements Validator {
private boolean validateRemoveToCache(Object object, String methodName) {
- if (object instanceof InstitutionOperationRequest) {
- InstitutionOperationRequest request =
(InstitutionOperationRequest) object;
+ if (object instanceof CacheManipulationRequest) {
+ CacheManipulationRequest request = (CacheManipulationRequest)
object;
if (request.getTenantId() == 0) {
throw new MissingParameterException("Tenant Id should not be
null", null);
}
- if (request.getInstitutionIdList() == null ||
request.getInstitutionIdList().isEmpty()) {
+ if (request.getInstitutionIdsList() == null ||
request.getInstitutionIdsList().isEmpty()) {
throw new MissingParameterException("Institutional id list is
empty", null);
}
@@ -182,8 +182,8 @@ public class InputValidator implements Validator {
private boolean validateGetFromCache(Object object, String methodName) {
- if (object instanceof InstitutionOperationRequest) {
- InstitutionOperationRequest request =
(InstitutionOperationRequest) object;
+ if (object instanceof CacheManipulationRequest) {
+ CacheManipulationRequest request = (CacheManipulationRequest)
object;
if (request.getTenantId() == 0) {
throw new MissingParameterException("Tenant Id should not be
null", null);
diff --git
a/custos-core-services/federated-authentication-core-service/src/main/proto/FederatedAuthenticationService.proto
b/custos-core-services/federated-authentication-core-service/src/main/proto/FederatedAuthenticationService.proto
index 564d0d7..8e25b0e 100644
---
a/custos-core-services/federated-authentication-core-service/src/main/proto/FederatedAuthenticationService.proto
+++
b/custos-core-services/federated-authentication-core-service/src/main/proto/FederatedAuthenticationService.proto
@@ -95,9 +95,9 @@ message GetOperationsMetadataResponse {
}
-message InstitutionOperationRequest {
+message CacheManipulationRequest {
int64 tenant_id = 1;
- repeated string institution_id = 2;
+ repeated string institution_ids = 2;
InstitutionCacheType type = 3;
string performedBy = 4;
}
@@ -117,6 +117,10 @@ message Institution {
bool rand_s = 4;
}
+message GetInstitutionsIdsAsResponse {
+ repeated string entity_ids = 1;
+}
+
message GetInstitutionsResponse {
repeated Institution institutions = 2;
@@ -130,9 +134,9 @@ service FederatedAuthenticationService {
rpc deleteClient (DeleteClientRequest) returns (Empty);
rpc getOperationMetadata (GetOperationsMetadataRequest) returns
(GetOperationsMetadataResponse);
- rpc addToCache (InstitutionOperationRequest) returns (Status);
- rpc removeFromCache (InstitutionOperationRequest) returns (Status);
- rpc getFromCache (InstitutionOperationRequest) returns
(GetInstitutionsResponse);
- rpc getInstitutions (InstitutionOperationRequest) returns
(GetInstitutionsResponse);
+ rpc addToCache (CacheManipulationRequest) returns (Status);
+ rpc removeFromCache (CacheManipulationRequest) returns (Status);
+ rpc getFromCache (CacheManipulationRequest) returns
(GetInstitutionsIdsAsResponse);
+ rpc getInstitutions (CacheManipulationRequest) returns
(GetInstitutionsResponse);
}
\ No newline at end of file
diff --git
a/custos-integration-services/tenant-management-service-parent/tenant-management-service-sidecar/src/main/resources/tenant-management-service.pb
b/custos-integration-services/tenant-management-service-parent/tenant-management-service-sidecar/src/main/resources/tenant-management-service.pb
index ed80643..a1f9608 100644
Binary files
a/custos-integration-services/tenant-management-service-parent/tenant-management-service-sidecar/src/main/resources/tenant-management-service.pb
and
b/custos-integration-services/tenant-management-service-parent/tenant-management-service-sidecar/src/main/resources/tenant-management-service.pb
differ
diff --git
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/interceptors/AuthInterceptorImpl.java
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/interceptors/AuthInterceptorImpl.java
index 222b441..4d31ffb 100644
---
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/interceptors/AuthInterceptorImpl.java
+++
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/interceptors/AuthInterceptorImpl.java
@@ -21,6 +21,7 @@ package org.apache.custos.tenant.management.interceptors;
import io.grpc.Metadata;
import org.apache.custos.credential.store.client.CredentialStoreServiceClient;
+import
org.apache.custos.federated.authentication.service.CacheManipulationRequest;
import org.apache.custos.iam.service.AddProtocolMapperRequest;
import org.apache.custos.iam.service.AddRolesRequest;
import org.apache.custos.iam.service.EventPersistenceRequest;
@@ -32,6 +33,7 @@ import
org.apache.custos.tenant.management.service.Credentials;
import org.apache.custos.tenant.management.service.DeleteTenantRequest;
import org.apache.custos.tenant.management.service.GetTenantRequest;
import org.apache.custos.tenant.management.service.UpdateTenantRequest;
+import org.apache.custos.tenant.management.utils.Constants;
import org.apache.custos.tenant.profile.client.async.TenantProfileClient;
import org.apache.custos.tenant.profile.service.GetTenantsRequest;
import org.apache.custos.tenant.profile.service.Tenant;
@@ -139,8 +141,25 @@ public class AuthInterceptorImpl extends AuthInterceptor {
} else if (method.equals("getAllTenantsForUser")) {
validateAuth(headers);
return msg;
- }
+ } else if (method.equals("getFromCache") ||
method.equals("getInstitutions")) {
+ AuthClaim claim = validateAuth(headers);
+
+ CacheManipulationRequest request = ((CacheManipulationRequest)
msg);
+ return (ReqT)
request.toBuilder().setTenantId(claim.getTenantId()).build();
+
+ } else if (method.equals("addToCache") ||
method.equals("removeFromCache")) {
+ AuthClaim claim = validateAuth(headers);
+ AuthClaim userClaim = validateUserToken(headers);
+
+ CacheManipulationRequest.Builder request =
((CacheManipulationRequest) msg).toBuilder();
+
+ if (userClaim != null) {
+ request = request.setPerformedBy(userClaim.getUsername());
+ }
+
+ return (ReqT) request.setTenantId(claim.getTenantId()).build();
+ }
return msg;
}
@@ -159,6 +178,28 @@ public class AuthInterceptorImpl extends AuthInterceptor {
return claim;
}
+
+ private AuthClaim validateUserToken(Metadata headers) {
+ AuthClaim claim = null;
+ try {
+ String usertoken =
headers.get(Metadata.Key.of(Constants.USER_TOKEN,
Metadata.ASCII_STRING_MARSHALLER));
+ if (usertoken == null) {
+ return null;
+ }
+
+ claim = authorizeUsingUserToken(usertoken);
+ } catch (Exception ex) {
+ LOGGER.error(" Authorizing error " + ex.getMessage());
+ throw new NotAuthorizedException("Request is not authorized", ex);
+ }
+ if (claim == null) {
+ throw new NotAuthorizedException("Request is not authorized",
null);
+ }
+ return claim;
+
+
+ }
+
private Credentials getCredentials(AuthClaim claim) {
return Credentials.newBuilder()
.setCustosClientId(claim.getCustosId())
diff --git
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/interceptors/InputValidator.java
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/interceptors/InputValidator.java
index 8879666..9e20043 100644
---
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/interceptors/InputValidator.java
+++
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/interceptors/InputValidator.java
@@ -76,6 +76,12 @@ public class InputValidator implements
IntegrationServiceInterceptor {
case "updateTenantStatus":
validateUpdateTenantStatus(headers, body, methodName);
break;
+ case "addToCache":
+ case "removeFromCache":
+ case "getFromCache":
+ case "getInstitutions":
+ validationAuthorizationHeader(headers);
+ break;
default:
}
}
diff --git
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/service/TenantManagementService.java
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/service/TenantManagementService.java
index b0978df..6b52c5e 100644
---
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/service/TenantManagementService.java
+++
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/service/TenantManagementService.java
@@ -25,7 +25,10 @@ import io.grpc.stub.StreamObserver;
import org.apache.custos.credential.store.client.CredentialStoreServiceClient;
import org.apache.custos.credential.store.service.*;
import
org.apache.custos.federated.authentication.client.FederatedAuthenticationClient;
+import
org.apache.custos.federated.authentication.service.CacheManipulationRequest;
import org.apache.custos.federated.authentication.service.DeleteClientRequest;
+import
org.apache.custos.federated.authentication.service.GetInstitutionsIdsAsResponse;
+import
org.apache.custos.federated.authentication.service.GetInstitutionsResponse;
import org.apache.custos.iam.admin.client.IamAdminServiceClient;
import org.apache.custos.iam.service.OperationStatus;
import org.apache.custos.iam.service.*;
@@ -656,6 +659,76 @@ public class TenantManagementService extends
TenantManagementServiceImplBase {
@Override
+ public void addToCache(CacheManipulationRequest request,
+
StreamObserver<org.apache.custos.federated.authentication.service.Status>
responseObserver) {
+ try {
+ LOGGER.debug("Request received to add to cache for tenant " +
request.getTenantId());
+
+
+ org.apache.custos.federated.authentication.service.Status status =
federatedAuthenticationClient.addToCache(request);
+
+ responseObserver.onNext(status);
+ responseObserver.onCompleted();
+
+ } catch (Exception ex) {
+ String msg = "Error occurred calling addToCache method for tenant
" + request.getTenantId() + " reason :" + ex.getMessage();
+ LOGGER.error(msg);
+
responseObserver.onError(Status.INTERNAL.withDescription(msg).asRuntimeException());
+ }
+ }
+
+ @Override
+ public void removeFromCache(CacheManipulationRequest request,
+
StreamObserver<org.apache.custos.federated.authentication.service.Status>
responseObserver) {
+ try {
+ LOGGER.debug("Request received to removeFromCache for tenant " +
request.getTenantId());
+ org.apache.custos.federated.authentication.service.Status status =
federatedAuthenticationClient.removeFromCache(request);
+
+ responseObserver.onNext(status);
+ responseObserver.onCompleted();
+
+ } catch (Exception ex) {
+ String msg = "Error occurred calling removeFromCache method for
tenant " + request.getTenantId() + " reason :" + ex.getMessage();
+ LOGGER.error(msg);
+
responseObserver.onError(Status.INTERNAL.withDescription(msg).asRuntimeException());
+ }
+ }
+
+ @Override
+ public void getFromCache(CacheManipulationRequest request,
+ StreamObserver<GetInstitutionsIdsAsResponse>
responseObserver) {
+ try {
+ LOGGER.debug("Request received to getFromCache for tenant " +
request.getTenantId());
+
+ GetInstitutionsIdsAsResponse status =
federatedAuthenticationClient.getFromCache(request);
+
+ responseObserver.onNext(status);
+ responseObserver.onCompleted();
+ } catch (Exception ex) {
+ String msg = "Error occurred calling getFromCache method for
tenant " + request.getTenantId() + " reason :" + ex.getMessage();
+ LOGGER.error(msg);
+
responseObserver.onError(Status.INTERNAL.withDescription(msg).asRuntimeException());
+ }
+ }
+
+ @Override
+ public void getInstitutions(CacheManipulationRequest request,
+ StreamObserver<GetInstitutionsResponse>
responseObserver) {
+ try {
+ LOGGER.debug("Request received to getInstitutions for tenant " +
request.getTenantId());
+ GetInstitutionsResponse status =
federatedAuthenticationClient.getInstitutions(request);
+
+ responseObserver.onNext(status);
+ responseObserver.onCompleted();
+
+ } catch (Exception ex) {
+ String msg = "Error occurred calling getInstitutions method for
tenant " + request.getTenantId() + " reason :" + ex.getMessage();
+ LOGGER.error(msg);
+
responseObserver.onError(Status.INTERNAL.withDescription(msg).asRuntimeException());
+ }
+ }
+
+ @Override
public void getTenantStatusUpdateAuditTrail(GetAuditTrailRequest request,
StreamObserver<GetStatusUpdateAuditTrailResponse> responseObserver) {
GetStatusUpdateAuditTrailResponse response =
profileClient.getStatusUpdateAuditTrail(request);
@@ -671,6 +744,7 @@ public class TenantManagementService extends
TenantManagementServiceImplBase {
responseObserver.onCompleted();
}
+
private UserProfile convertToProfile(UserRepresentation representation) {
UserProfile.Builder profileBuilder = UserProfile.newBuilder();
diff --git
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/utils/Constants.java
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/utils/Constants.java
index f06966b..21d332c 100644
---
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/utils/Constants.java
+++
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/java/org/apache/custos/tenant/management/utils/Constants.java
@@ -33,4 +33,6 @@ public final class Constants {
public static final String REFRESH_TOKEN = "refresh-token";
public static final String AUTHORIZATION_HEADER = "authorization";
+ public static final String USER_TOKEN = "user-token";
+
}
diff --git
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/proto/TenantManagementService.proto
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/proto/TenantManagementService.proto
index a5816e6..b491ba6 100644
---
a/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/proto/TenantManagementService.proto
+++
b/custos-integration-services/tenant-management-service-parent/tenant-management-service/src/main/proto/TenantManagementService.proto
@@ -28,6 +28,7 @@ import "TenantProfileService.proto";
import "google/rpc/error_details.proto";
import "google/protobuf/empty.proto";
import "IamAdminService.proto";
+import "FederatedAuthenticationService.proto";
message CreateTenantResponse {
@@ -161,7 +162,6 @@ service TenantManagementService {
}
-
rpc updateTenantStatus
(org.apache.custos.tenant.profile.service.UpdateStatusRequest) returns
(org.apache.custos.tenant.profile.service.UpdateStatusResponse) {
option (google.api.http) = {
post: "/tenant-management/v1.0.0/status"
@@ -197,4 +197,29 @@ service TenantManagementService {
}
+ rpc addToCache
(org.apache.custos.federated.authentication.service.CacheManipulationRequest)
returns (org.apache.custos.federated.authentication.service.Status) {
+ option (google.api.http) = {
+ post: "/tenant-management/v1.0.0/cache/institutions/CILogon"
+ };
+
+ }
+ rpc removeFromCache
(org.apache.custos.federated.authentication.service.CacheManipulationRequest)
returns (org.apache.custos.federated.authentication.service.Status) {
+ option (google.api.http) = {
+ delete: "/tenant-management/v1.0.0/cache/institutions/CILogon"
+ };
+
+ }
+ rpc getFromCache
(org.apache.custos.federated.authentication.service.CacheManipulationRequest)
returns
(org.apache.custos.federated.authentication.service.GetInstitutionsIdsAsResponse)
{
+ option (google.api.http) = {
+ get: "/tenant-management/v1.0.0/cache/institutions/CILogon"
+ };
+
+ }
+ rpc getInstitutions
(org.apache.custos.federated.authentication.service.CacheManipulationRequest)
returns
(org.apache.custos.federated.authentication.service.GetInstitutionsResponse) {
+ option (google.api.http) = {
+ get: "/tenant-management/v1.0.0/institutions/CILogon"
+ };
+ }
+
+
}
\ No newline at end of file