Beispiel #1
0
        /// <summary>
        /// Gets the device service client.
        /// </summary>
        /// <returns>Returns an AMI service client instance or null.</returns>
        protected AmiServiceClient GetDeviceServiceClient()
        {
            var deviceIdentity = ApplicationSignInManager.LoginAsDevice();

            if (deviceIdentity == null)
            {
                return(null);
            }

            this.Request.Cookies.Set(new HttpCookie("access_token", deviceIdentity.AccessToken));

            var restClientService = new RestClientService(Constants.Ami)
            {
                Credentials = new AmiCredentials(new GenericPrincipal(deviceIdentity, null), this.Request)
            };

            return(new AmiServiceClient(restClientService));
        }
Beispiel #2
0
        /// <summary>
        /// Handles the EndRequest event of the Application control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param>
        protected void Application_EndRequest(object sender, EventArgs e)
        {
            try
            {
                if (!RealmConfig.IsJoinedToRealm())
                {
                    return;
                }

                // if the response status code is not a client level error code, we don't want to attempt to audit the access
                if (this.Response.StatusCode != 401 && this.Response.StatusCode != 403 && this.Response.StatusCode != 404)
                {
                    return;
                }

                var deviceIdentity = ApplicationSignInManager.LoginAsDevice();

                //var auditHelper = new GlobalAuditHelper(new AmiCredentials(this.User, deviceIdentity.AccessToken), this.Context);

                //switch (this.Response.StatusCode)
                //{
                //	case 401:
                //		if (this.Request.Headers["Authorization"] != null)
                //			auditHelper.AuditUnauthorizedAccess();
                //		break;
                //	case 403:
                //		auditHelper.AuditForbiddenAccess();
                //		break;
                //	case 404:
                //		auditHelper.AuditResourceNotFoundAccess();
                //		break;
                //}
            }
            catch (Exception exception)
            {
                Trace.TraceError($"Unable to audit application end request: {exception}");
            }
        }