Exemplo n.º 1
0
        public CheckAuthorizationResponse CheckAuthorization(CheckAuthorizationRequest request)
        {
            BusinessEntities.CheckAuthorizationParameters p = CheckAuthorizationTranslator.TranslateFromServiceToBusiness(request.CheckAuthorizationParameters);

            IClaimsIdentity claimsIdentity = Thread.CurrentPrincipal.Identity as IClaimsIdentity;

            p.Roles = (from c in claimsIdentity.Claims.FindAll(c => { return(c.ClaimType == ClaimTypes.GroupSid); })
                       select c.Value).ToList();

            p.Roles.Add(claimsIdentity.Claims.FindAll(c => { return(c.ClaimType == ClaimTypes.Sid); }).First().Value);

            BusinessEntities.CheckAuthorizationResult businessResult = _checkAuthorizationAction.Execute(p);

            CheckAuthorizationResponse response = new CheckAuthorizationResponse();

            response.CheckAuthorizationResult = CheckAuthorizationTranslator.TranslateFromBusinessToService(businessResult);

            return(response);
        }
        public static Business.CheckAuthorizationParameters TranslateFromServiceToBusiness(Service.CheckAuthorizationParameters serviceEntity)
        {
            Business.CheckAuthorizationParameters parameters = new Business.CheckAuthorizationParameters();

            parameters.Operations            = new List <Business.AuthOperation>();
            parameters.AuthorizationProvider = serviceEntity.AuthorizationProvider;

            foreach (Service.AuthOperation serviceOperation in serviceEntity.Operations)
            {
                Business.AuthOperation businnessOperation = new Business.AuthOperation()
                {
                    Operation    = serviceOperation.Operation,
                    IsAuthorized = serviceOperation.IsAuthorized
                };

                parameters.Operations.Add(businnessOperation);
            }

            return(parameters);
        }