public override bool CheckAccess(OperationContext operationContext, ref Message message) { base.CheckAccess(operationContext, ref message); string action = operationContext.IncomingMessageHeaders.Action; if (action == "urn:msdnmag/IService/GetRoles") { // messags in WCF are always read-once // we create one copy to work with, and one copy to return back to the plumbing MessageBuffer buffer = operationContext.RequestContext.RequestMessage.CreateBufferedCopy(int.MaxValue); message = buffer.CreateMessage(); // get the username vale using XPath XPathNavigator nav = buffer.CreateNavigator(); StandardNamespaceManager nsm = new StandardNamespaceManager(nav.NameTable); nsm.AddNamespace("msdn", "urn:msdnmag"); XPathNavigator node = nav.SelectSingleNode("s:Envelope/s:Body/msdn:GetRoles/msdn:username", nsm); string parameter = node.InnerXml; // check authorization if (operationContext.ServiceSecurityContext.PrimaryIdentity.Name == parameter) { return(true); } else { return(GetPrincipal(operationContext).IsInRole("administrators")); } } return(true); }
public override bool CheckAccess(OperationContext operationContext, ref Message message) { base.CheckAccess(operationContext, ref message); string action = operationContext.IncomingMessageHeaders.Action; if (action == "urn:msdnmag/IService/GetRoles") { // messags in WCF are always read-once // we create one copy to work with, and one copy to return back to the plumbing MessageBuffer buffer = operationContext.RequestContext.RequestMessage.CreateBufferedCopy(int.MaxValue); message = buffer.CreateMessage(); // get the username vale using XPath XPathNavigator nav = buffer.CreateNavigator(); StandardNamespaceManager nsm = new StandardNamespaceManager(nav.NameTable); nsm.AddNamespace("msdn", "urn:msdnmag"); XPathNavigator node = nav.SelectSingleNode("s:Envelope/s:Body/msdn:GetRoles/msdn:username", nsm); string parameter = node.InnerXml; // check authorization if (operationContext.ServiceSecurityContext.PrimaryIdentity.Name == parameter) { return true; } else { return (GetPrincipal(operationContext).IsInRole("administrators")); } } return true; }