public SsoAuthorizationDTO GetApplicationAuthorizations(ApplicationFilterDTO filter) { var authorization = new SsoAuthorizationDTO(); try { if (string.IsNullOrEmpty(filter.ApplicationCode)) { throw new ServiceException(CommonExceptionType.ParameterException, "ApplicationCode"); } //Get application and its profiles var ssoApp = GetSsoApplication(filter); if (ssoApp != default(SsoApplication)) { authorization.Claims = ssoApp.GetClaims(); authorization.IsValid = (authorization.Claims.Count > 0); } } catch (Exception ex) { LogHelper.ExceptionAndThrow(ex); } return(authorization); }
public SsoAuthorizationDTO ValidateAndGetUserAuthorizations(SsoAuthenticationDTO sso) { var authorization = new SsoAuthorizationDTO { IsValid = false }; try { if (string.IsNullOrEmpty(sso.EncriptedAppCode) || string.IsNullOrEmpty(sso.EncriptedLogin)) { throw new ServiceException(CommonExceptionType.ParameterException, "EncriptedAppCode and EncriptedLogin"); } var appCode = CryptographHelper.RijndaelDecrypt(sso.EncriptedAppCode, CommonConsts.CommonPassword); var login = CryptographHelper.RijndaelDecrypt(sso.EncriptedLogin, CommonConsts.CommonPassword); var userFilter = new UserFilterDTO { Login = login, LoadProfiles = true }; //Get user data var worker = GetWorker(userFilter); //Validates user password if its a SSO user worker.ValidateUserCredential(sso.EncriptedPassword); //Get worker related apps filtered by AppCode worker.Applications = GetUserApplications(userFilter, new ApplicationFilterDTO { ApplicationCode = appCode, LoadTranslations = true, LanguageCultureName = sso.LanguageCultureName }); //Transforms user permissions to claims identity authorization.Claims = worker.GetClaims(); authorization.IsValid = (!worker.Validation.HasErrors && authorization.Claims.Count > 0); } catch (ServiceException ex) { //Suppress validations exceptions and returns an empty authorization } catch (Exception ex) { LogHelper.ExceptionAndThrow(ex); } return(authorization); }