Search in sources :

Example 6 with AuthorizationException

use of org.apache.airavata.model.error.AuthorizationException in project airavata by apache.

the class TenantProfileServiceHandler method deleteGateway.

@Override
@SecurityCheck
public boolean deleteGateway(AuthzToken authzToken, String airavataInternalGatewayId, String gatewayId) throws TenantProfileServiceException, AuthorizationException, TException {
    try {
        logger.debug("Deleting Airavata gateway-profile with ID: " + gatewayId + "Internal ID: " + airavataInternalGatewayId);
        boolean deleteSuccess = tenantProfileRepository.delete(airavataInternalGatewayId);
        if (deleteSuccess) {
            // delete tenant at end-places
            ProfileServiceUtils.getDbEventPublisher().publish(ProfileServiceUtils.getDBEventMessageContext(EntityType.TENANT, CrudType.DELETE, // approvalstatus is not used for delete, hence set dummy value
            new Gateway(gatewayId, GatewayApprovalStatus.DEACTIVATED)), DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString()));
        }
        return deleteSuccess;
    } catch (Exception ex) {
        logger.error("Error deleting gateway-profile, reason: " + ex.getMessage(), ex);
        TenantProfileServiceException exception = new TenantProfileServiceException();
        exception.setMessage("Error deleting gateway-profile, reason: " + ex.getMessage());
        throw exception;
    }
}
Also used : TenantProfileServiceException(org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException) Gateway(org.apache.airavata.model.workspace.Gateway) CredentialStoreException(org.apache.airavata.credential.store.exception.CredentialStoreException) TenantProfileServiceException(org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException) TException(org.apache.thrift.TException) AuthorizationException(org.apache.airavata.model.error.AuthorizationException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 7 with AuthorizationException

use of org.apache.airavata.model.error.AuthorizationException in project airavata by apache.

the class TenantProfileServiceHandler method addGateway.

@Override
@SecurityCheck
public String addGateway(AuthzToken authzToken, Gateway gateway) throws TenantProfileServiceException, AuthorizationException, TException {
    try {
        // Assign UUID to gateway
        gateway.setAiravataInternalGatewayId(UUID.randomUUID().toString());
        if (!checkDuplicateGateway(gateway)) {
            // If admin password, copy it in the credential store under the requested gateway's gatewayId
            if (gateway.getIdentityServerPasswordToken() != null) {
                copyAdminPasswordToGateway(authzToken, gateway);
            }
            gateway = tenantProfileRepository.create(gateway);
            if (gateway != null) {
                logger.info("Added Airavata Gateway with Id: " + gateway.getGatewayId());
                // replicate tenant at end-places only if status is APPROVED
                if (gateway.getGatewayApprovalStatus().equals(GatewayApprovalStatus.APPROVED)) {
                    logger.info("Gateway with ID: {}, is now APPROVED, replicating to subscribers.", gateway.getGatewayId());
                    ProfileServiceUtils.getDbEventPublisher().publish(ProfileServiceUtils.getDBEventMessageContext(EntityType.TENANT, CrudType.CREATE, gateway), DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString()));
                }
                // return internal id
                return gateway.getAiravataInternalGatewayId();
            } else {
                throw new Exception("Gateway object is null.");
            }
        } else {
            throw new TenantProfileServiceException("An approved Gateway already exists with the same GatewayId, Name or URL");
        }
    } catch (Exception ex) {
        logger.error("Error adding gateway-profile, reason: " + ex.getMessage(), ex);
        TenantProfileServiceException exception = new TenantProfileServiceException();
        exception.setMessage("Error adding gateway-profile, reason: " + ex.getMessage());
        throw exception;
    }
}
Also used : TenantProfileServiceException(org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException) CredentialStoreException(org.apache.airavata.credential.store.exception.CredentialStoreException) TenantProfileServiceException(org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException) TException(org.apache.thrift.TException) AuthorizationException(org.apache.airavata.model.error.AuthorizationException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Example 8 with AuthorizationException

use of org.apache.airavata.model.error.AuthorizationException in project airavata by apache.

the class UserProfileServiceHandler method addUserProfile.

@Override
@SecurityCheck
public String addUserProfile(AuthzToken authzToken, UserProfile userProfile) throws UserProfileServiceException, AuthorizationException, TException {
    try {
        // Lowercase user id and internal id
        userProfile.setUserId(userProfile.getUserId().toLowerCase());
        userProfile.setAiravataInternalUserId(userProfile.getUserId() + "@" + userProfile.getGatewayId());
        userProfile = userProfileRepository.updateUserProfile(userProfile, getIAMUserProfileUpdater(authzToken, userProfile));
        if (null != userProfile) {
            logger.info("Added UserProfile with userId: " + userProfile.getUserId());
            // replicate userProfile at end-places
            ProfileServiceUtils.getDbEventPublisher().publish(ProfileServiceUtils.getDBEventMessageContext(EntityType.USER_PROFILE, CrudType.CREATE, userProfile), DBEventManagerConstants.getRoutingKey(DBEventService.DB_EVENT.toString()));
            // return userId
            return userProfile.getUserId();
        } else {
            throw new Exception("User creation failed. Please try again.");
        }
    } catch (Exception e) {
        logger.error("Error while creating user profile", e);
        UserProfileServiceException exception = new UserProfileServiceException();
        exception.setMessage("Error while creating user profile. More info : " + e.getMessage());
        throw exception;
    }
}
Also used : UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) TException(org.apache.thrift.TException) AuthorizationException(org.apache.airavata.model.error.AuthorizationException) ApplicationSettingsException(org.apache.airavata.common.exception.ApplicationSettingsException) IamAdminServicesException(org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException) UserProfileServiceException(org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException) SecurityCheck(org.apache.airavata.service.security.interceptor.SecurityCheck)

Aggregations

ApplicationSettingsException (org.apache.airavata.common.exception.ApplicationSettingsException)8 AuthorizationException (org.apache.airavata.model.error.AuthorizationException)8 SecurityCheck (org.apache.airavata.service.security.interceptor.SecurityCheck)7 TException (org.apache.thrift.TException)7 CredentialStoreException (org.apache.airavata.credential.store.exception.CredentialStoreException)4 IamAdminServicesException (org.apache.airavata.service.profile.iam.admin.services.cpi.exception.IamAdminServicesException)4 TenantProfileServiceException (org.apache.airavata.service.profile.tenant.cpi.exception.TenantProfileServiceException)3 UserProfileServiceException (org.apache.airavata.service.profile.user.cpi.exception.UserProfileServiceException)3 Gateway (org.apache.airavata.model.workspace.Gateway)2 PasswordCredential (org.apache.airavata.model.credential.store.PasswordCredential)1 UserProfile (org.apache.airavata.model.user.UserProfile)1 RegistryServiceException (org.apache.airavata.registry.api.exception.RegistryServiceException)1 AiravataSecurityException (org.apache.airavata.security.AiravataSecurityException)1 TenantManagementKeycloakImpl (org.apache.airavata.service.profile.iam.admin.services.core.impl.TenantManagementKeycloakImpl)1 AiravataSecurityManager (org.apache.airavata.service.security.AiravataSecurityManager)1