Monday, July 26, 2021

Continued from previous post...

 

 

Example for server-side implementation:

using Microsoft.AspNet.SignalR;

using Microsoft.AspNet.SignalR.Hubs;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Threading.Tasks;

using System.Web;

 

namespace SignalR.EditFile

{

     

    public static class UserHandler //this static class is to store the number of  users conected at the same time

    {

        public static HashSet<string> ConnectedIds = new HashSet<string>();

    }

 

    [HubName("editFile")]   //this is for use a name to use in the client

    public class EditFileHub : Hub

    {

        public void editFile(int x, int y) // this method will be called from the client, when the user edits a file

        {    

            Clients.Others.fileEdited(x, y); // this method will send the coord x, y  to the other users but the user draging the shape

        }

 

        public override Task OnConnected() //override OnConnect, OnReconnected and OnDisconnected  to know if a user is connected or disconnected

        {

            UserHandler.ConnectedIds.Add(Context.ConnectionId); //add a connection id to the list

            Clients.All.usersConnected(UserHandler.ConnectedIds.Count()); //this will send to ALL the clients  the number of users connected

             return base.OnConnected();

        }

 

        public override Task OnReconnected()

        {

            UserHandler.ConnectedIds.Add(Context.ConnectionId);

            Clients.All.usersConnected(UserHandler.ConnectedIds.Count());

            return base.OnConnected();

        }

 

        public override Task OnDisconnected()

        {

            UserHandler.ConnectedIds.Remove(Context.ConnectionId);

            Clients.All.usersConnected(UserHandler.ConnectedIds.Count());

            return base.OnDisconnected();

        }          

    }

}

Sunday, July 25, 2021

An article on using Azure SignalR service:

 


Introduction:

This is an article about Azure SignalR service. It simplifies the process of adding real time web functionality to applications over HTTP that allows the services to push content updates to connected clients. The payload can be single page web or mobile application content transfers updated without the need to pull the server or submit new HTTP requests for updates in a way that allows for syncing of devices from a single web server over HTTP. The devices can be connected to the server via the control plane which represents those devices to the SignalR service as entities to which it sends notifications. The scenario is one of synchronization or web update and it is common to many applications and services where data is pushed from the server to client in real time. The benefits cannot be overemphasized when it concerns actions such as gaming voting polling or auction. The dashboard and financial market data, sales update and multiplayer game leaderboard can be maintained with this application It can support chat and chatbot applications, real time shopping assistance, messengers and location services. It is also very helpful towards targeted ads, collaborative applications, push notifications and real time broadcasting or some other scenarios in which Azure signal R service can be used. Finally, automation is a core component in many workflows and that can also make use of triggers for upstream events. The idea behind SignalR is the building of real-time web applications using WebSocket which is an optimal transport for service and events, and it avoids having the client pull for the server signal service. It provides native programming experience with both asp.net core and asp.net. The synchronization functionality of web servers can now be offloaded to its own module but remain core component of web applications and services. Blazor is used on the server side.  This service can be used with a wide range of clients spanning mobile applications to IoT devices. The transport as well as its programmability with a variety of languages makes it convenient to use and integrate with other clouds services such as Azure functions and event grid. By itself or when used together with other cloud scale traffic, it can scale to multiple instances and millions of client connections. Switching to signal R service removes the need to manage backplanes that handles scale and client connections at the same time. It also provides compliance and security that Azure is known for. It's even possible to utilize just Azure functions and SignalR without any web applications to build service. Real time applications can be supported in multiple languages enabling interoperability. Finally, SignalR features support a wide range of management routines with respect to notifications and the clients that receive them.

Let’s compare this with a Do-it-yourself approach:

Saturday, July 24, 2021

 

This article continues from the previous one for claim provisioning and is dedicated towards security token service.

A security token service can relieve this end-to-end workflow by performing authentication for clients including services and users and providing security tokens for clients to present to the applications. It can support authentication federation for passive clients as well as a trust protocol for the active clients. It can implement a variety of authentication and authorization protocols including OpenID and OAuth while remaining aligned with enterprise authentication guidelines. It can provide a control plane for other services to integrate, and this plane can be internal without any risk of allowing customer access to identity providers. It can be provided regionally for application affinity and for isolated deployments. It can feature in an organization’s service inventory and leverage it for interacting with other services.

One of the instances of the Security Token Service can be used to support dialtone service requests. This follows the same routine as any other Security Token Service instances but with the dedicated purpose of providing dialtone response to other services. Any application using this service must support the right affinity to the dialtone instance. A dialtone service is a self-contained instance with a backup that is running on an infrastructure separate from that of others.

A dialtone service contributes towards resiliency. The local authentication supports cached security group memberships to provide continuity of DevOps account authentication if the Active Directory is not available. In such a case, the client manually selects the local dsts authentication option when requesting a security token.

The issuing authority for a security token does not have to be of the same type as the consumer. Domain controllers issue Kerberos tickets and X.509 certificate authorities issue chained certificates. A token that contains claims is issued by a web application or web service that is dedicated to this purpose. This plays a significant role in the identity solution.

Failover for active clients is achieved automatically if the authentication client is making simultaneous token request calls to both the primary and backup instances, with a preference based on the waittime  for the primary. Passive clients can achieve this using a manager which detects that the primary issuance endpoint is unavailable and routes traffic to the backup within half a minute.

The relying parties are the claim-aware applications and the claims-based applications. These can also be web applications and services, but they are usually different from the issuing authorities. When it gets a token, the relying parties extract claims from the tokens to perform specific identity related tasks

Interoperability between issuing authorities and relying parties is maintained by a set of industry standards. A policy for the interchange is retrieved with the help of a metadata exchange and the policy itself is structured. Sample standards include Security Assertion Markup Language which is an industry recognized XML vocabulary to represent claims. 

A claim to token conversion service is common to an identity foundation. It extracts the user principal name as a claim from heterogeneous devices, applications and services and generates an impersonation token granting user level access to those entities.

Friday, July 23, 2021

 <#

SYNOPSIS

This scripts provisions a new service claim identity as discussed in previous post.

#>

[CmdletBinding()]

param(

    [Parameter(Mandatory = $True, HelpMessage="the claim value to use")]

    [string]$claimType, # example: "http://schemas.xmlsoap.org/ws/2005/05/identity/claims/upn"


    [Parameter(Mandatory = $True, HelpMessage="the claim value to use")]

    [string]$claimValue,


    [Parameter(Mandatory = $True, HelpMessage="The service identity name")]

    [string]$sciName, # example: "dmsi-wus3-prod01-srs1"


    [Parameter(Mandatory = $True, HelpMessage="The service tree identifier")]

    [string]$serviceTreeId,


    [Parameter(Mandatory = $True, HelpMessage="The subscription identifier")]

    [string]$subscriptionId,


    [Parameter(Mandatory = $True, HelpMessage="The custom instance")]

    [string]$customInstance,


    [Parameter(Mandatory = $True, HelpMessage="The service account")]

    [string]$serviceAccount,


    [Parameter(Mandatory = $True, HelpMessage="The region")]

    [string]$region,


    [Parameter(Mandatory = $False, HelpMessage="If the claim is scoped.")]

    [string]$isScoped = $False,


    [Parameter(Mandatory = $False, HelpMessage="The azure environment/cloud name")]

    [string]$environmentName = "prod"


)


Ipmo \\location\client.dll 

Connect-ProviderActiveClient Prod

$request = New-ProviderCreateManagedServiceClientIdentity

$request.Name = $sciName

$request.ServiceTreeId = $serviceTreeId

$request.CustomInstance = $customInstance

$request.ClaimProvisionings = @()

$claim = New-ProviderClaimProvisioning

$claim.ClaimInstance.Type = $claimType

$claim.ClaimInstance.Value = $claimValue

$claim.ScopedToServiceAccount = $serviceAccount

$claim.IsUnscoped= $isScoped

$request.ClaimProvisionings.Add($claim)

$request.Region = $region

$request.Subscriptions = @()

$request.Subscriptions.Add($subscriptionId)

$request | Add-ProviderManagedServiceClientIdentity


#codingexercise:
Q: An array A of N elements has each element within the range 0 to N-1. Find the smallest element P such that every value that occurs in A also occurs in sequence A[0], A[1] ... A[P] 

For example, A = [2,2,1,0,1] and the smallest value of P is 3 where elements 2,2,1,0 contain all values that occur in A. 

A:   

public int getPrefix(int[] A) { 

Int prefix = Integer.MIN_VALUE; 

Int n = A.length; 

Int visited = new int[n]; 

for (int i = 0; i < n; i++) { 

     if (visited[A[I]] == 0){ 

         visited[A[I]] = 1;  

         Prefix = I; 

     } 

} 

return prefix; 

}