Esempio n. 1
0
        /// <summary>
        /// Check whether the user has any of the allowed roles to access given functionality.
        /// </summary>
        /// <param name="user">User account with roles.</param>
        /// <param name="requiredRole">Required user role.</param>
        /// <exception cref="InsufficientRoleException">is thrown when the user doesn't have any role specified by <see cref="allowedRoles"/></exception>
        internal static void CheckUserRole(AdaptorUser user, UserRoleType requiredUserRole)
        {
            bool hasRequiredRole = user.Roles.Any(userRole => (UserRoleType)userRole.Id == requiredUserRole);

            if (!hasRequiredRole)
            {
                using var unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork();
                var requiredRoleModel = unitOfWork.AdaptorUserRoleRepository.GetById((long)requiredUserRole);
                throw InsufficientRoleException.CreateMissingRoleException(requiredRoleModel, user.Roles);
            }
        }
Esempio n. 2
0
        public async Task <string> AuthenticateUserAsync(AuthenticationCredentialsExt credentials)
        {
            try
            {
                AuthenticationCredentials credentialsIn;
                if (credentials is PasswordCredentialsExt)
                {
                    credentialsIn = new PasswordCredentials
                    {
                        Username = credentials.Username,
                        Password = ((PasswordCredentialsExt)credentials).Password
                    };
                }
                else if (credentials is DigitalSignatureCredentialsExt)
                {
                    credentialsIn = new DigitalSignatureCredentials
                    {
                        Username         = credentials.Username,
                        DigitalSignature = Array.ConvertAll(((DigitalSignatureCredentialsExt)credentials).DigitalSignature, b => unchecked ((byte)b)),
                        SignedContent    = CombineContentWithSalt(credentials.Username)
                    };
                }
                else if (credentials is OpenIdCredentialsExt openIdCredentials)
                {
                    //Username is extracted from the access_token later.
                    credentialsIn = new OpenIdCredentials
                    {
                        OpenIdAccessToken = openIdCredentials.OpenIdAccessToken,
                    };
                }
                else
                {
                    log.Error("Credentials of class " + credentials.GetType().Name +
                              " are not supported. Change the HaaSMiddleware.ServiceTier.UserAndLimitationManagement.UserAndLimitationManagementService.AuthenticateUser() method to add support for additional credential types.");
                    throw new ArgumentException("Credentials of class " + credentials.GetType().Name +
                                                " are not supported. Change the HaaSMiddleware.ServiceTier.UserAndLimitationManagement.UserAndLimitationManagementService.AuthenticateUser() method to add support for additional credential types.");
                }

                using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
                {
                    IUserAndLimitationManagementLogic userLogic =
                        LogicFactory.GetLogicFactory().CreateUserAndLimitationManagementLogic(unitOfWork);
                    var result = await userLogic.AuthenticateUserAsync(credentialsIn);

                    return(result);
                }
            }
            catch (Exception exc)
            {
                ExceptionHandler.ThrowProperExternalException(exc);
                return(null);
            }
        }
 public void EndFileTransfer(long submittedJobInfoId, FileTransferMethodExt usedTransferMethod, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser        loggedUser        = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IFileTransferLogic fileTransferLogic = LogicFactory.GetLogicFactory().CreateFileTransferLogic(unitOfWork);
             fileTransferLogic.EndFileTransfer(submittedJobInfoId, FileTransferConverts.ConvertFileTransferMethodExtToIn(usedTransferMethod), loggedUser);
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
     }
 }
Esempio n. 4
0
 public DataTransferMethodExt GetDataTransferMethod(string nodeIPAddress, int nodePort, long submittedTaskInfoId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser        loggedUser         = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IDataTransferLogic dataTransferLogic  = LogicFactory.GetLogicFactory().CreateDataTransferLogic(unitOfWork);
             DataTransferMethod dataTransferMethod = dataTransferLogic.GetDataTransferMethod(nodeIPAddress, nodePort, submittedTaskInfoId, loggedUser);
             return(dataTransferMethod.ConvertIntToExt());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(default);
Esempio n. 5
0
 public void DeleteJob(long submittedJobInfoId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser         loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IJobManagementLogic jobLogic   = LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork);
             jobLogic.DeleteJob(submittedJobInfoId, loggedUser);
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
     }
 }
 public byte[] DownloadFileFromCluster(long submittedJobInfoId, string relativeFilePath, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser        loggedUser        = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IFileTransferLogic fileTransferLogic = LogicFactory.GetLogicFactory().CreateFileTransferLogic(unitOfWork);
             return(fileTransferLogic.DownloadFileFromCluster(submittedJobInfoId, relativeFilePath, loggedUser));
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
 public IEnumerable <AdaptorUserGroupExt> ListAdaptorUserGroups(string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser        loggedUser        = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Maintainer);
             IJobReportingLogic jobReportingLogic = LogicFactory.GetLogicFactory().CreateJobReportingLogic(unitOfWork);
             return(jobReportingLogic.ListAdaptorUserGroups().Select(s => s.ConvertIntToExt()));
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
 public ClusterExt[] ListAvailableClusters()
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             IClusterInformationLogic clusterLogic = LogicFactory.GetLogicFactory().CreateClusterInformationLogic(unitOfWork);
             IList <Cluster>          clusters     = clusterLogic.ListAvailableClusters();
             return(clusters.Select(s => s.ConvertIntToExt()).ToArray());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
 public SubmittedJobInfoUsageReportExt GetResourceUsageReportForJob(long jobId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser        loggedUser        = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Reporter);
             IJobReportingLogic jobReportingLogic = LogicFactory.GetLogicFactory().CreateJobReportingLogic(unitOfWork);
             return(jobReportingLogic.GetResourceUsageReportForJob(jobId).ConvertIntToExt());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 10
0
 public FileTransferMethodExt GetFileTransferMethod(long submittedJobInfoId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser        loggedUser         = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IFileTransferLogic fileTransferLogic  = LogicFactory.GetLogicFactory().CreateFileTransferLogic(unitOfWork);
             FileTransferMethod fileTransferMethod = fileTransferLogic.GetFileTransferMethod(submittedJobInfoId, loggedUser);
             return(fileTransferMethod.ConvertIntToExt());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 11
0
 public FileInformationExt[] ListChangedFilesForJob(long submittedJobInfoId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser                   loggedUser        = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IFileTransferLogic            fileTransferLogic = LogicFactory.GetLogicFactory().CreateFileTransferLogic(unitOfWork);
             ICollection <FileInformation> result            = fileTransferLogic.ListChangedFilesForJob(submittedJobInfoId, loggedUser);
             return(result?.Select(s => s.ConvertIntToExt()).ToArray());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 12
0
 public string RemoveCommandTemplate(long commandTemplateId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser      loggedUser      = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Administrator);
             IManagementLogic managementLogic = LogicFactory.GetLogicFactory().CreateManagementLogic(unitOfWork);
             managementLogic.RemoveCommandTemplate(commandTemplateId);
             return($"CommandTemplate with id {commandTemplateId} has been removed.");
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 13
0
 public SubmittedJobInfoExt[] ListJobsForCurrentUser(string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser         loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IJobManagementLogic jobLogic   = LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork);
             var jobInfos = jobLogic.GetJobsForUser(loggedUser);
             return(jobInfos.Select(s => s.ConvertIntToExt()).ToArray());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 14
0
 public SubmittedJobInfoExt SubmitJob(long createdJobInfoId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser         loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IJobManagementLogic jobLogic   = LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork);
             SubmittedJobInfo    jobInfo    = jobLogic.SubmitJob(createdJobInfoId, loggedUser);
             return(jobInfo.ConvertIntToExt());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 15
0
 public IEnumerable <string> GetAllocatedNodesIPs(long submittedTaskInfoId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser         loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IJobManagementLogic jobLogic   = LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork);
             var nodesIPs = jobLogic.GetAllocatedNodesIPs(submittedTaskInfoId, loggedUser);
             return(nodesIPs.ToArray());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
 public ClusterNodeUsageExt GetCurrentClusterNodeUsage(long clusterNodeId, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Reporter);
             IClusterInformationLogic clusterLogic = LogicFactory.GetLogicFactory().CreateClusterInformationLogic(unitOfWork);
             ClusterNodeUsage         nodeUsage    = clusterLogic.GetCurrentClusterNodeUsage(clusterNodeId, loggedUser);
             return(nodeUsage.ConvertIntToExt());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 17
0
 public SubmittedJobInfoExt CreateJob(JobSpecificationExt specification, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser         loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IJobManagementLogic jobLogic   = LogicFactory.GetLogicFactory().CreateJobManagementLogic(unitOfWork);
             JobSpecification    js         = specification.ConvertExtToInt();
             SubmittedJobInfo    jobInfo    = jobLogic.CreateJob(js, loggedUser, specification.IsExtraLong.Value);
             return(jobInfo.ConvertIntToExt());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 18
0
 public ResourceUsageExt[] GetCurrentUsageAndLimitationsForCurrentUser(string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser loggedUser = GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Reporter);
             IUserAndLimitationManagementLogic userLogic =
                 LogicFactory.GetLogicFactory().CreateUserAndLimitationManagementLogic(unitOfWork);
             IList <ResourceUsage> usages = userLogic.GetCurrentUsageAndLimitationsForUser(loggedUser);
             return((from usage in usages select usage.ConvertIntToExt()).ToArray());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 19
0
        public async Task <OpenStackApplicationCredentialsExt> AuthenticateUserToOpenStackAsync(AuthenticationCredentialsExt credentials)
        {
            if (credentials is OpenIdCredentialsExt openIdCredentials)
            {
                using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
                {
                    var userLogic = LogicFactory.GetLogicFactory().CreateUserAndLimitationManagementLogic(unitOfWork);
                    var appCreds  = await userLogic.AuthenticateUserToOpenStackAsync(new OpenIdCredentials
                    {
                        OpenIdAccessToken = openIdCredentials.OpenIdAccessToken
                    });

                    return(appCreds.ConvertIntToExt());
                }
            }

            string errorMessage = $"Credentials of type {credentials.GetType().Name} are not supported for OpenStack authentication.";

            log.Error(errorMessage);
            throw new ArgumentException(errorMessage);
        }
Esempio n. 20
0
 public JobFileContentExt[] DownloadPartsOfJobFilesFromCluster(long submittedJobInfoId, TaskFileOffsetExt[] taskFileOffsets, string sessionCode)
 {
     try
     {
         using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
         {
             AdaptorUser            loggedUser          = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
             IFileTransferLogic     fileTransferLogic   = LogicFactory.GetLogicFactory().CreateFileTransferLogic(unitOfWork);
             IList <JobFileContent> downloadedFileParts = fileTransferLogic.DownloadPartsOfJobFilesFromCluster(
                 submittedJobInfoId,
                 (from taskFileOffset in (new List <TaskFileOffsetExt>(taskFileOffsets).ToList()) select FileTransferConverts.ConvertTaskFileOffsetExtToIn(taskFileOffset)).ToArray(),
                 loggedUser);
             return((from fileContent in downloadedFileParts select FileTransferConverts.ConvertJobFileContentToExt(fileContent)).ToArray());
         }
     }
     catch (Exception exc)
     {
         ExceptionHandler.ThrowProperExternalException(exc);
         return(null);
     }
 }
Esempio n. 21
0
        public UserResourceUsageReportExt GetUserResourceUsageReport(long userId, DateTime startTime, DateTime endTime, string sessionCode)
        {
            try
            {
                using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
                {
                    AdaptorUser loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
                    if (loggedUser.Id != userId)
                    {
                        throw new NotAllowedException("Logged user is not allowed to request this report.");
                    }

                    IJobReportingLogic jobReportingLogic = LogicFactory.GetLogicFactory().CreateJobReportingLogic(unitOfWork);
                    return(jobReportingLogic.GetUserResourceUsageReport(userId, startTime, endTime).ConvertIntToExt());
                }
            }
            catch (Exception exc)
            {
                ExceptionHandler.ThrowProperExternalException(exc);
                return(null);
            }
        }
Esempio n. 22
0
        public CommandTemplateExt ModifyCommandTemplate(long commandTemplateId, string name, string description, string code, string executableFile, string preparationScript, string sessionCode)
        {
            try
            {
                using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
                {
                    AdaptorUser      loggedUser      = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Administrator);
                    IManagementLogic managementLogic = LogicFactory.GetLogicFactory().CreateManagementLogic(unitOfWork);
                    CommandTemplate  commandTemplate = managementLogic.ModifyCommandTemplate(commandTemplateId, name, description, code, executableFile, preparationScript);
                    return(commandTemplate.ConvertIntToExt());
                }
            }
            catch (Exception exc)
            {
                if (exc.Message.Contains("No such file or directory"))
                {
                    ExceptionHandler.ThrowProperExternalException(new InputValidationException(exc.Message));
                }

                ExceptionHandler.ThrowProperExternalException(exc);
                return(null);
            }
        }
        public IEnumerable <string> GetCommandTemplateParametersName(long commandTemplateId, string userScriptPath, string sessionCode)
        {
            try
            {
                using (IUnitOfWork unitOfWork = UnitOfWorkFactory.GetUnitOfWorkFactory().CreateUnitOfWork())
                {
                    AdaptorUser loggedUser = UserAndLimitationManagementService.GetValidatedUserForSessionCode(sessionCode, unitOfWork, UserRoleType.Submitter);
                    IClusterInformationLogic clusterLogic = LogicFactory.GetLogicFactory().CreateClusterInformationLogic(unitOfWork);
                    return(clusterLogic.GetCommandTemplateParametersName(commandTemplateId, userScriptPath, loggedUser));
                }
            }

            catch (Exception exc)
            {
                //TODO Should be rewrite!
                if (exc.Message.Contains("No such file or directory") || exc.Message.Contains("Is a directory"))
                {
                    ExceptionHandler.ThrowProperExternalException(new InputValidationException(exc.Message));
                }

                ExceptionHandler.ThrowProperExternalException(exc);
                return(null);
            }
        }