public async Task<IHttpActionResult> AssignUserToGroupAsync(string userId,string userName ,string groupId,string groupName)
 {
     var operation = new TableDal(ConfigurationManager.AppSettings["storageConnection"], TableNames.UserGroupAssignments);
     var ugae = new UserGroupAssignmentsEntity(userId, groupId);
     ugae.UserPrincipleName = userName;
     ugae.GroupName = groupName;
     ugae.UpdatedBy = "*****@*****.**";
     var result = operation.InsertEntity(ugae);
     var resultUser = operation.RetrieveUserByUserId(userId);
     return CreateSuccessResult(resultUser);
 }
예제 #2
0
        public static void TestItaLite()
        {
            TableDal userGroupAssignmentOperation = new TableDal(ConfigurationSettings.AppSettings["storageConnection"], TableNames.UserGroupAssignments);
            TableDal appGroupAssignmentOperation = new TableDal(ConfigurationSettings.AppSettings["storageConnection"], TableNames.AppGroupAssignments);

            var userGroupAssignment = new UserGroupAssignmentsEntity("8734cc8a-2e67-4a9f-b1aa-3306a5e62760", "f8541113-c54b-4eab-af59-77b0eeef3617");
            userGroupAssignment.UserPrincipleName = "*****@*****.**";
            userGroupAssignment.GroupName = "MyGroup";
            userGroupAssignment.UpdatedBy = "*****@*****.**";
            userGroupAssignmentOperation.InsertEntity(userGroupAssignment);

            var appGroupAssignment = new AppGroupAssignmentEntity("1a7249e7-fa56-4c47-83de-5048097bc510", "f8541113-c54b-4eab-af59-77b0eeef3617");
            appGroupAssignment.AppName = "Console App for Azure AD";
            appGroupAssignment.GroupName = "MyGroup";
            appGroupAssignment.UpdatedBy = "*****@*****.**";
            appGroupAssignment.OperationTypes = OperationTypes.Read.ToString();
            appGroupAssignmentOperation.InsertEntity(appGroupAssignment);

            InvokingITA testITACore = new InvokingITA();
            // true
            Console.WriteLine(testITACore.AccessControl(new List<UserGroupAssignmentsEntity>() { userGroupAssignment }, new List<AppGroupAssignmentEntity>() { appGroupAssignment }, "8734cc8a-2e67-4a9f-b1aa-3306a5e62760", "1a7249e7-fa56-4c47-83de-5048097bc510"));
            // false
            Console.WriteLine(testITACore.AccessControl(new List<UserGroupAssignmentsEntity>() { userGroupAssignment }, new List<AppGroupAssignmentEntity>() { appGroupAssignment }, "8734cc8a-2e67-4a9f-b1aa-3306a5e62760_", "1a7249e7-fa56-4c47-83de-5048097bc510"));
            // false
            Console.WriteLine(testITACore.AccessControl(new List<UserGroupAssignmentsEntity>() { userGroupAssignment }, new List<AppGroupAssignmentEntity>() { appGroupAssignment }, "8734cc8a-2e67-4a9f-b1aa-3306a5e62760", "1a7249e7-fa56-4c47-83de-5048097bc510_"));


            var userGroupAssignment2 = new UserGroupAssignmentsEntity("8734cc8a-2e67-4a9f-b1aa-3306a5e62760_", "f8541113-c54b-4eab-af59-77b0eeef3617");
            userGroupAssignment2.UserPrincipleName = "*****@*****.**";
            userGroupAssignment2.GroupName = "MyGroup";
            userGroupAssignment2.UpdatedBy = "*****@*****.**";
            userGroupAssignmentOperation.InsertEntity(userGroupAssignment2);

            // true
            Console.WriteLine(testITACore.AccessControl(new List<UserGroupAssignmentsEntity>() { userGroupAssignment, userGroupAssignment2 }, new List<AppGroupAssignmentEntity>() { appGroupAssignment }, "8734cc8a-2e67-4a9f-b1aa-3306a5e62760_", "1a7249e7-fa56-4c47-83de-5048097bc510"));

            var appGroupAssignment2 = new AppGroupAssignmentEntity("1a7249e7-fa56-4c47-83de-5048097bc510_", "f8541113-c54b-4eab-af59-77b0eeef3617_");
            appGroupAssignment2.AppName = "Console App for Azure AD_";
            appGroupAssignment2.GroupName = "MyGroup";
            appGroupAssignment2.UpdatedBy = "*****@*****.**";
            appGroupAssignment2.OperationTypes = OperationTypes.Read.ToString();
            appGroupAssignmentOperation.InsertEntity(appGroupAssignment2);

            var userGroupAssignment31 = new UserGroupAssignmentsEntity("8734cc8a-2e67-4a9f-b1aa-3306a5e62760", "f8541113-c54b-4eab-af59-77b0eeef3617_");
            userGroupAssignment2.UserPrincipleName = "*****@*****.**";
            userGroupAssignment2.GroupName = "MyGroup";
            userGroupAssignment2.UpdatedBy = "*****@*****.**";
            userGroupAssignmentOperation.InsertEntity(userGroupAssignment2);

            var userGroupAssignment32 = new UserGroupAssignmentsEntity("8734cc8a-2e67-4a9f-b1aa-3306a5e62760_", "f8541113-c54b-4eab-af59-77b0eeef3617_");
            userGroupAssignment2.UserPrincipleName = "*****@*****.**";
            userGroupAssignment2.GroupName = "MyGroup";
            userGroupAssignment2.UpdatedBy = "*****@*****.**";
            userGroupAssignmentOperation.InsertEntity(userGroupAssignment2);

            // true
            Console.WriteLine(testITACore.AccessControl(new List<UserGroupAssignmentsEntity>() { userGroupAssignment, userGroupAssignment2, userGroupAssignment31 }, new List<AppGroupAssignmentEntity>() { appGroupAssignment, appGroupAssignment2 }, "8734cc8a-2e67-4a9f-b1aa-3306a5e62760", "1a7249e7-fa56-4c47-83de-5048097bc510_"));

            // true
            Console.WriteLine(testITACore.AccessControl(new List<UserGroupAssignmentsEntity>() { userGroupAssignment, userGroupAssignment2, userGroupAssignment32 }, new List<AppGroupAssignmentEntity>() { appGroupAssignment, appGroupAssignment2 }, "8734cc8a-2e67-4a9f-b1aa-3306a5e62760_", "1a7249e7-fa56-4c47-83de-5048097bc510_"));

        }
예제 #3
0
        static void ParseUserMembership()
        {
            Console.WriteLine("Start to sync AAD memberships ...");
            foreach (IUser retrievedUser in AllUsers)
            {

                IUserFetcher retrievedUserFetcher = (User)retrievedUser;
                try
                {
                    IPagedCollection<IDirectoryObject> pagedCollection = retrievedUserFetcher.MemberOf.ExecuteAsync().Result;
                    do
                    {
                        //Console.WriteLine("\n {0} is a member of the following Group and Roles (IDs)", retrievedUser.DisplayName);
                        List<IDirectoryObject> directoryObjects = pagedCollection.CurrentPage.ToList();
                        foreach (IDirectoryObject directoryObject in directoryObjects)
                        {
                            if (directoryObject is Group)
                            {
                                Group group = directoryObject as Group;
                                var userGroupAssignment = new UserGroupAssignmentsEntity(retrievedUser.ObjectId, group.ObjectId);
                                userGroupAssignment.UserPrincipleName = retrievedUser.UserPrincipalName;
                                userGroupAssignment.GroupName = group.DisplayName;
                                userGroupAssignmentOperation.InsertEntity(userGroupAssignment);

                            }
                            if (directoryObject is DirectoryRole)
                            {
                                DirectoryRole role = directoryObject as DirectoryRole;
                                var userAdminRoleAssignment = new UserAdminRoleAssignmentEntity(retrievedUser.ObjectId, role.ObjectId);
                                userAdminRoleAssignment.UserPrincipleName = retrievedUser.UserPrincipalName;
                                userAdminRoleAssignment.AdminRoleName = role.DisplayName;
                                userAdminRoleAssignmentOper.InsertEntity(userAdminRoleAssignment);
                            }
                        }
                        pagedCollection = pagedCollection.GetNextPageAsync().Result;
                    } while (pagedCollection != null);
                }
                catch (Exception e)
                {
                    Console.WriteLine("\nError getting user's groups and roles memberships. {0} {1}", e.Message, e.InnerException != null ? e.InnerException.Message : "");
                }
            }
        }
예제 #4
0
        public static void PortalSimulator()
        {
            Console.WriteLine("Start to insert simulation data ?");
            if (Console.ReadLine()=="yes")
            {
            var userGroupAssignment = new UserGroupAssignmentsEntity("8734cc8a-2e67-4a9f-b1aa-3306a5e62760", "f8541113-c54b-4eab-af59-77b0eeef3617");
                userGroupAssignment.UserPrincipleName = "*****@*****.**";
            userGroupAssignment.GroupName = "MyGroup";
            userGroupAssignment.UpdatedBy = "*****@*****.**";
            userGroupAssignmentOperation.InsertEntity(userGroupAssignment);

            var appGroupAssignment = new AppGroupAssignmentEntity("1a7249e7-fa56-4c47-83de-5048097bc510", "f8541113-c54b-4eab-af59-77b0eeef3617");
            appGroupAssignment.AppName = "Console App for Azure AD";
            appGroupAssignment.GroupName = "MyGroup";
            appGroupAssignment.UpdatedBy = "*****@*****.**";
            appGroupAssignment.OperationTypes = OperationTypes.Read.ToString();
            appGroupAssignmentOperation.InsertEntity(appGroupAssignment);
            }

        }
예제 #5
0
 public bool InsertEntity(UserGroupAssignmentsEntity assignment)
 {
     var operation = TableOperation.InsertOrReplace(assignment);
     _table.Execute(operation);
     return true;
 }