IsInRole


Description

Verifies whether a member has been assigned a specified role within a security context.

Parameters

Parameter

Type

Description

member

string

The member’s logon name. The property should be set to the logon name in the form: DOMAIN\USERNAME.

roleKey

RoleKey

The role key object that specifies the role being verified.

context

SecurityContext

A security context object that specifies the application and scope properties of the request.


Return Value:

Value

Type

Description

IsInRoleResult

boolean

Specifies whether the member is in the requested role. True indicates the member is in the role for the specified context. False indicates the user in not in the role.


Examples

The following C# example determines whether a member has a specific role within a security context. The example’s security context uses the Microsoft Dynamics GP web service application and the sample company. The member is identified by the logon name “DOMAIN\\username“. A message box displays whether or not the member has the specified role.

using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;
using DynamicsSecurityServiceSample.DynamicsSecurityWebService;

namespace DynamicsSecurityServiceSample
{
	class Program
	{
		static void Main(string[] args)
		{
			ApplicationKey applicationKey;
			ScopeKey scopeKey;
			SecurityContext securityContext;
			RoleKey roleKey;
			bool inRole;

			// Create an instance of the security service
			DynamicsSecurityService wsDynamicsSecurity = new DynamicsSecurityService();

			// Use default credentials
			wsDynamicsSecurity.UseDefaultCredentials = true;

			// Create a security context object
			securityContext = new SecurityContext();

			// Create the application key and add it to the security context object
			// Use the ID of the Dynamics GP web service application
			applicationKey = new ApplicationKey();
			applicationKey.Id = "25cc1a21-2cc4-4b13-a1c8-eea186fb688a";
			securityContext.ApplicationKey = applicationKey;

			// Create the scope key and add it to the security context object
			// Use the Id of the sample company
			scopeKey = new ScopeKey();
			scopeKey.Id = "-1";
			securityContext.ScopeKey = scopeKey;

			// Create a role key object to specify the role
			roleKey = new RoleKey();
			roleKey.Id = "e18b321a-9548-48fb-b75a-dee0a618ddaa";

			// Determine whether or not the user is in the specified role
			inRole = wsDynamicsSecurity.IsInRole("DOMAIN\\username", roleKey, securityContext);

			// Display a message indicating whether the member is assigned the specified role
			if (inRole == true)
			{
				MessageBox.Show("Member has been assigned to the role");
		}
			else
			{
				MessageBox.Show("Member has not been assigned to the role");
		}
	}
}
}

 


Documentation Feedback