You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airavata.apache.org by ma...@apache.org on 2019/07/11 21:05:40 UTC
[airavata] branch staging updated: AIRAVATA-3098 Create user
profile when user is enabled
This is an automated email from the ASF dual-hosted git repository.
machristie pushed a commit to branch staging
in repository https://gitbox.apache.org/repos/asf/airavata.git
The following commit(s) were added to refs/heads/staging by this push:
new ea2d593 AIRAVATA-3098 Create user profile when user is enabled
ea2d593 is described below
commit ea2d593887bffb57dc39ac9dd3c16624a776e732
Author: Marcus Christie <ma...@iu.edu>
AuthorDate: Thu Jul 11 17:05:27 2019 -0400
AIRAVATA-3098 Create user profile when user is enabled
---
.../profile/handlers/IamAdminServicesHandler.java | 34 ++++++++++++++++++----
.../airavata/common/utils/DBEventService.java | 3 +-
.../registry/api/service/util/Constants.java | 9 +++---
.../airavata/sharing/registry/utils/Constants.java | 1 +
4 files changed, 36 insertions(+), 11 deletions(-)
diff --git a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java
index ea6d504..4c6b6d0 100644
--- a/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java
+++ b/airavata-services/profile-service/profile-service-server/src/main/java/org/apache/airavata/service/profile/handlers/IamAdminServicesHandler.java
@@ -19,14 +19,22 @@
*/
package org.apache.airavata.service.profile.handlers;
+import java.util.List;
+
+import org.apache.airavata.common.exception.AiravataException;
import org.apache.airavata.common.exception.ApplicationSettingsException;
+import org.apache.airavata.common.utils.AiravataUtils;
import org.apache.airavata.common.utils.Constants;
+import org.apache.airavata.common.utils.DBEventService;
import org.apache.airavata.common.utils.ServerSettings;
import org.apache.airavata.credential.store.client.CredentialStoreClientFactory;
import org.apache.airavata.credential.store.cpi.CredentialStoreService;
import org.apache.airavata.credential.store.exception.CredentialStoreException;
+import org.apache.airavata.messaging.core.util.DBEventPublisherUtils;
import org.apache.airavata.model.appcatalog.gatewayprofile.GatewayResourceProfile;
import org.apache.airavata.model.credential.store.PasswordCredential;
+import org.apache.airavata.model.dbevent.CrudType;
+import org.apache.airavata.model.dbevent.EntityType;
import org.apache.airavata.model.error.AuthorizationException;
import org.apache.airavata.model.security.AuthzToken;
import org.apache.airavata.model.user.UserProfile;
@@ -36,18 +44,19 @@ import org.apache.airavata.registry.api.client.RegistryServiceClientFactory;
import org.apache.airavata.registry.api.exception.RegistryServiceException;
import org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl;
import org.apache.airavata.service.profile.iam.admin.services.cpi.IamAdminServices;
-import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException;
import org.apache.airavata.service.profile.iam.admin.services.cpi.iam_admin_services_cpiConstants;
+import org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException;
+import org.apache.airavata.service.profile.user.core.repositories.UserProfileRepository;
import org.apache.airavata.service.security.interceptor.SecurityCheck;
import org.apache.thrift.TException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
-import java.util.List;
-
public class IamAdminServicesHandler implements IamAdminServices.Iface {
private final static Logger logger = LoggerFactory.getLogger(IamAdminServicesHandler.class);
+ private UserProfileRepository userProfileRepository = new UserProfileRepository();
+ private DBEventPublisherUtils dbEventPublisherUtils = new DBEventPublisherUtils(DBEventService.IAM_ADMIN);
@Override
public String getAPIVersion() throws TException {
@@ -111,11 +120,24 @@ public class IamAdminServicesHandler implements IamAdminServices.Iface {
TenantManagementKeycloakImpl keycloakclient = new TenantManagementKeycloakImpl();
String gatewayId = authzToken.getClaimsMap().get(Constants.GATEWAY_ID);
try {
- if (keycloakclient.enableUserAccount(authzToken.getAccessToken(), gatewayId, username))
+ if (keycloakclient.enableUserAccount(authzToken.getAccessToken(), gatewayId, username)) {
+ // Check if user profile exists, if not create it
+ boolean userProfileExists = userProfileRepository.getUserProfileByIdAndGateWay(username, gatewayId) != null;
+ if (!userProfileExists) {
+ // Load basic user profile information from Keycloak and then save in UserProfileRepository
+ UserProfile userProfile = keycloakclient.getUser(authzToken.getAccessToken(), gatewayId, username);
+ userProfile.setCreationTime(AiravataUtils.getCurrentTimestamp().getTime());
+ userProfile.setLastAccessTime(AiravataUtils.getCurrentTimestamp().getTime());
+ userProfile.setValidUntil(-1);
+ userProfileRepository.createUserProfile(userProfile);
+ // Dispatch IAM_ADMIN service event for a new USER_PROFILE
+ dbEventPublisherUtils.publish(EntityType.USER_PROFILE, CrudType.CREATE, userProfile);
+ }
return true;
- else
+ } else {
return false;
- } catch (TException ex) {
+ }
+ } catch (TException | AiravataException ex) {
String msg = "Error while enabling user account, reason: " + ex.getMessage();
logger.error(msg, ex);
throw new IamAdminServicesException(msg);
diff --git a/modules/commons/src/main/java/org/apache/airavata/common/utils/DBEventService.java b/modules/commons/src/main/java/org/apache/airavata/common/utils/DBEventService.java
index 626fc9f..b700720 100644
--- a/modules/commons/src/main/java/org/apache/airavata/common/utils/DBEventService.java
+++ b/modules/commons/src/main/java/org/apache/airavata/common/utils/DBEventService.java
@@ -28,7 +28,8 @@ public enum DBEventService {
USER_PROFILE("user.profile"),
SHARING("sharing"),
REGISTRY("registry"),
- TENANT("tenant");
+ TENANT("tenant"),
+ IAM_ADMIN("iam.admin");
private final String name;
DBEventService(String name) {
diff --git a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/Constants.java b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/Constants.java
index 93ddc1d..794af39 100644
--- a/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/Constants.java
+++ b/modules/registry/registry-server/registry-api-service/src/main/java/org/apache/airavata/registry/api/service/util/Constants.java
@@ -30,8 +30,9 @@ public class Constants {
public static final String REGISTRY_SERVER_NAME = "regserver.server.name";
public static final String REGISTRY_SERVER_MIN_THREADS = "regserver.server.min.threads";
- public static final List<String> DB_EVENT_SUBSCRIBERS = new ArrayList<String>(){
- {add(DBEventService.USER_PROFILE.toString());}
- {add(DBEventService.TENANT.toString());}
- };
+ public static final List<String> DB_EVENT_SUBSCRIBERS = new ArrayList<String>(){{
+ add(DBEventService.USER_PROFILE.toString());
+ add(DBEventService.TENANT.toString());
+ add(DBEventService.IAM_ADMIN.toString());
+ }};
}
diff --git a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/utils/Constants.java b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/utils/Constants.java
index d7b4892..10bce03 100644
--- a/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/utils/Constants.java
+++ b/modules/sharing-registry/sharing-registry-server/src/main/java/org/apache/airavata/sharing/registry/utils/Constants.java
@@ -36,5 +36,6 @@ public class Constants {
add(DBEventService.USER_PROFILE.toString());
add(DBEventService.TENANT.toString());
add(DBEventService.REGISTRY.toString());
+ add(DBEventService.IAM_ADMIN.toString());
}};
}