Skip to content

Commit

Permalink
Merge pull request #45 from isururanawaka/microservices_based_impl
Browse files Browse the repository at this point in the history
minimize update request operations
  • Loading branch information
isururanawaka authored Apr 29, 2020
2 parents dd3596d + c80e53d commit 019e8ba
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ iam.federated.cilogon.token.userinfo.endpoint=https://cilogon.org/oauth2/userinf
iam.federated.cilogon.issuer=https://cilogon.org
iam.federated.cilogon.jwksUri=https://cilogon.org/oauth2/certs
introspection.endpoint=https://custos.scigap.org:32036/identity-management/v1.0.0/token/introspect
issuer=https://custos.scigap.org:32036/
authorization.endpoint=https://custos.scigap.org:32036/identity-management/v1.0.0/authorize
token.endpoint=https://custos.scigap.org:32036/identity-management/v1.0.0/token
end.session.endpoint=https://custos.scigap.org:32036/identity-management/v1.0.0/logout
user.info.endpoint=https://custos.scigap.org:32036/user-management/v1.0.0/userinfo
jwks_uri=https://custos.scigap.org:32036/identity-management/v1.0.0/certs
registration.endpoint=https://custos.scigap.org:32036/tenant-management/v1.0.0/oauth2/tenant
issuer=https://custos.scigap.org/
authorization.endpoint=https://custos.scigap.org/apiserver/identity-management/v1.0.0/authorize
token.endpoint=https://custos.scigap.org/apiserver/identity-management/v1.0.0/token
end.session.endpoint=https://custos.scigap.org/apiserver/identity-management/v1.0.0/logout
user.info.endpoint=https://custos.scigap.org/apiserver/user-management/v1.0.0/userinfo
jwks_uri=https://custos.scigap.org/apiserver/identity-management/v1.0.0/certs
registration.endpoint=https://custos.scigap.org/apiserver/tenant-management/v1.0.0/oauth2/tenant
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ iam.server.url=https://keycloak.custos.scigap.org:31000/auth/
iam.server.truststore.path=/home/ubuntu/keystore/keycloak-client-truststore.pkcs12
iam.server.truststore.password=keycloak
introspection.endpoint=https://custos.scigap.org:32036/identity-management/v1.0.0/token/introspect
issuer=https://custos.scigap.org:32036/
authorization.endpoint=https://custos.scigap.org:32036/identity-management/v1.0.0/authorize
token.endpoint=https://custos.scigap.org:32036/identity-management/v1.0.0/token
end.session.endpoint=https://custos.scigap.org:32036/identity-management/v1.0.0/logout
user.info.endpoint=https://custos.scigap.org:32036/user-management/v1.0.0/userinfo
jwks_uri=https://custos.scigap.org:32036/identity-management/v1.0.0/certs
registration.endpoint=https://custos.scigap.org:32036/tenant-management/v1.0.0/oauth2/tenant
issuer=https://custos.scigap.org/
authorization.endpoint=https://custos.scigap.org/apiserver/identity-management/v1.0.0/authorize
token.endpoint=https://custos.scigap.org/apiserver/identity-management/v1.0.0/token
end.session.endpoint=https://custos.scigap.org/apiserver/identity-management/v1.0.0/logout
user.info.endpoint=https://custos.scigap.org/apiserver/user-management/v1.0.0/userinfo
jwks_uri=https://custos.scigap.org/apiserver/identity-management/v1.0.0/certs
registration.endpoint=https://custos.scigap.org:/apiserver/tenant-management/v1.0.0/oauth2/tenant
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ public <ReqT> ReqT intercept(String method, Metadata headers, ReqT msg) {

String clientId = tenantRequest.getClientId();

if (clientId == null || clientId.trim().equals("")) {
clientId = tenantRequest.getBody().getClientId();
}

GetCredentialRequest request = GetCredentialRequest.newBuilder()
.setId(clientId)
.build();
Expand All @@ -105,7 +109,7 @@ public <ReqT> ReqT intercept(String method, Metadata headers, ReqT msg) {

Tenant tenant = validateTenant(metadata.getOwnerId(), tenantRequest.getTenantId(), headers);

return (ReqT) tenantRequest.toBuilder().setTenantId(tenant.getTenantId()).build();
return (ReqT) tenantRequest.toBuilder().setTenantId(tenant.getTenantId()).setClientId(clientId).build();

} else if (method.equals("deleteTenant")) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,11 @@ private boolean validateUpdateTenant(Metadata headers, Object body, String metho

String clientId = tenantRequest.getClientId();

if (clientId == null || clientId.trim().equals("")) {
clientId = tenantRequest.getBody().getClientId();
}

LOGGER.info("CLient Id "+ clientId);

if (clientId == null || clientId.trim().equals("")) {
throw new MissingParameterException("client_id should not be null", null);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,39 +216,43 @@ public UpdateStatusResponse activateTenant(Tenant tenant, String performedBy, bo
clientMetadataBuilder.setClientId(creMeta.getId());


RegisterClientResponse registerClientResponse = federatedAuthenticationClient
.addClient(clientMetadataBuilder.build());


CredentialMetadata credentialMetadataCILogon = CredentialMetadata
.newBuilder()
.setId(registerClientResponse.getClientId())
.setSecret(registerClientResponse.getClientSecret())
.setOwnerId(tenant.getTenantId())
.setType(Type.CILOGON)
.build();

credentialStoreServiceClient.putCredential(credentialMetadataCILogon);
if (!update) {
RegisterClientResponse registerClientResponse = federatedAuthenticationClient
.addClient(clientMetadataBuilder.build());


CredentialMetadata credentialMetadataCILogon = CredentialMetadata
.newBuilder()
.setId(registerClientResponse.getClientId())
.setSecret(registerClientResponse.getClientSecret())
.setOwnerId(tenant.getTenantId())
.setType(Type.CILOGON)
.build();

credentialStoreServiceClient.putCredential(credentialMetadataCILogon);


ConfigureFederateIDPRequest request = ConfigureFederateIDPRequest
.newBuilder()
.setTenantId(tenant.getTenantId())
.setClientID(registerClientResponse.getClientId())
.setClientSec(registerClientResponse.getClientSecret())
.setScope(tenant.getScope())
.setRequesterEmail(tenant.getRequesterEmail())
.setType(FederatedIDPs.CILOGON)
.build();
iamAdminServiceClient.configureFederatedIDP(request);
} else {
federatedAuthenticationClient
.updateClient(clientMetadataBuilder.build());
}

org.apache.custos.tenant.profile.service.UpdateStatusRequest updateTenantRequest =
org.apache.custos.tenant.profile.service.UpdateStatusRequest.newBuilder()
.setTenantId(tenant.getTenantId())
.setStatus(TenantStatus.ACTIVE)
.setUpdatedBy(Constants.SYSTEM)
.build();

ConfigureFederateIDPRequest request = ConfigureFederateIDPRequest
.newBuilder()
.setTenantId(tenant.getTenantId())
.setClientID(registerClientResponse.getClientId())
.setClientSec(registerClientResponse.getClientSecret())
.setScope(tenant.getScope())
.setRequesterEmail(tenant.getRequesterEmail())
.setType(FederatedIDPs.CILOGON)
.build();
iamAdminServiceClient.configureFederatedIDP(request);


return profileClient.updateTenantStatus(updateTenantRequest);
}

Expand Down

0 comments on commit 019e8ba

Please sign in to comment.