public bool IsAuthorized(UserContext userContext, Uri resourceUri) { SenderInfo senderInfo = new SenderInfo(userContext.GetIdentity(), userContext.ClientCertificate, resourceUri); CustomAuthorizationHandler.CustomContext customContext = null; TraceHelper.Current.MethodCall0("CustomAuthorizationHandler", "IsAuthorized"); try { using (OperationTracerWithTimeout operationTracerWithTimeout = new OperationTracerWithTimeout(new Action <string>(TraceHelper.Current.CustomAuthzCallStart), new Action <string>(TraceHelper.Current.CustomAuthzCallEnd), "AuthorizeUser", new Action <string>(TraceHelper.Current.CustomAuthzExceedTimeLimit), 30)) { UserQuota userQuotum = null; WindowsIdentity windowsIdentity = this.customAuthorization.AuthorizeUser(senderInfo, out userQuotum); if (windowsIdentity != null) { if (userQuotum != null) { TraceHelper.Current.UserQuotaInformation(userContext.Name, userQuotum.MaxConcurrentRequests, userQuotum.MaxRequestsPerTimeSlot, userQuotum.TimeSlotSize); customContext = new CustomAuthorizationHandler.CustomContext(windowsIdentity, userQuotum); } else { object[] nullQuota = new object[2]; nullQuota[0] = "CustomAuthorization.AuthorizeUser"; nullQuota[1] = Resources.NullQuota; throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, nullQuota)); } } else { object[] nullWindowsIdentity = new object[2]; nullWindowsIdentity[0] = "CustomAuthorization.AuthorizeUser"; nullWindowsIdentity[1] = Resources.NullWindowsIdentity; throw new InvalidOperationException(ExceptionHelpers.GetExceptionMessage(Resources.MethodReturnedInvalidOutput, nullWindowsIdentity)); } } } catch (Exception exception1) { Exception exception = exception1; if (!exception.IsSevereException()) { exception.Trace(null); } else { throw; } } this.customContextStore.StoreContext(customContext); if (customContext == null || customContext.Identity == null) { TraceHelper.Current.AuthorizeUserRequestFailed(userContext.Name, userContext.AuthenticationType); return(false); } else { TraceHelper.Current.AuthorizeUserRequestSucceeded(userContext.Name); return(true); } }
public SafeRefCountedContainer <WindowsIdentity> GetAuthorizedUserIdentity(UserContext userContext) { CustomAuthorizationHandler.CustomContext context = this.customContextStore.GetContext(); if (context == null || context.Identity == null) { throw new UnauthorizedAccessException(userContext.Name, userContext.AuthenticationType, userContext.IsAuthenticated); } else { return(context.Identity); } }
public void StoreContext(CustomAuthorizationHandler.CustomContext customContext) { if (customContext != null && customContext.Identity != null) { CustomAuthorizationHandler.CustomContext customContext1 = OperationContext.Current.Extensions.Find <CustomAuthorizationHandler.CustomContext>(); if (customContext1 != null) { OperationContext.Current.Extensions.Remove(customContext1); } OperationContext.Current.Extensions.Add(customContext); } }
public CustomAuthorizationHandler.CustomContext GetContext() { /* TODO: REVIEW */ var customContext = OperationContext.Current.Extensions.Find <CustomAuthorizationHandler.CustomContext> (); if (customContext == null) { customContext = new CustomAuthorizationHandler.CustomContext(System.Security.Principal.WindowsIdentity.GetCurrent(), new UserQuota(100, 100, 1000)); OperationContext.Current.Extensions.Add(customContext); } return(customContext); }
public bool IsRequestProcessingStarted(UserContext userContext) { CustomAuthorizationHandler.CustomContext context = this.customContextStore.GetContext(); if (context == null || context.Identity == null) { throw new UnauthorizedAccessException(userContext.Name, userContext.AuthenticationType, userContext.IsAuthenticated); } else { return(context.IsRequestProcessingStarted); } }
public UserQuota GetUserQuota(UserContext userContext) { CustomAuthorizationHandler.CustomContext context = this.customContextStore.GetContext(); if (context == null || context.Identity == null) { throw new UnauthorizedAccessException(userContext.Name, userContext.AuthenticationType, userContext.IsAuthenticated); } else { return(context.UserQuota); } }
public int IncrementCmdletExecutionCount(UserContext userContext) { CustomAuthorizationHandler.CustomContext context = this.customContextStore.GetContext(); if (context == null || context.Identity == null) { throw new UnauthorizedAccessException(userContext.Name, userContext.AuthenticationType, userContext.IsAuthenticated); } else { CustomAuthorizationHandler.CustomContext customContext = context; int cmdletsExecuted = customContext.CmdletsExecuted + 1; int num = cmdletsExecuted; customContext.CmdletsExecuted = cmdletsExecuted; return(num); } }